Skip to content

Commit 28489b3

Browse files
authored
Preserve env in tripleString(forPlatformVersion:) (#6834)
Preserve the `environmentName` part of triples when altering the OS version with `Triple.tripleString(forPlatformVersion:)` ### Motivation: Building for the iOS simulator (and presumably anything other triple with a fourth component) would fail because we would generate the wrong swiftc/clang `-target`, incorrectly excluding the `Triple.environmentName`. ### Modifications: - Modify `tripleString(forPlatformVersion:)` to include `self.environmentName` if it is non-empty. ### Result: You can now build for the iOS simulator with ```shell swift build --triple arm64-apple-ios-simulator --sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" ``` or if you also pull #6828, just ```shell swift build --triple arm64-apple-ios-simulator ```
1 parent 55936dc commit 28489b3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Sources/Basics/Triple+Basics.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ extension Triple {
6464
/// This is currently meant for Apple platforms only.
6565
public func tripleString(forPlatformVersion version: String) -> String {
6666
precondition(isDarwin())
67-
// This function did not handle triples with a specific environments and
68-
// object formats previously to using SwiftDriver.Triple and still does
69-
// not.
7067
return """
7168
\(self.archName)-\
7269
\(self.vendorName)-\
73-
\(self.osNameUnversioned)\(version)
70+
\(self.osNameUnversioned)\(version)\
71+
\(self.environmentName.isEmpty ? "" : "-\(self.environmentName)")
7472
"""
7573
}
7674

Tests/BasicsTests/TripleTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ final class TripleTests: XCTestCase {
122122

123123
XCTAssertTriple("mips-apple-darwin19", forPlatformVersion: "", is: "mips-apple-darwin")
124124
XCTAssertTriple("mips-apple-darwin19", forPlatformVersion: "22", is: "mips-apple-darwin22")
125+
126+
XCTAssertTriple("arm64-apple-ios-simulator", forPlatformVersion: "", is: "arm64-apple-ios-simulator")
127+
XCTAssertTriple("arm64-apple-ios-simulator", forPlatformVersion: "13.0", is: "arm64-apple-ios13.0-simulator")
128+
129+
XCTAssertTriple("arm64-apple-ios12-simulator", forPlatformVersion: "", is: "arm64-apple-ios-simulator")
130+
XCTAssertTriple("arm64-apple-ios12-simulator", forPlatformVersion: "13.0", is: "arm64-apple-ios13.0-simulator")
125131
}
126132

127133
func testKnownTripleParsing() {

0 commit comments

Comments
 (0)