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 909d871655cb25..caaab4a01c3d2a 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 @@ -67,9 +67,13 @@ public class AppleConfiguration extends Fragment implements AppleConfigurationAp */ public static final String APPLE_SDK_PLATFORM_ENV_NAME = "APPLE_SDK_PLATFORM"; - /** Prefix for iOS cpu values. */ + /** Prefix for iOS cpu values */ public static final String IOS_CPU_PREFIX = "ios_"; + // 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_"; + /** Default cpu for iOS builds. */ @VisibleForTesting static final String DEFAULT_IOS_CPU = "x86_64"; @@ -214,16 +218,33 @@ public String getIosCpu() { */ @Override public String getSingleArchitecture() { - return getSingleArchitecture(applePlatformType, appleCpus); + return getSingleArchitecture(applePlatformType, appleCpus, /* removeSimPrefix= */ true); } - private static String getSingleArchitecture(PlatformType applePlatformType, AppleCpus appleCpus) { + private static String getSingleArchitecture( + PlatformType applePlatformType, AppleCpus appleCpus, boolean removeSimPrefix) { + // 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. + // TODO(b/180572694): Remove removeSimPrefix parameter once platforms are used instead of CPU if (!Strings.isNullOrEmpty(appleCpus.appleSplitCpu())) { - return 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; } switch (applePlatformType) { case IOS: - return Iterables.getFirst(appleCpus.iosMultiCpus(), appleCpus.iosCpu()); + { + 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; + } case WATCHOS: return appleCpus.watchosCpus().get(0); case TVOS: @@ -292,7 +313,9 @@ public List getMultiArchitectures(PlatformType platformType) { */ @Override public ApplePlatform getSingleArchPlatform() { - return ApplePlatform.forTarget(applePlatformType, getSingleArchitecture()); + return ApplePlatform.forTarget( + applePlatformType, + getSingleArchitecture(applePlatformType, appleCpus, /* removeSimPrefix= */ false)); } /** @@ -394,7 +417,8 @@ public static AppleBitcodeMode getAppleBitcodeMode( PlatformType applePlatformType, AppleCpus appleCpus, EnumMap platformBitcodeModes) { - String architecture = getSingleArchitecture(applePlatformType, appleCpus); + String architecture = + getSingleArchitecture(applePlatformType, appleCpus, /* removeSimPrefix= */ false); String cpuString = ApplePlatform.cpuStringForTarget(applePlatformType, architecture); if (ApplePlatform.isApplePlatform(cpuString)) { ApplePlatform platform = ApplePlatform.forTarget(applePlatformType, architecture); 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 1470e39b2356d2..68eb162ad7ef93 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 @@ -41,8 +41,9 @@ public enum ApplePlatform implements ApplePlatformApi { WATCHOS_SIMULATOR("watchos_simulator", "WatchSimulator", PlatformType.WATCHOS, false), CATALYST("catalyst", "MacOSX", PlatformType.CATALYST, true); + // TODO(b/180572694): Remove ios_sim_arm64 after platforms based toolchain resolution supported. private static final ImmutableSet IOS_SIMULATOR_TARGET_CPUS = - ImmutableSet.of("ios_x86_64", "ios_i386"); + ImmutableSet.of("ios_x86_64", "ios_i386", "ios_sim_arm64"); private static final ImmutableSet IOS_DEVICE_TARGET_CPUS = ImmutableSet.of("ios_armv6", "ios_arm64", "ios_armv7", "ios_armv7s", "ios_arm64e"); private static final ImmutableSet WATCHOS_SIMULATOR_TARGET_CPUS =