Skip to content

Commit 39310a2

Browse files
authored
pref,builder: add support for -macosx-version-min 10.2 and -macosx-version-min 0 (with default of 10.7) (#19626)
1 parent 65dd69c commit 39310a2

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

vlib/v/builder/cc.v

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const (
1919

2020
const c_verror_message_marker = 'VERROR_MESSAGE '
2121

22+
const current_os = os.user_os()
23+
2224
fn (mut v Builder) show_c_compiler_output(res os.Result) {
2325
println('======== C Compiler output ========')
2426
println(res.output)
@@ -298,7 +300,7 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
298300
ccoptions.args << '-Wl,--export-all'
299301
ccoptions.args << '-Wl,--no-entry'
300302
}
301-
if ccoptions.debug_mode && os.user_os() != 'windows' && v.pref.build_mode != .build_module {
303+
if ccoptions.debug_mode && builder.current_os != 'windows' && v.pref.build_mode != .build_module {
302304
ccoptions.linker_flags << '-rdynamic' // needed for nicer symbolic backtraces
303305
}
304306
if v.pref.os == .freebsd {
@@ -320,10 +322,10 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
320322
ccoptions.wargs << '-Wno-write-strings'
321323
}
322324
if v.pref.is_liveshared || v.pref.is_livemain {
323-
if (v.pref.os == .linux || os.user_os() == 'linux') && v.pref.build_mode != .build_module {
325+
if v.pref.os == .linux && v.pref.build_mode != .build_module {
324326
ccoptions.linker_flags << '-rdynamic'
325327
}
326-
if v.pref.os == .macos || os.user_os() == 'macos' {
328+
if v.pref.os == .macos {
327329
ccoptions.args << '-flat_namespace'
328330
}
329331
}
@@ -349,14 +351,18 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
349351
}
350352
// Min macos version is mandatory I think?
351353
if v.pref.os == .macos {
352-
ccoptions.post_args << '-mmacosx-version-min=10.7'
353-
} else if v.pref.os == .ios {
354+
if v.pref.macosx_version_min != '0' {
355+
ccoptions.post_args << '-mmacosx-version-min=${v.pref.macosx_version_min}'
356+
}
357+
}
358+
if v.pref.os == .ios {
354359
if v.pref.is_ios_simulator {
355360
ccoptions.post_args << '-miphonesimulator-version-min=10.0'
356361
} else {
357362
ccoptions.post_args << '-miphoneos-version-min=10.0'
358363
}
359-
} else if v.pref.os == .windows {
364+
}
365+
if v.pref.os == .windows {
360366
ccoptions.post_args << '-municode'
361367
}
362368
cflags := v.get_os_cflags()
@@ -382,7 +388,6 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
382388
ccoptions.post_args << '-bt25'
383389
}
384390
// Without these libs compilation will fail on Linux
385-
// || os.user_os() == 'linux'
386391
if !v.pref.is_bare && v.pref.build_mode != .build_module
387392
&& v.pref.os in [.linux, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .haiku] {
388393
if v.pref.os in [.freebsd, .netbsd] {
@@ -472,7 +477,7 @@ fn (v &Builder) thirdparty_object_args(ccoptions CcompilerOptions, middle []stri
472477
}
473478

474479
fn (mut v Builder) setup_output_name() {
475-
if !v.pref.is_shared && v.pref.build_mode != .build_module && os.user_os() == 'windows'
480+
if !v.pref.is_shared && v.pref.build_mode != .build_module && v.pref.os == .windows
476481
&& !v.pref.out_name.ends_with('.exe') {
477482
v.pref.out_name += '.exe'
478483
}
@@ -860,8 +865,8 @@ fn (mut c Builder) cc_windows_cross() {
860865
} else {
861866
args << cflags.c_options_after_target()
862867
}
863-
if os.user_os() !in ['macos', 'linux', 'termux'] {
864-
println(os.user_os())
868+
if builder.current_os !in ['macos', 'linux', 'termux'] {
869+
println(builder.current_os)
865870
panic('your platform is not supported yet')
866871
}
867872
//

vlib/v/help/build/build-c.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ see also `v help build`.
155155
that V will use (`x86_64-w64-mingw32-gcc` for targeting Windows, and
156156
`clang` for targeting Linux from other operating systems).
157157

158+
-macosx-version-min 10.7
159+
Only relevant on macos. It will be passed as -mmacosx-version-min=10.7 to
160+
the C backend compiler clang . It is 10.7 on macos by default. If you
161+
pass `-macosx-version-min 0`, then that flag will not be passed at all.
162+
158163
-sanitize
159164
Pass flags related to sanitization to the C compiler.
160165

vlib/v/pref/pref.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub mut:
157157
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)
158158
retry_compilation bool = true // retry the compilation with another C compiler, if tcc fails.
159159
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
160+
macosx_version_min string = '10.7' // relevant only for macos and ios targets
160161
// TODO Convert this into a []string
161162
cflags string // Additional options which will be passed to the C compiler *before* other options.
162163
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
685686
'-use-os-system-to-run' {
686687
res.use_os_system_to_run = true
687688
}
689+
'-macosx-version-min' {
690+
res.macosx_version_min = cmdline.option(current_args, arg, res.macosx_version_min)
691+
i++
692+
res.build_options << '${arg} ${res.macosx_version_min}'
693+
}
688694
'-nocache' {
689695
res.use_cache = false
690696
}
@@ -694,10 +700,12 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
694700
}
695701
'-no-parallel' {
696702
res.no_parallel = true
703+
res.build_options << arg
697704
}
698705
'-parallel-cc' {
699706
res.parallel_cc = true
700707
res.no_parallel = true // TODO: see how to make both work
708+
res.build_options << arg
701709
}
702710
'-native' {
703711
res.backend = .native

0 commit comments

Comments
 (0)