diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index a5e4b552bdc643..2c6401dfa06ae1 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -19,6 +19,8 @@ const ( const c_verror_message_marker = 'VERROR_MESSAGE ' +const current_os = os.user_os() + fn (mut v Builder) show_c_compiler_output(res os.Result) { println('======== C Compiler output ========') println(res.output) @@ -298,7 +300,7 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { ccoptions.args << '-Wl,--export-all' ccoptions.args << '-Wl,--no-entry' } - if ccoptions.debug_mode && os.user_os() != 'windows' && v.pref.build_mode != .build_module { + if ccoptions.debug_mode && builder.current_os != 'windows' && v.pref.build_mode != .build_module { ccoptions.linker_flags << '-rdynamic' // needed for nicer symbolic backtraces } if v.pref.os == .freebsd { @@ -320,10 +322,10 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { ccoptions.wargs << '-Wno-write-strings' } if v.pref.is_liveshared || v.pref.is_livemain { - if (v.pref.os == .linux || os.user_os() == 'linux') && v.pref.build_mode != .build_module { + if v.pref.os == .linux && v.pref.build_mode != .build_module { ccoptions.linker_flags << '-rdynamic' } - if v.pref.os == .macos || os.user_os() == 'macos' { + if v.pref.os == .macos { ccoptions.args << '-flat_namespace' } } @@ -349,14 +351,18 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { } // Min macos version is mandatory I think? if v.pref.os == .macos { - ccoptions.post_args << '-mmacosx-version-min=10.7' - } else if v.pref.os == .ios { + if v.pref.macosx_version_min != '0' { + ccoptions.post_args << '-mmacosx-version-min=${v.pref.macosx_version_min}' + } + } + if v.pref.os == .ios { if v.pref.is_ios_simulator { ccoptions.post_args << '-miphonesimulator-version-min=10.0' } else { ccoptions.post_args << '-miphoneos-version-min=10.0' } - } else if v.pref.os == .windows { + } + if v.pref.os == .windows { ccoptions.post_args << '-municode' } cflags := v.get_os_cflags() @@ -382,7 +388,6 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { ccoptions.post_args << '-bt25' } // Without these libs compilation will fail on Linux - // || os.user_os() == 'linux' if !v.pref.is_bare && v.pref.build_mode != .build_module && v.pref.os in [.linux, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .haiku] { if v.pref.os in [.freebsd, .netbsd] { @@ -472,7 +477,7 @@ fn (v &Builder) thirdparty_object_args(ccoptions CcompilerOptions, middle []stri } fn (mut v Builder) setup_output_name() { - if !v.pref.is_shared && v.pref.build_mode != .build_module && os.user_os() == 'windows' + if !v.pref.is_shared && v.pref.build_mode != .build_module && v.pref.os == .windows && !v.pref.out_name.ends_with('.exe') { v.pref.out_name += '.exe' } @@ -860,8 +865,8 @@ fn (mut c Builder) cc_windows_cross() { } else { args << cflags.c_options_after_target() } - if os.user_os() !in ['macos', 'linux', 'termux'] { - println(os.user_os()) + if builder.current_os !in ['macos', 'linux', 'termux'] { + println(builder.current_os) panic('your platform is not supported yet') } // diff --git a/vlib/v/help/build/build-c.txt b/vlib/v/help/build/build-c.txt index 858680bf9c114c..257420afcdb4f4 100644 --- a/vlib/v/help/build/build-c.txt +++ b/vlib/v/help/build/build-c.txt @@ -155,6 +155,11 @@ see also `v help build`. that V will use (`x86_64-w64-mingw32-gcc` for targeting Windows, and `clang` for targeting Linux from other operating systems). + -macosx-version-min 10.7 + Only relevant on macos. It will be passed as -mmacosx-version-min=10.7 to + the C backend compiler clang . It is 10.7 on macos by default. If you + pass `-macosx-version-min 0`, then that flag will not be passed at all. + -sanitize Pass flags related to sanitization to the C compiler. diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 5121db2aad285c..a2b26df64d6c62 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -157,6 +157,7 @@ pub mut: use_cache bool // when set, use cached modules to speed up subsequent compilations, at the cost of slower initial ones (while the modules are cached) retry_compilation bool = true // retry the compilation with another C compiler, if tcc fails. use_os_system_to_run bool // when set, use os.system() to run the produced executable, instead of os.new_process; works around segfaults on macos, that may happen when xcode is updated + macosx_version_min string = '10.7' // relevant only for macos and ios targets // TODO Convert this into a []string cflags string // Additional options which will be passed to the C compiler *before* other options. ldflags string // Additional options which will be passed to the C compiler *after* everything else. @@ -685,6 +686,11 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin '-use-os-system-to-run' { res.use_os_system_to_run = true } + '-macosx-version-min' { + res.macosx_version_min = cmdline.option(current_args, arg, res.macosx_version_min) + i++ + res.build_options << '${arg} ${res.macosx_version_min}' + } '-nocache' { res.use_cache = false } @@ -694,10 +700,12 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin } '-no-parallel' { res.no_parallel = true + res.build_options << arg } '-parallel-cc' { res.parallel_cc = true res.no_parallel = true // TODO: see how to make both work + res.build_options << arg } '-native' { res.backend = .native