Skip to content

Commit

Permalink
pref,builder: add support for -macosx-version-min 10.2 and `-macosx…
Browse files Browse the repository at this point in the history
…-version-min 0` (with default of 10.7) (#19626)
  • Loading branch information
spytheman authored Oct 22, 2023
1 parent 65dd69c commit 39310a2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
25 changes: 15 additions & 10 deletions vlib/v/builder/cc.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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'
}
}
Expand All @@ -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()
Expand All @@ -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] {
Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -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')
}
//
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/help/build/build-c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 8 additions & 0 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 39310a2

Please sign in to comment.