diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java index 886677e1f91a40..28de09f6b48395 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java @@ -77,8 +77,8 @@ public class AppleConfiguration extends Fragment implements AppleConfigurationAp private static final String MACOS_CPU_PREFIX = "darwin_"; // TODO(b/180572694): Remove after platforms based toolchain resolution supported. - /** Prefix for forced iOS simulator cpu values */ - public static final String IOS_FORCED_SIMULATOR_CPU_PREFIX = "sim_"; + /** Prefix for forced iOS and tvOS simulator cpu values */ + public static final String FORCED_SIMULATOR_CPU_PREFIX = "sim_"; /** Default cpu for iOS builds. */ @VisibleForTesting @@ -231,25 +231,24 @@ private static String getSingleArchitecture( // The removeSimPrefix argument is necessary due to a simulator and device both using arm64 // architecture. In the case of Starlark asking for the architecture, we should return the // actual architecture (arm64) but in other cases in this class what we actually want is the - // CPU without the ios prefix (e.g. sim_arm64). This parameter is provided in the private method - // so that internal to this class we are able to use both without duplicating retrieval logic. + // CPU without the ios/tvos prefix (e.g. sim_arm64). This parameter is provided in the private + // method so that internal to this class we are able to use both without duplicating retrieval + // logic. // TODO(b/180572694): Remove removeSimPrefix parameter once platforms are used instead of CPU + String cpu = getPrefixedAppleCpu(applePlatformType, appleCpus); + if (removeSimPrefix && cpu.startsWith(FORCED_SIMULATOR_CPU_PREFIX)) { + cpu = cpu.substring(FORCED_SIMULATOR_CPU_PREFIX.length()); + } + return cpu; + } + + private static String getPrefixedAppleCpu(PlatformType applePlatformType, AppleCpus appleCpus) { if (!Strings.isNullOrEmpty(appleCpus.appleSplitCpu())) { - String cpu = appleCpus.appleSplitCpu(); - if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) { - cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length()); - } - return cpu; + return appleCpus.appleSplitCpu(); } switch (applePlatformType) { case IOS: - { - String cpu = Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu()); - if (removeSimPrefix && cpu.startsWith(IOS_FORCED_SIMULATOR_CPU_PREFIX)) { - cpu = cpu.substring(IOS_FORCED_SIMULATOR_CPU_PREFIX.length()); - } - return cpu; - } + return Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu()); case WATCHOS: return appleCpus.watchosCpus().get(0); case TVOS: diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java b/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java index 68eb162ad7ef93..e90d8445917c97 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java @@ -51,7 +51,7 @@ public enum ApplePlatform implements ApplePlatformApi { private static final ImmutableSet WATCHOS_DEVICE_TARGET_CPUS = ImmutableSet.of("watchos_armv7k", "watchos_arm64_32"); private static final ImmutableSet TVOS_SIMULATOR_TARGET_CPUS = - ImmutableSet.of("tvos_x86_64"); + ImmutableSet.of("tvos_x86_64", "tvos_sim_arm64"); private static final ImmutableSet TVOS_DEVICE_TARGET_CPUS = ImmutableSet.of("tvos_arm64"); private static final ImmutableSet CATALYST_TARGET_CPUS = diff --git a/tools/osx/crosstool/BUILD.toolchains b/tools/osx/crosstool/BUILD.toolchains index 0e2f7c09681527..c63b11874ad645 100644 --- a/tools/osx/crosstool/BUILD.toolchains +++ b/tools/osx/crosstool/BUILD.toolchains @@ -52,6 +52,10 @@ OSX_TOOLS_CONSTRAINTS = { "@platforms//os:ios", "@platforms//cpu:x86_64", ], + "tvos_sim_arm64": [ + "@platforms//os:ios", + "@platforms//cpu:aarch64", + ], "watchos_arm64": [ "@platforms//os:ios", "@platforms//cpu:aarch64", diff --git a/tools/osx/crosstool/cc_toolchain_config.bzl b/tools/osx/crosstool/cc_toolchain_config.bzl index c23072e8109e3d..2129262a75ac4e 100644 --- a/tools/osx/crosstool/cc_toolchain_config.bzl +++ b/tools/osx/crosstool/cc_toolchain_config.bzl @@ -75,6 +75,8 @@ def _impl(ctx): target_system_name = "x86_64-apple-ios" elif (ctx.attr.cpu == "ios_sim_arm64"): target_system_name = "arm64-apple-ios-simulator" + elif (ctx.attr.cpu == "tvos_sim_arm64"): + target_system_name = "arm64-apple-tvos-simulator" elif (ctx.attr.cpu == "watchos_arm64"): target_system_name = "arm64-apple-watchos-simulator" elif (ctx.attr.cpu == "darwin_x86_64"): @@ -104,7 +106,7 @@ def _impl(ctx): host_system_name = "x86_64-apple-macosx" arch = ctx.attr.cpu.split("_", 1)[-1] - if ctx.attr.cpu == "ios_sim_arm64": + if ctx.attr.cpu in ["ios_sim_arm64", "tvos_sim_arm64", "watchos_arm64"]: arch = "arm64" all_compile_actions = [ @@ -769,7 +771,8 @@ def _impl(ctx): ], ) elif (ctx.attr.cpu == "tvos_arm64" or - ctx.attr.cpu == "tvos_x86_64"): + ctx.attr.cpu == "tvos_x86_64" or + ctx.attr.cpu == "tvos_sim_arm64"): apply_default_compiler_flags_feature = feature( name = "apply_default_compiler_flags", flag_sets = [ @@ -929,6 +932,7 @@ def _impl(ctx): ctx.attr.cpu == "ios_x86_64" or ctx.attr.cpu == "ios_sim_arm64" or ctx.attr.cpu == "tvos_x86_64" or + ctx.attr.cpu == "tvos_sim_arm64" or ctx.attr.cpu == "watchos_i386" or ctx.attr.cpu == "watchos_x86_64" or ctx.attr.cpu == "watchos_arm64"): @@ -1000,6 +1004,7 @@ def _impl(ctx): ctx.attr.cpu == "ios_sim_arm64" or ctx.attr.cpu == "tvos_arm64" or ctx.attr.cpu == "tvos_x86_64" or + ctx.attr.cpu == "tvos_sim_arm64" or ctx.attr.cpu == "watchos_arm64_32" or ctx.attr.cpu == "watchos_armv7k" or ctx.attr.cpu == "watchos_i386" or @@ -1289,7 +1294,8 @@ def _impl(ctx): ), ], ) - elif (ctx.attr.cpu == "tvos_x86_64"): + elif (ctx.attr.cpu == "tvos_x86_64" or + ctx.attr.cpu == "tvos_sim_arm64"): version_min_feature = feature( name = "version_min", flag_sets = [ @@ -1765,6 +1771,7 @@ def _impl(ctx): ctx.attr.cpu == "ios_sim_arm64" or ctx.attr.cpu == "tvos_arm64" or ctx.attr.cpu == "tvos_x86_64" or + ctx.attr.cpu == "tvos_sim_arm64" or ctx.attr.cpu == "watchos_arm64_32" or ctx.attr.cpu == "watchos_armv7k" or ctx.attr.cpu == "watchos_i386" or @@ -2850,6 +2857,7 @@ def _impl(ctx): ctx.attr.cpu == "ios_sim_arm64" or ctx.attr.cpu == "tvos_arm64" or ctx.attr.cpu == "tvos_x86_64" or + ctx.attr.cpu == "tvos_sim_arm64" or ctx.attr.cpu == "watchos_arm64_32" or ctx.attr.cpu == "watchos_armv7k" or ctx.attr.cpu == "watchos_i386" or diff --git a/tools/osx/crosstool/osx_archs.bzl b/tools/osx/crosstool/osx_archs.bzl index ec684eb3d1efb9..aeb82ac6953cb7 100644 --- a/tools/osx/crosstool/osx_archs.bzl +++ b/tools/osx/crosstool/osx_archs.bzl @@ -25,6 +25,7 @@ OSX_TOOLS_NON_DEVICE_ARCHS = [ "watchos_i386", "watchos_x86_64", "tvos_x86_64", + "tvos_sim_arm64", ] OSX_TOOLS_ARCHS = [