Skip to content

Commit

Permalink
Enable Apple Silicon iOS simulator support via use of new CPU type. T…
Browse files Browse the repository at this point in the history
…his will be removed in favor of platforms once moved onto the new toolchain resolution system.

PiperOrigin-RevId: 391596112
  • Loading branch information
Googler authored and copybara-github committed Aug 18, 2021
1 parent f0ff3c0 commit c1ea2d4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -292,7 +313,9 @@ public List<String> getMultiArchitectures(PlatformType platformType) {
*/
@Override
public ApplePlatform getSingleArchPlatform() {
return ApplePlatform.forTarget(applePlatformType, getSingleArchitecture());
return ApplePlatform.forTarget(
applePlatformType,
getSingleArchitecture(applePlatformType, appleCpus, /* removeSimPrefix= */ false));
}

/**
Expand Down Expand Up @@ -394,7 +417,8 @@ public static AppleBitcodeMode getAppleBitcodeMode(
PlatformType applePlatformType,
AppleCpus appleCpus,
EnumMap<ApplePlatform.PlatformType, AppleBitcodeMode> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> IOS_DEVICE_TARGET_CPUS =
ImmutableSet.of("ios_armv6", "ios_arm64", "ios_armv7", "ios_armv7s", "ios_arm64e");
private static final ImmutableSet<String> WATCHOS_SIMULATOR_TARGET_CPUS =
Expand Down

0 comments on commit c1ea2d4

Please sign in to comment.