Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
[Apple] Fix iPhone simulator arm64 swift triple (#2621)
Browse files Browse the repository at this point in the history
* Fix iPhoneSimulator arm64 swift triplet

* fix unit tests

* Empty commit to retrigger CI

* fix WatchSimulator architectures

Co-authored-by: Lucas Marçal <[email protected]>
  • Loading branch information
Lcsmarcal and Lucas Marçal authored Aug 27, 2021
1 parent ea66748 commit 5444652
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/com/facebook/buck/apple/AppleToolchainDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public BuildRule createBuildRule(
args.getArchitecture(),
"apple",
applePlatform.getSwiftName().orElse(applePlatform.getName()),
args.getMinVersion());
args.getMinVersion(),
applePlatform.getIsSimulator());
Optional<SwiftPlatform> swiftPlatform =
swiftToolchainRule
.map(SwiftToolchainBuildRule.class::cast)
Expand Down
12 changes: 8 additions & 4 deletions src/com/facebook/buck/apple/toolchain/ApplePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class ApplePlatform implements Comparable<ApplePlatform>, AddsTo
ImmutableApplePlatform.builder()
.setName("iphonesimulator")
.setSwiftName("ios")
.setArchitectures(ImmutableList.of("i386", "x86_64"))
.setArchitectures(ImmutableList.of("i386", "x86_64", "arm64"))
.setMinVersionFlagPrefix("-mios-simulator-version-min=")
// only used for legacy watch apps
.setStubBinaryPath(Optional.of("Library/Application Support/WatchKit/WK"))
Expand All @@ -59,7 +59,7 @@ public abstract class ApplePlatform implements Comparable<ApplePlatform>, AddsTo
public static final ApplePlatform WATCHSIMULATOR =
ImmutableApplePlatform.builder()
.setName("watchsimulator")
.setArchitectures(ImmutableList.of("i386", "x86_64"))
.setArchitectures(ImmutableList.of("i386", "x86_64", "arm64"))
.setMinVersionFlagPrefix("-mwatchos-simulator-version-min=")
.setStubBinaryPath(Optional.of("Library/Application Support/WatchKit/WK"))
.build();
Expand All @@ -73,14 +73,14 @@ public abstract class ApplePlatform implements Comparable<ApplePlatform>, AddsTo
public static final ApplePlatform APPLETVSIMULATOR =
ImmutableApplePlatform.builder()
.setName("appletvsimulator")
.setArchitectures(ImmutableList.of("x86_64"))
.setArchitectures(ImmutableList.of("arm64", "x86_64"))
.setMinVersionFlagPrefix("-mtvos-simulator-version-min=")
.setSwiftName("tvos")
.build();
public static final ApplePlatform MACOSX =
ImmutableApplePlatform.builder()
.setName("macosx")
.setArchitectures(ImmutableList.of("i386", "x86_64"))
.setArchitectures(ImmutableList.of("i386", "x86_64", "arm64"))
.setAppIncludesFrameworks(true)
.build();
public static final ApplePlatform DRIVERKIT =
Expand Down Expand Up @@ -144,6 +144,10 @@ public ApplePlatformType getType() {
return ApplePlatformType.of(getName());
}

public boolean getIsSimulator() {
return isSimulator(getName());
}

public static boolean needsCodeSign(String name) {
return name.startsWith(IPHONEOS.getName())
|| name.startsWith(IPHONESIMULATOR.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ public static AppleCxxPlatform buildWithXcodeToolFinder(
targetArchitecture,
"apple",
applePlatform.getSwiftName().orElse(applePlatform.getName()),
minVersion),
minVersion,
applePlatform.getIsSimulator()),
version,
targetSdk,
swiftSdkPathsBuilder.build(),
Expand Down
15 changes: 11 additions & 4 deletions src/com/facebook/buck/swift/toolchain/SwiftTargetTriple.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,26 @@ public abstract class SwiftTargetTriple implements AddsToRuleKey {
@AddToRuleKey
public abstract String getTargetSdkVersion();

@AddToRuleKey
public abstract Boolean getIsSimulator();

public String getTriple() {
return getArchitecture() + "-" + getVendor() + "-" + getPlatformName() + getTargetSdkVersion();
String triple = getArchitecture() + "-" + getVendor() + "-" + getPlatformName() + getTargetSdkVersion();
if(getIsSimulator()) {
triple = triple + "-simulator";
}
return triple;
}

public static SwiftTargetTriple of(
String architecture, String vendor, String platformName, String targetSdkVersion) {
return ImmutableSwiftTargetTriple.of(architecture, vendor, platformName, targetSdkVersion);
String architecture, String vendor, String platformName, String targetSdkVersion, Boolean isSimulator) {
return ImmutableSwiftTargetTriple.of(architecture, vendor, platformName, targetSdkVersion, isSimulator);
}

public SwiftTargetTriple withTargetSdkVersion(String targetSdkVersion) {
if (targetSdkVersion.equals(getTargetSdkVersion())) {
return this;
}
return of(getArchitecture(), getVendor(), getPlatformName(), targetSdkVersion);
return of(getArchitecture(), getVendor(), getPlatformName(), targetSdkVersion, getIsSimulator());
}
}
4 changes: 2 additions & 2 deletions test/com/facebook/buck/apple/AppleBinaryIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ public void testAppleBinaryBuildsFatBinariesWithSwift() throws Exception {
workspace.setUp();
BuildTarget target =
BuildTargetFactory.newInstance(
"//:DemoAppBinary#iphonesimulator-i386,iphonesimulator-x86_64,no-linkermap");
"//:DemoAppBinary#iphonesimulator-i386,iphonesimulator-x86_64,iphonesimulator-arm64,no-linkermap");
workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();

Path output =
Expand All @@ -1541,7 +1541,7 @@ public void testAppleBinaryBuildsFatBinariesWithSwift() throws Exception {
workspace.runCommand("file", output.toString()).getStdout().get(),
containsString("executable"));
ProcessExecutor.Result lipoVerifyResult =
workspace.runCommand("lipo", output.toString(), "-verify_arch", "i386", "x86_64");
workspace.runCommand("lipo", output.toString(), "-verify_arch", "i386", "x86_64", "arm64");
assertEquals(lipoVerifyResult.getStderr().orElse(""), 0, lipoVerifyResult.getExitCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ public void checkSwiftPlatformUsesCorrectMinTargetSdk() {
assertThat(swiftc, instanceOf(VersionedTool.class));
assertThat(
swiftPlatform.getSwiftTarget(),
equalTo(SwiftTargetTriple.of("i386", "apple", "ios", "7.0")));
equalTo(SwiftTargetTriple.of("i386", "apple", "ios", "7.0", false)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public void shouldResolveSdkVersionConflicts() throws IOException {
.setName("macosx")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addAllToolchains(toolchains.values())
.build();
AppleSdk macosxDebugSdk =
AppleSdk.builder()
.setName("macosx-Debug")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addAllToolchains(toolchains.values())
.build();
AppleSdkPaths macosxReleasePaths =
Expand Down Expand Up @@ -167,7 +167,7 @@ public void shouldFindPlatformsInExtraPlatformDirectories() throws IOException {
.setName("macosx10.9")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addAllToolchains(toolchains.values())
.build();
AppleSdkPaths macosx109Paths =
Expand Down Expand Up @@ -210,7 +210,7 @@ public void ignoresInvalidExtraPlatformDirectories() throws IOException {
.setName("macosx10.9")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addAllToolchains(toolchains.values())
.build();
AppleSdkPaths macosx109Paths =
Expand Down Expand Up @@ -284,7 +284,7 @@ public void shouldIgnoreSdkWithBadSymlink() throws Exception {
.setName("macosx10.9")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addAllToolchains(toolchains.values())
.build();
AppleSdkPaths macosx109Paths =
Expand Down Expand Up @@ -326,7 +326,7 @@ public void appleSdkPathsBuiltFromDirectory() throws Exception {
.setName("macosx10.9")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addToolchains(getDefaultToolchain(root))
.build();
AppleSdkPaths macosx109Paths =
Expand Down Expand Up @@ -358,7 +358,7 @@ public void appleSdkPathsBuiltFromDirectory() throws Exception {
.setName("iphonesimulator8.0")
.setVersion("8.0")
.setApplePlatform(ApplePlatform.IPHONESIMULATOR)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addToolchains(getDefaultToolchain(root))
.build();
AppleSdkPaths iphonesimulator80Paths =
Expand Down Expand Up @@ -392,7 +392,7 @@ public void appleSdkPathsBuiltFromDirectory() throws Exception {
.setName("watchsimulator2.0")
.setVersion("2.0")
.setApplePlatform(ApplePlatform.WATCHSIMULATOR)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addToolchains(getDefaultToolchain(root))
.build();
AppleSdkPaths watchsimulator20Paths =
Expand Down Expand Up @@ -425,7 +425,7 @@ public void appleSdkPathsBuiltFromDirectory() throws Exception {
.setName("appletvsimulator9.1")
.setVersion("9.1")
.setApplePlatform(ApplePlatform.APPLETVSIMULATOR)
.addArchitectures("x86_64")
.addArchitectures("x86_64", "arm64")
.addToolchains(getDefaultToolchain(root))
.build();
AppleSdkPaths appletvsimulator91Paths =
Expand Down Expand Up @@ -501,7 +501,7 @@ public void multipleAppleSdkPathsPerPlatformBuiltFromDirectory() throws Exceptio
.setName("macosx10.9")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addToolchains(getDefaultToolchain(root))
.build();
AppleSdkPaths macosx109Paths =
Expand Down Expand Up @@ -533,7 +533,7 @@ public void multipleAppleSdkPathsPerPlatformBuiltFromDirectory() throws Exceptio
.setName("iphonesimulator8.0")
.setVersion("8.0")
.setApplePlatform(ApplePlatform.IPHONESIMULATOR)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addToolchains(getDefaultToolchain(root))
.build();
AppleSdkPaths iphonesimulator80Paths =
Expand Down Expand Up @@ -567,7 +567,7 @@ public void multipleAppleSdkPathsPerPlatformBuiltFromDirectory() throws Exceptio
.setName("iphonesimulator8.1")
.setVersion("8.1")
.setApplePlatform(ApplePlatform.IPHONESIMULATOR)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addToolchains(getDefaultToolchain(root))
.build();
AppleSdkPaths iphonesimulator81Paths =
Expand Down Expand Up @@ -625,7 +625,7 @@ public void shouldDiscoverRealSdkThroughAbsoluteSymlink() throws IOException {
.setName("macosx10.9")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addAllToolchains(toolchains.values())
.build();
AppleSdkPaths macosx109Paths =
Expand Down Expand Up @@ -751,7 +751,7 @@ public void overrideToolchains() throws IOException {
.setName("macosx10.9")
.setVersion("10.9")
.setApplePlatform(ApplePlatform.MACOSX)
.addArchitectures("i386", "x86_64")
.addArchitectures("i386", "x86_64", "arm64")
.addAllToolchains(ImmutableList.of(overrideToolchain1, overrideToolchain2))
.build();
AppleSdkPaths macosx109Paths =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testStaticLinkerFlagsOnMobile() {
swiftcTool,
Optional.of(swiftStdTool),
true,
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3"));
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3", false));

ImmutableList.Builder<Arg> staticArgsBuilder = ImmutableList.builder();
SwiftRuntimeNativeLinkableGroup.populateLinkerArguments(
Expand Down Expand Up @@ -152,7 +152,7 @@ public void testStaticLinkerFlagsOnMac() {
swiftcTool,
Optional.of(swiftStdTool),
true,
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3"));
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3", false));

ImmutableList.Builder<Arg> sharedArgsBuilder = ImmutableList.builder();
SwiftRuntimeNativeLinkableGroup.populateLinkerArguments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void setUp() {
@Test
public void testBuildSwiftPlatformWithEmptyToolchainPaths() throws IOException {
Path developerDir = tmp.newFolder("Developer");
SwiftTargetTriple triple = SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3");
SwiftTargetTriple triple = SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3", false);
SwiftPlatform swiftPlatform =
SwiftPlatformFactory.build(
createAppleSdk(),
Expand All @@ -113,7 +113,7 @@ public void testBuildSwiftPlatformWithNonEmptyLookupPathWithoutTools() throws IO
swiftcTool,
Optional.of(swiftStdTool),
true,
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3"));
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3", false));
assertThat(swiftPlatform.getSwiftRuntimePathsForBundling(), empty());
assertThat(swiftPlatform.getSwiftStaticRuntimePaths(), empty());
}
Expand All @@ -136,7 +136,7 @@ public void testBuildSwiftPlatformWithNonEmptyLookupPathWithTools() throws IOExc
swiftcTool,
Optional.of(swiftStdTool),
true,
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3"));
SwiftTargetTriple.of("x86_64", "apple", "ios", "9.3", false));
assertThat(swiftPlatform.getSwiftRuntimePathsForBundling(), hasSize(1));
assertThat(swiftPlatform.getSwiftStaticRuntimePaths(), hasSize(2));
}
Expand Down

0 comments on commit 5444652

Please sign in to comment.