1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: use a guarded include for <inttypes.h> too

This commit is contained in:
Delyan Angelov 2020-10-19 12:18:22 +03:00
parent 4bc38a2f6c
commit d89986dd5e

View File

@ -282,7 +282,7 @@ pub fn (mut g Gen) init() {
g.cheaders.writeln(g.pref.custom_prelude)
} else if !g.pref.no_preludes {
g.cheaders.writeln('// Generated by the V compiler')
g.cheaders.writeln('#include <inttypes.h>') // int64_t etc
g.cheaders.writeln(get_guarded_include_text('<inttypes.h>', 'Please install build-essentials')) // int64_t etc
g.cheaders.writeln(c_builtin_types)
if g.pref.is_bare {
g.cheaders.writeln(bare_c_headers)
@ -979,19 +979,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
} else {
missing_message += ' Please install the corresponding development headers.'
}
mut guarded_include := '
|#if defined(__has_include)
|
|#if __has_include($node.main)
|#include $node.main
|#else
|#error VERROR_MESSAGE $missing_message
|#endif
|
|#else
|#include $node.main
|#endif
'.strip_margin()
mut guarded_include := get_guarded_include_text(node.main, missing_message)
if node.main == '<errno.h>' {
// fails with musl-gcc and msvc; but an unguarded include works:
guarded_include = '#include $node.main'
@ -5533,3 +5521,20 @@ fn (mut g Gen) panic_debug_info(pos token.Position) (int, string, string, string
pamod := g.fn_decl.modname()
return paline, pafile, pamod, pafn
}
pub fn get_guarded_include_text(iname string, imessage string) string {
res := '
|#if defined(__has_include)
|
|#if __has_include($iname)
|#include $iname
|#else
|#error VERROR_MESSAGE $imessage
|#endif
|
|#else
|#include $iname
|#endif
'.strip_margin()
return res
}