Skip to content

Commit 2f50607

Browse files
committed
Fix searching for SDKs when a --triple is specified along with the SDK name
Extend `selectBundle()` to use the existing `selectSwiftSDK(id:hostTriple:targetTriple)` overload, plus fix the latter to check the full triple string, which affects `swift sdk configure` also. Fixes #7973 and #9220
1 parent 6a5714d commit 2f50607

5 files changed

Lines changed: 47 additions & 3 deletions

File tree

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ public struct SwiftSDK: Equatable {
786786
swiftSDK = targetSwiftSDK
787787
} else if let swiftSDKSelector {
788788
do {
789-
swiftSDK = try store.selectBundle(matching: swiftSDKSelector, hostTriple: hostTriple)
789+
swiftSDK = try store.selectBundle(matching: swiftSDKSelector, hostTriple: hostTriple, targetTriple: customCompileTriple)
790790
} catch {
791791
// If a user-installed bundle for the selector doesn't exist, check if the
792792
// selector is recognized as a default SDK.

Sources/PackageModel/SwiftSDKs/SwiftSDKBundle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension [SwiftSDKBundle] {
6767
}
6868
}
6969

70-
return variant.swiftSDKs.first { $0.targetTriple == targetTriple }
70+
return variant.swiftSDKs.first { $0.targetTriple?.tripleString == targetTriple.tripleString }
7171
}
7272
}
7373
}

Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public final class SwiftSDKBundleStore {
4747

4848
enum Error: Swift.Error, CustomStringConvertible {
4949
case noMatchingSwiftSDK(selector: String, hostTriple: Triple)
50+
case noMatchingSwiftSDKWithTriple(selector: String, hostTriple: Triple, targetTriple: Triple)
5051

5152
var description: String {
5253
switch self {
@@ -56,6 +57,12 @@ public final class SwiftSDKBundleStore {
5657
`\(hostTriple.tripleString)`. Use `swift sdk list` command to see \
5758
available Swift SDKs.
5859
"""
60+
case let .noMatchingSwiftSDKWithTriple(selector, hostTriple, targetTriple):
61+
return """
62+
No Swift SDK found matching query `\(selector)`, target triple \
63+
`\(targetTriple.tripleString)`, and host triple `\(hostTriple.tripleString)`. \
64+
Use `swift sdk list` command to see available Swift SDKs.
65+
"""
5966
}
6067
}
6168
}
@@ -123,10 +130,12 @@ public final class SwiftSDKBundleStore {
123130
/// - Parameters:
124131
/// - query: either an artifact ID or target triple to filter with.
125132
/// - hostTriple: triple of the host building with these Swift SDKs.
133+
/// - targetTriple: optional separate target triple to look for
126134
/// - Returns: ``SwiftSDK`` value matching `query` either by artifact ID or target triple, `nil` if none found.
127135
public func selectBundle(
128136
matching selector: String,
129-
hostTriple: Triple
137+
hostTriple: Triple,
138+
targetTriple: Triple? = nil
130139
) throws -> SwiftSDK {
131140
let validBundles = try self.allValidBundles
132141

@@ -136,6 +145,18 @@ public final class SwiftSDKBundleStore {
136145
)
137146
}
138147

148+
if let triple = targetTriple {
149+
guard var selectedSwiftSDK = validBundles.selectSwiftSDK(
150+
id: selector,
151+
hostTriple: hostTriple,
152+
targetTriple: triple
153+
) else {
154+
throw Error.noMatchingSwiftSDKWithTriple(selector: selector, hostTriple: hostTriple, targetTriple: triple)
155+
}
156+
selectedSwiftSDK.applyPathCLIOptions()
157+
return selectedSwiftSDK
158+
}
159+
139160
guard var selectedSwiftSDKs = validBundles.selectSwiftSDK(
140161
matching: selector,
141162
hostTriple: hostTriple,

Tests/CommandsTests/SwiftSDKCommandTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,21 @@ struct SwiftSDKCommandTests {
295295
}
296296
}
297297

298+
await expectThrowsCommandExecutionError(
299+
try await command.execute(
300+
[
301+
"configure", "--show-configuration",
302+
"--swift-sdks-path", fixturePath.pathString,
303+
"test-artifact",
304+
"aarch64-unknown-linux-gnu11.0",
305+
]
306+
)
307+
) { error in
308+
let stderr = error.stderr
309+
#expect(stderr.contains("Error: Swift SDK with ID `test-artifact`, host triple "))
310+
#expect(stderr.contains(", and target triple aarch64-unknown-linux-gnu11.0 is not currently installed."))
311+
}
312+
298313
(stdout, stderr) = try await command.execute(
299314
["remove", "--swift-sdks-path", fixturePath.pathString, "test-artifact"])
300315

Tests/PackageModelTests/SwiftSDKBundleTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ final class SwiftSDKBundleTests: XCTestCase {
391391
bundleName: AbsolutePath(bundles[1].path).components.last!
392392
),
393393
])
394+
395+
let tripleSDK = try store.selectBundle(
396+
matching: "\(testArtifactID)1",
397+
hostTriple: Triple("arm64-apple-macosx14.0"),
398+
targetTriple: targetTriple
399+
)
400+
401+
XCTAssertEqual(tripleSDK.targetTriple, targetTriple)
394402
}
395403

396404
func testTargetSDKDerivation() async throws {

0 commit comments

Comments
 (0)