Skip to content

Commit

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

PiperOrigin-RevId: 427721738
  • Loading branch information
dflems authored and copybara-github committed Feb 10, 2022
1 parent 012cab5 commit 207c31b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 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 @@ -229,25 +229,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
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _IOS_SIMULATOR_TARGET_CPUS = ["ios_x86_64", "ios_i386", "ios_sim_arm64"]
_IOS_DEVICE_TARGET_CPUS = ["ios_armv6", "ios_arm64", "ios_armv7", "ios_armv7s", "ios_arm64e"]
_WATCHOS_SIMULATOR_TARGET_CPUS = ["watchos_i386", "watchos_x86_64", "watchos_arm64"]
_WATCHOS_DEVICE_TARGET_CPUS = ["watchos_armv7k", "watchos_arm64_32"]
_TVOS_SIMULATOR_TARGET_CPUS = ["tvos_x86_64"]
_TVOS_SIMULATOR_TARGET_CPUS = ["tvos_x86_64", "tvos_sim_arm64"]
_TVOS_DEVICE_TARGET_CPUS = ["tvos_arm64"]
_CATALYST_TARGET_CPUS = ["catalyst_x86_64"]
_MACOS_TARGET_CPUS = ["darwin_x86_64", "darwin_arm64", "darwin_arm64e", "darwin"]
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 @@ -76,6 +76,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 @@ -105,7 +107,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 @@ -770,7 +772,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 @@ -930,6 +933,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 @@ -1001,6 +1005,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 @@ -1290,7 +1295,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 @@ -1766,6 +1772,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 @@ -2851,6 +2858,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 207c31b

Please sign in to comment.