Skip to content

Commit ffdd633

Browse files
[apple] support tvos_sim_arm64 in toolchain (bazelbuild#14779)
Closes bazelbuild#14439. PiperOrigin-RevId: 427721738 (cherry picked from commit 207c31b) Co-authored-by: Dan Fleming <[email protected]>
1 parent 5356fed commit ffdd633

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java

+15-16
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public class AppleConfiguration extends Fragment implements AppleConfigurationAp
7777
private static final String MACOS_CPU_PREFIX = "darwin_";
7878

7979
// TODO(b/180572694): Remove after platforms based toolchain resolution supported.
80-
/** Prefix for forced iOS simulator cpu values */
81-
public static final String IOS_FORCED_SIMULATOR_CPU_PREFIX = "sim_";
80+
/** Prefix for forced iOS and tvOS simulator cpu values */
81+
public static final String FORCED_SIMULATOR_CPU_PREFIX = "sim_";
8282

8383
/** Default cpu for iOS builds. */
8484
@VisibleForTesting
@@ -231,25 +231,24 @@ private static String getSingleArchitecture(
231231
// The removeSimPrefix argument is necessary due to a simulator and device both using arm64
232232
// architecture. In the case of Starlark asking for the architecture, we should return the
233233
// actual architecture (arm64) but in other cases in this class what we actually want is the
234-
// CPU without the ios prefix (e.g. sim_arm64). This parameter is provided in the private method
235-
// so that internal to this class we are able to use both without duplicating retrieval logic.
234+
// CPU without the ios/tvos prefix (e.g. sim_arm64). This parameter is provided in the private
235+
// method so that internal to this class we are able to use both without duplicating retrieval
236+
// logic.
236237
// TODO(b/180572694): Remove removeSimPrefix parameter once platforms are used instead of CPU
238+
String cpu = getPrefixedAppleCpu(applePlatformType, appleCpus);
239+
if (removeSimPrefix && cpu.startsWith(FORCED_SIMULATOR_CPU_PREFIX)) {
240+
cpu = cpu.substring(FORCED_SIMULATOR_CPU_PREFIX.length());
241+
}
242+
return cpu;
243+
}
244+
245+
private static String getPrefixedAppleCpu(PlatformType applePlatformType, AppleCpus appleCpus) {
237246
if (!Strings.isNullOrEmpty(appleCpus.appleSplitCpu())) {
238-
String cpu = appleCpus.appleSplitCpu();
239-
if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) {
240-
cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length());
241-
}
242-
return cpu;
247+
return appleCpus.appleSplitCpu();
243248
}
244249
switch (applePlatformType) {
245250
case IOS:
246-
{
247-
String cpu = Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu());
248-
if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) {
249-
cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length());
250-
}
251-
return cpu;
252-
}
251+
return Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu());
253252
case WATCHOS:
254253
return appleCpus.watchosCpus().get(0);
255254
case TVOS:

src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public enum ApplePlatform implements ApplePlatformApi {
5151
private static final ImmutableSet<String> WATCHOS_DEVICE_TARGET_CPUS =
5252
ImmutableSet.of("watchos_armv7k", "watchos_arm64_32");
5353
private static final ImmutableSet<String> TVOS_SIMULATOR_TARGET_CPUS =
54-
ImmutableSet.of("tvos_x86_64");
54+
ImmutableSet.of("tvos_x86_64", "tvos_sim_arm64");
5555
private static final ImmutableSet<String> TVOS_DEVICE_TARGET_CPUS =
5656
ImmutableSet.of("tvos_arm64");
5757
private static final ImmutableSet<String> CATALYST_TARGET_CPUS =

tools/osx/crosstool/BUILD.toolchains

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ OSX_TOOLS_CONSTRAINTS = {
5252
"@platforms//os:ios",
5353
"@platforms//cpu:x86_64",
5454
],
55+
"tvos_sim_arm64": [
56+
"@platforms//os:ios",
57+
"@platforms//cpu:aarch64",
58+
],
5559
"watchos_arm64": [
5660
"@platforms//os:ios",
5761
"@platforms//cpu:aarch64",

tools/osx/crosstool/cc_toolchain_config.bzl

+11-3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def _impl(ctx):
7575
target_system_name = "x86_64-apple-ios"
7676
elif (ctx.attr.cpu == "ios_sim_arm64"):
7777
target_system_name = "arm64-apple-ios-simulator"
78+
elif (ctx.attr.cpu == "tvos_sim_arm64"):
79+
target_system_name = "arm64-apple-tvos-simulator"
7880
elif (ctx.attr.cpu == "watchos_arm64"):
7981
target_system_name = "arm64-apple-watchos-simulator"
8082
elif (ctx.attr.cpu == "darwin_x86_64"):
@@ -104,7 +106,7 @@ def _impl(ctx):
104106

105107
host_system_name = "x86_64-apple-macosx"
106108
arch = ctx.attr.cpu.split("_", 1)[-1]
107-
if ctx.attr.cpu == "ios_sim_arm64":
109+
if ctx.attr.cpu in ["ios_sim_arm64", "tvos_sim_arm64", "watchos_arm64"]:
108110
arch = "arm64"
109111

110112
all_compile_actions = [
@@ -769,7 +771,8 @@ def _impl(ctx):
769771
],
770772
)
771773
elif (ctx.attr.cpu == "tvos_arm64" or
772-
ctx.attr.cpu == "tvos_x86_64"):
774+
ctx.attr.cpu == "tvos_x86_64" or
775+
ctx.attr.cpu == "tvos_sim_arm64"):
773776
apply_default_compiler_flags_feature = feature(
774777
name = "apply_default_compiler_flags",
775778
flag_sets = [
@@ -929,6 +932,7 @@ def _impl(ctx):
929932
ctx.attr.cpu == "ios_x86_64" or
930933
ctx.attr.cpu == "ios_sim_arm64" or
931934
ctx.attr.cpu == "tvos_x86_64" or
935+
ctx.attr.cpu == "tvos_sim_arm64" or
932936
ctx.attr.cpu == "watchos_i386" or
933937
ctx.attr.cpu == "watchos_x86_64" or
934938
ctx.attr.cpu == "watchos_arm64"):
@@ -1000,6 +1004,7 @@ def _impl(ctx):
10001004
ctx.attr.cpu == "ios_sim_arm64" or
10011005
ctx.attr.cpu == "tvos_arm64" or
10021006
ctx.attr.cpu == "tvos_x86_64" or
1007+
ctx.attr.cpu == "tvos_sim_arm64" or
10031008
ctx.attr.cpu == "watchos_arm64_32" or
10041009
ctx.attr.cpu == "watchos_armv7k" or
10051010
ctx.attr.cpu == "watchos_i386" or
@@ -1289,7 +1294,8 @@ def _impl(ctx):
12891294
),
12901295
],
12911296
)
1292-
elif (ctx.attr.cpu == "tvos_x86_64"):
1297+
elif (ctx.attr.cpu == "tvos_x86_64" or
1298+
ctx.attr.cpu == "tvos_sim_arm64"):
12931299
version_min_feature = feature(
12941300
name = "version_min",
12951301
flag_sets = [
@@ -1765,6 +1771,7 @@ def _impl(ctx):
17651771
ctx.attr.cpu == "ios_sim_arm64" or
17661772
ctx.attr.cpu == "tvos_arm64" or
17671773
ctx.attr.cpu == "tvos_x86_64" or
1774+
ctx.attr.cpu == "tvos_sim_arm64" or
17681775
ctx.attr.cpu == "watchos_arm64_32" or
17691776
ctx.attr.cpu == "watchos_armv7k" or
17701777
ctx.attr.cpu == "watchos_i386" or
@@ -2850,6 +2857,7 @@ def _impl(ctx):
28502857
ctx.attr.cpu == "ios_sim_arm64" or
28512858
ctx.attr.cpu == "tvos_arm64" or
28522859
ctx.attr.cpu == "tvos_x86_64" or
2860+
ctx.attr.cpu == "tvos_sim_arm64" or
28532861
ctx.attr.cpu == "watchos_arm64_32" or
28542862
ctx.attr.cpu == "watchos_armv7k" or
28552863
ctx.attr.cpu == "watchos_i386" or

tools/osx/crosstool/osx_archs.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ OSX_TOOLS_NON_DEVICE_ARCHS = [
2525
"watchos_i386",
2626
"watchos_x86_64",
2727
"tvos_x86_64",
28+
"tvos_sim_arm64",
2829
]
2930

3031
OSX_TOOLS_ARCHS = [

0 commit comments

Comments
 (0)