Skip to content

Commit cac3d9e

Browse files
committed
builder: fix assembly-tests 3 of 4 failing (fixes #11433)
1 parent a9f23a2 commit cac3d9e

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

vlib/v/builder/builder_test.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,15 @@ fn test_macos_2048_build_does_not_force_deployment_target() {
265265
assert flags_output.contains('-fobjc-arc')
266266
assert !flags_output.contains('-mmacosx-version-min=')
267267
}
268+
269+
fn test_macos_arch_flag_is_forwarded_to_c_compiler() {
270+
$if !macos {
271+
return
272+
}
273+
src_file := os.join_path(test_path, 'macos_arch_forwarding.v')
274+
out_file := os.join_path(test_path, 'macos_arch_forwarding')
275+
os.write_file(src_file, 'fn main() {\n\tprintln("hello")\n}\n')!
276+
flags_output :=
277+
run_v_ok('${os.quoted_path(vexe)} -gc none -showcc -skip-running -arch amd64 -o ${os.quoted_path(out_file)} ${os.quoted_path(src_file)}')
278+
assert flags_output.contains('-arch x86_64')
279+
}

vlib/v/builder/cc.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,17 @@ fn resolve_ccompiler_type(ccompiler string, fallback pref.CompilerType) pref.Com
525525
return fallback
526526
}
527527

528+
fn darwin_target_arch_name(arch pref.Arch) string {
529+
return match arch {
530+
.amd64 { 'x86_64' }
531+
.arm64 { 'arm64' }
532+
.i386 { 'i386' }
533+
.ppc { 'ppc' }
534+
.ppc64 { 'ppc64' }
535+
else { '' }
536+
}
537+
}
538+
528539
fn cc_from_pref_ccompiler_type(cc_type pref.CompilerType) CC {
529540
return match cc_type {
530541
.tinyc { .tcc }
@@ -596,6 +607,12 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) {
596607
if ccoptions.cc == .unknown {
597608
eprintln('Compilation with unknown C compiler `${cc_file_name}`')
598609
}
610+
if v.pref.os == .macos {
611+
darwin_target_arch := darwin_target_arch_name(v.pref.arch)
612+
if darwin_target_arch != '' {
613+
ccoptions.args << ['-arch', darwin_target_arch]
614+
}
615+
}
599616

600617
// Add -fwrapv to handle UB overflows
601618
if ccoptions.cc in [.gcc, .clang, .tcc]

0 commit comments

Comments
 (0)