Skip to content

Commit d42ab0c

Browse files
brentleyjoneskeith
andauthored
Fix default CPU for macOS and iOS (#14923)
Since M1 support was added we started defaulting the CPU for macOS and iOS builds to the host CPU in the case another CPU wasn't passed. This change mirrors #13873, #13440 and https://github.com/bazelbuild/rules_apple//commit/99e5b631bf060358241a8eaabd285be5c120490f in the newer starlark transition. Without this you end up with architecture mismatches for builds. Fixes #14803 Closes #14816. PiperOrigin-RevId: 431641312 (cherry picked from commit 1ec1068) Co-authored-by: Keith Smiley <[email protected]>
1 parent 50bb742 commit d42ab0c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/main/starlark/builtins_bzl/common/objc/transitions.bzl

+13-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ def _determine_single_architecture(platform_type, settings):
3131
ios_cpus = settings["//command_line_option:ios_multi_cpus"]
3232
if len(ios_cpus) > 0:
3333
return ios_cpus[0]
34-
return _ios_cpu_from_cpu(settings["//command_line_option:cpu"])
34+
cpu_value = settings["//command_line_option:cpu"]
35+
if cpu_value.startswith(IOS_CPU_PREFIX):
36+
return cpu_value[len(IOS_CPU_PREFIX):]
37+
if cpu_value == "darwin_arm64":
38+
return "sim_arm64"
39+
return DEFAULT_IOS_CPU
3540
if platform_type == WATCHOS:
3641
watchos_cpus = settings["//command_line_option:watchos_cpus"]
3742
if len(watchos_cpus) == 0:
@@ -44,9 +49,12 @@ def _determine_single_architecture(platform_type, settings):
4449
return tvos_cpus[0]
4550
if platform_type == MACOS:
4651
macos_cpus = settings["//command_line_option:macos_cpus"]
47-
if len(macos_cpus) == 0:
48-
return DEFAULT_MACOS_CPU
49-
return macos_cpus[0]
52+
if macos_cpus:
53+
return macos_cpus[0]
54+
cpu_value = settings["//command_line_option:cpu"]
55+
if cpu_value.startswith(DARWIN_CPU_PREFIX):
56+
return cpu_value[len(DARWIN_CPU_PREFIX):]
57+
return DEFAULT_MACOS_CPU
5058
if platform_type == CATALYST:
5159
catalyst_cpus = settings["//command_line_option:catalyst_cpus"]
5260
if len(catalyst_cpus) == 0:
@@ -61,17 +69,13 @@ TVOS = "tvos"
6169
MACOS = "macos"
6270
CATALYST = "catalyst"
6371
IOS_CPU_PREFIX = "ios_"
72+
DARWIN_CPU_PREFIX = "darwin_"
6473
DEFAULT_IOS_CPU = "x86_64"
6574
DEFAULT_WATCHOS_CPU = "i386"
6675
DEFAULT_TVOS_CPU = "x86_64"
6776
DEFAULT_MACOS_CPU = "x86_64"
6877
DEFAULT_CATALYST_CPU = "x86_64"
6978

70-
def _ios_cpu_from_cpu(cpu):
71-
if cpu.startswith(IOS_CPU_PREFIX):
72-
return cpu[len(IOS_CPU_PREFIX):]
73-
return DEFAULT_IOS_CPU
74-
7579
def _apple_crosstool_transition_impl(settings, attr):
7680
platform_type = str(settings["//command_line_option:apple_platform_type"])
7781
cpu = _cpu_string(platform_type, settings)

0 commit comments

Comments
 (0)