Skip to content

Commit

Permalink
[apple] support tvos_sim_arm64 in toolchain (#14779)
Browse files Browse the repository at this point in the history
Closes #14439.

PiperOrigin-RevId: 427721738
(cherry picked from commit 207c31b)

Co-authored-by: Dan Fleming <dflems@spotify.com>
  • Loading branch information
brentleyjones and dflems authored Feb 10, 2022
1 parent 5356fed commit ffdd633
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public enum ApplePlatform implements ApplePlatformApi {
private static final ImmutableSet<String> WATCHOS_DEVICE_TARGET_CPUS =
ImmutableSet.of("watchos_armv7k", "watchos_arm64_32");
private static final ImmutableSet<String> TVOS_SIMULATOR_TARGET_CPUS =
ImmutableSet.of("tvos_x86_64");
ImmutableSet.of("tvos_x86_64", "tvos_sim_arm64");
private static final ImmutableSet<String> TVOS_DEVICE_TARGET_CPUS =
ImmutableSet.of("tvos_arm64");
private static final ImmutableSet<String> CATALYST_TARGET_CPUS =
Expand Down
4 changes: 4 additions & 0 deletions tools/osx/crosstool/BUILD.toolchains
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 11 additions & 3 deletions tools/osx/crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/osx/crosstool/osx_archs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OSX_TOOLS_NON_DEVICE_ARCHS = [
"watchos_i386",
"watchos_x86_64",
"tvos_x86_64",
"tvos_sim_arm64",
]

OSX_TOOLS_ARCHS = [
Expand Down

0 comments on commit ffdd633

Please sign in to comment.