diff --git a/Sources/CoreCommands/Options.swift b/Sources/CoreCommands/Options.swift index 1a39d809ac1..6778ae33a06 100644 --- a/Sources/CoreCommands/Options.swift +++ b/Sources/CoreCommands/Options.swift @@ -463,7 +463,9 @@ public struct BuildOptions: ParsableArguments { } /// The compilation destination’s target triple. - @Option(name: .customLong("triple"), transform: Triple.init) + @Option(name: .customLong("triple"), + help: "Filter for selecting the target triple from a Swift SDK bundle to build with.", + transform: Triple.init) public var customCompileTriple: Triple? /// Path to the compilation destination’s SDK. diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift index fc22efa1947..37acf83b01d 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift @@ -784,10 +784,16 @@ public struct SwiftSDK: Equatable { let targetSwiftSDK = SwiftSDK.defaultSwiftSDK(for: targetTriple, hostSDK: hostSwiftSDK) { swiftSDK = targetSwiftSDK - } else if let swiftSDKSelector { + } else if swiftSDKSelector != nil || customCompileTriple != nil { do { var ID: String - (ID, swiftSDK) = try store.selectBundle(matching: swiftSDKSelector, hostTriple: hostTriple, targetTriple: customCompileTriple) + if let swiftSDKSelector { + (ID, swiftSDK) = try store.selectBundle(matching: swiftSDKSelector, hostTriple: hostTriple, targetTriple: customCompileTriple) + } else if let customCompileTriple { + (ID, swiftSDK) = try store.selectBundle(matching: customCompileTriple.tripleString, hostTriple: hostTriple) + } else { + fatalError("Neither an SDK nor a triple matched somehow.") + } // Override with user's manual config do { @@ -806,7 +812,7 @@ public struct SwiftSDK: Equatable { } catch { // If a user-installed bundle for the selector doesn't exist, check if the // selector is recognized as a default SDK. - if let targetTriple = try? Triple(swiftSDKSelector), + if let targetTriple = try? customCompileTriple ?? Triple(swiftSDKSelector!), let defaultSDK = SwiftSDK.defaultSwiftSDK(for: targetTriple, hostSDK: hostSwiftSDK) { swiftSDK = defaultSDK } else {