Skip to content

Commit 8f43950

Browse files
authored
Move OS component version comparison to isRuntimeCompatible (#6925)
Cherry-pick of #6819. When setting host triple in Swift SDKs to `arm64-apple-macosx13.0` to allow cross-compiling from an older version of macOS, this triple is not recognized as directly matching `arm64-apple-macosx14.0` on a newer version of macOS. We should support backward compatibility with Swift SDKs that were built for older version of macOS. Resolves rdar://113967401. ``` # Conflicts: # Sources/PackageModel/SwiftSDKBundle.swift ```
1 parent efa222a commit 8f43950

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Sources/Basics/Triple+Basics.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,19 @@ extension Triple {
183183
return ".resources"
184184
}
185185
}
186+
187+
public func isRuntimeCompatible(with triple: Triple) -> Bool {
188+
if
189+
self.arch == triple.arch &&
190+
self.vendor == triple.vendor &&
191+
self.os == triple.os &&
192+
self.environment == triple.environment
193+
{
194+
return self.osVersion >= triple.osVersion
195+
} else {
196+
return false
197+
}
198+
}
186199
}
187200

188201
extension Triple: CustomStringConvertible {

Sources/PackageModel/SwiftSDKBundle.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ extension [SwiftSDKBundle] {
429429
for bundle in self {
430430
for (artifactID, variants) in bundle.artifacts {
431431
for variant in variants {
432-
guard variant.metadata.supportedTriples.contains(hostTriple) else {
432+
guard variant.metadata.supportedTriples.contains(where: { variantTriple in
433+
hostTriple.isRuntimeCompatible(with: variantTriple)
434+
}) else {
433435
continue
434436
}
435437

Tests/BasicsTests/TripleTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,11 @@ final class TripleTests: XCTestCase {
165165
XCTAssertTriple("x86_64-unknown-windows-msvc", matches: (.x86_64, nil, nil, .win32, .msvc, .coff))
166166
XCTAssertTriple("wasm32-unknown-wasi", matches: (.wasm32, nil, nil, .wasi, nil, .wasm))
167167
}
168+
169+
func testIsRuntimeCompatibleWith() throws {
170+
try XCTAssertTrue(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-macosx")))
171+
try XCTAssertTrue(Triple("x86_64-unknown-linux").isRuntimeCompatible(with: Triple("x86_64-unknown-linux")))
172+
try XCTAssertFalse(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-linux")))
173+
try XCTAssertTrue(Triple("x86_64-apple-macosx14.0").isRuntimeCompatible(with: Triple("x86_64-apple-macosx13.0")))
174+
}
168175
}

0 commit comments

Comments
 (0)