Skip to content

Commit 207c31b

Browse files
dflemscopybara-github
authored andcommitted
[apple] support tvos_sim_arm64 in toolchain
Closes bazelbuild#14439. PiperOrigin-RevId: 427721738
1 parent 012cab5 commit 207c31b

6 files changed

Lines changed: 33 additions & 21 deletions

File tree

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

Lines changed: 15 additions & 16 deletions
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
@@ -229,25 +229,24 @@ private static String getSingleArchitecture(
229229
// The removeSimPrefix argument is necessary due to a simulator and device both using arm64
230230
// architecture. In the case of Starlark asking for the architecture, we should return the
231231
// actual architecture (arm64) but in other cases in this class what we actually want is the
232-
// CPU without the ios prefix (e.g. sim_arm64). This parameter is provided in the private method
233-
// so that internal to this class we are able to use both without duplicating retrieval logic.
232+
// CPU without the ios/tvos prefix (e.g. sim_arm64). This parameter is provided in the private
233+
// method so that internal to this class we are able to use both without duplicating retrieval
234+
// logic.
234235
// TODO(b/180572694): Remove removeSimPrefix parameter once platforms are used instead of CPU
236+
String cpu = getPrefixedAppleCpu(applePlatformType, appleCpus);
237+
if (removeSimPrefix && cpu.startsWith(FORCED_SIMULATOR_CPU_PREFIX)) {
238+
cpu = cpu.substring(FORCED_SIMULATOR_CPU_PREFIX.length());
239+
}
240+
return cpu;
241+
}
242+
243+
private static String getPrefixedAppleCpu(PlatformType applePlatformType, AppleCpus appleCpus) {
235244
if (!Strings.isNullOrEmpty(appleCpus.appleSplitCpu())) {
236-
String cpu = appleCpus.appleSplitCpu();
237-
if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) {
238-
cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length());
239-
}
240-
return cpu;
245+
return appleCpus.appleSplitCpu();
241246
}
242247
switch (applePlatformType) {
243248
case IOS:
244-
{
245-
String cpu = Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu());
246-
if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) {
247-
cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length());
248-
}
249-
return cpu;
250-
}
249+
return Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu());
251250
case WATCHOS:
252251
return appleCpus.watchosCpus().get(0);
253252
case TVOS:

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

Lines changed: 1 addition & 1 deletion
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 =

src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _IOS_SIMULATOR_TARGET_CPUS = ["ios_x86_64", "ios_i386", "ios_sim_arm64"]
3434
_IOS_DEVICE_TARGET_CPUS = ["ios_armv6", "ios_arm64", "ios_armv7", "ios_armv7s", "ios_arm64e"]
3535
_WATCHOS_SIMULATOR_TARGET_CPUS = ["watchos_i386", "watchos_x86_64", "watchos_arm64"]
3636
_WATCHOS_DEVICE_TARGET_CPUS = ["watchos_armv7k", "watchos_arm64_32"]
37-
_TVOS_SIMULATOR_TARGET_CPUS = ["tvos_x86_64"]
37+
_TVOS_SIMULATOR_TARGET_CPUS = ["tvos_x86_64", "tvos_sim_arm64"]
3838
_TVOS_DEVICE_TARGET_CPUS = ["tvos_arm64"]
3939
_CATALYST_TARGET_CPUS = ["catalyst_x86_64"]
4040
_MACOS_TARGET_CPUS = ["darwin_x86_64", "darwin_arm64", "darwin_arm64e", "darwin"]

tools/osx/crosstool/BUILD.toolchains

Lines changed: 4 additions & 0 deletions
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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def _impl(ctx):
7676
target_system_name = "x86_64-apple-ios"
7777
elif (ctx.attr.cpu == "ios_sim_arm64"):
7878
target_system_name = "arm64-apple-ios-simulator"
79+
elif (ctx.attr.cpu == "tvos_sim_arm64"):
80+
target_system_name = "arm64-apple-tvos-simulator"
7981
elif (ctx.attr.cpu == "watchos_arm64"):
8082
target_system_name = "arm64-apple-watchos-simulator"
8183
elif (ctx.attr.cpu == "darwin_x86_64"):
@@ -105,7 +107,7 @@ def _impl(ctx):
105107

106108
host_system_name = "x86_64-apple-macosx"
107109
arch = ctx.attr.cpu.split("_", 1)[-1]
108-
if ctx.attr.cpu == "ios_sim_arm64":
110+
if ctx.attr.cpu in ["ios_sim_arm64", "tvos_sim_arm64", "watchos_arm64"]:
109111
arch = "arm64"
110112

111113
all_compile_actions = [
@@ -770,7 +772,8 @@ def _impl(ctx):
770772
],
771773
)
772774
elif (ctx.attr.cpu == "tvos_arm64" or
773-
ctx.attr.cpu == "tvos_x86_64"):
775+
ctx.attr.cpu == "tvos_x86_64" or
776+
ctx.attr.cpu == "tvos_sim_arm64"):
774777
apply_default_compiler_flags_feature = feature(
775778
name = "apply_default_compiler_flags",
776779
flag_sets = [
@@ -930,6 +933,7 @@ def _impl(ctx):
930933
ctx.attr.cpu == "ios_x86_64" or
931934
ctx.attr.cpu == "ios_sim_arm64" or
932935
ctx.attr.cpu == "tvos_x86_64" or
936+
ctx.attr.cpu == "tvos_sim_arm64" or
933937
ctx.attr.cpu == "watchos_i386" or
934938
ctx.attr.cpu == "watchos_x86_64" or
935939
ctx.attr.cpu == "watchos_arm64"):
@@ -1001,6 +1005,7 @@ def _impl(ctx):
10011005
ctx.attr.cpu == "ios_sim_arm64" or
10021006
ctx.attr.cpu == "tvos_arm64" or
10031007
ctx.attr.cpu == "tvos_x86_64" or
1008+
ctx.attr.cpu == "tvos_sim_arm64" or
10041009
ctx.attr.cpu == "watchos_arm64_32" or
10051010
ctx.attr.cpu == "watchos_armv7k" or
10061011
ctx.attr.cpu == "watchos_i386" or
@@ -1290,7 +1295,8 @@ def _impl(ctx):
12901295
),
12911296
],
12921297
)
1293-
elif (ctx.attr.cpu == "tvos_x86_64"):
1298+
elif (ctx.attr.cpu == "tvos_x86_64" or
1299+
ctx.attr.cpu == "tvos_sim_arm64"):
12941300
version_min_feature = feature(
12951301
name = "version_min",
12961302
flag_sets = [
@@ -1766,6 +1772,7 @@ def _impl(ctx):
17661772
ctx.attr.cpu == "ios_sim_arm64" or
17671773
ctx.attr.cpu == "tvos_arm64" or
17681774
ctx.attr.cpu == "tvos_x86_64" or
1775+
ctx.attr.cpu == "tvos_sim_arm64" or
17691776
ctx.attr.cpu == "watchos_arm64_32" or
17701777
ctx.attr.cpu == "watchos_armv7k" or
17711778
ctx.attr.cpu == "watchos_i386" or
@@ -2851,6 +2858,7 @@ def _impl(ctx):
28512858
ctx.attr.cpu == "ios_sim_arm64" or
28522859
ctx.attr.cpu == "tvos_arm64" or
28532860
ctx.attr.cpu == "tvos_x86_64" or
2861+
ctx.attr.cpu == "tvos_sim_arm64" or
28542862
ctx.attr.cpu == "watchos_arm64_32" or
28552863
ctx.attr.cpu == "watchos_armv7k" or
28562864
ctx.attr.cpu == "watchos_i386" or

tools/osx/crosstool/osx_archs.bzl

Lines changed: 1 addition & 0 deletions
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)