Skip to content

[5.10] Fix backward compatibility in host triple checks #6925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/Basics/Triple+Basics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ extension Triple {
return ".resources"
}
}

public func isRuntimeCompatible(with triple: Triple) -> Bool {
if
self.arch == triple.arch &&
self.vendor == triple.vendor &&
self.os == triple.os &&
self.environment == triple.environment
{
return self.osVersion >= triple.osVersion
} else {
return false
}
}
}

extension Triple: CustomStringConvertible {
Expand Down
4 changes: 3 additions & 1 deletion Sources/PackageModel/SwiftSDKBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ extension [SwiftSDKBundle] {
for bundle in self {
for (artifactID, variants) in bundle.artifacts {
for variant in variants {
guard variant.metadata.supportedTriples.contains(hostTriple) else {
guard variant.metadata.supportedTriples.contains(where: { variantTriple in
hostTriple.isRuntimeCompatible(with: variantTriple)
}) else {
continue
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/BasicsTests/TripleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,11 @@ final class TripleTests: XCTestCase {
XCTAssertTriple("x86_64-unknown-windows-msvc", matches: (.x86_64, nil, nil, .win32, .msvc, .coff))
XCTAssertTriple("wasm32-unknown-wasi", matches: (.wasm32, nil, nil, .wasi, nil, .wasm))
}

func testIsRuntimeCompatibleWith() throws {
try XCTAssertTrue(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-macosx")))
try XCTAssertTrue(Triple("x86_64-unknown-linux").isRuntimeCompatible(with: Triple("x86_64-unknown-linux")))
try XCTAssertFalse(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-linux")))
try XCTAssertTrue(Triple("x86_64-apple-macosx14.0").isRuntimeCompatible(with: Triple("x86_64-apple-macosx13.0")))
}
}