Skip to content

Allow omitting the target triple for swift sdk configure #8856

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Manages configuration options for installed Swift SDKs.

```
sdk configure [--package-path=<package-path>] [--cache-path=<cache-path>] [--config-path=<config-path>] [--security-path=<security-path>] [--scratch-path=<scratch-path>] [--swift-sdks-path=<swift-sdks-path>] [--toolset=<toolset>...] [--pkg-config-path=<pkg-config-path>...] [--sdk-root-path=<sdk-root-path>] [--swift-resources-path=<swift-resources-path>] [--swift-static-resources-path=<swift-static-resources-path>] [--include-search-path=<include-search-path>...] [--library-search-path=<library-search-path>...] [--toolset-path=<toolset-path>...] [--reset] [--show-configuration] <sdk-id> <target-triple> [--version] [--help]
sdk configure [--package-path=<package-path>] [--cache-path=<cache-path>] [--config-path=<config-path>] [--security-path=<security-path>] [--scratch-path=<scratch-path>] [--swift-sdks-path=<swift-sdks-path>] [--toolset=<toolset>...] [--pkg-config-path=<pkg-config-path>...] [--sdk-root-path=<sdk-root-path>] [--swift-resources-path=<swift-resources-path>] [--swift-static-resources-path=<swift-static-resources-path>] [--include-search-path=<include-search-path>...] [--library-search-path=<library-search-path>...] [--toolset-path=<toolset-path>...] [--reset] [--show-configuration] <sdk-id> [<target-triple>] [--version] [--help]
```

- term **--package-path=\<package-path\>**:
Expand Down
17 changes: 12 additions & 5 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum SwiftSDKError: Swift.Error {
case unserializableMetadata

/// No configuration values are available for this Swift SDK and target triple.
case swiftSDKNotFound(artifactID: String, hostTriple: Triple, targetTriple: Triple)
case swiftSDKNotFound(artifactID: String, hostTriple: Triple, targetTriple: Triple?)

/// A Swift SDK bundle with this name is already installed, can't install a new bundle with the same name.
case swiftSDKBundleAlreadyInstalled(bundleName: String)
Expand Down Expand Up @@ -108,10 +108,17 @@ extension SwiftSDKError: CustomStringConvertible {
properties required for initialization
"""
case .swiftSDKNotFound(let artifactID, let hostTriple, let targetTriple):
return """
Swift SDK with ID `\(artifactID)`, host triple \(hostTriple), and target triple \(targetTriple) is not \
currently installed.
"""
if let targetTriple {
return """
Swift SDK with ID `\(artifactID)`, host triple \(hostTriple), and target triple \(targetTriple) is not \
currently installed.
"""
} else {
return """
Swift SDK with ID `\(artifactID)` is not \
currently installed.
"""
}
case .swiftSDKBundleAlreadyInstalled(let bundleName):
return """
Swift SDK bundle with name `\(bundleName)` is already installed. Can't install a new bundle \
Expand Down
16 changes: 16 additions & 0 deletions Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ public final class SwiftSDKConfigurationStore {
try encoder.encode(path: configurationPath, fileSystem: fileSystem, properties)
}

public func swiftSDKs(for id: String) throws -> [SwiftSDK] {
for bundle in try self.swiftSDKBundleStore.allValidBundles {
for (artifactID, variants) in bundle.artifacts {
guard artifactID == id else {
continue
}

for variant in variants {
return variant.swiftSDKs
}
}
}

return []
}

public func readConfiguration(
sdkID: String,
targetTriple: Triple
Expand Down
22 changes: 20 additions & 2 deletions Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
var sdkID: String

@Argument(help: "The target triple of the Swift SDK to configure.")
var targetTriple: String
var targetTriple: String?

/// The file system used by default by this command.
private var fileSystem: FileSystem { localFileSystem }
Expand Down Expand Up @@ -132,8 +132,24 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
hostTimeTriple: triple,
swiftSDKBundleStore: bundleStore
)
let targetTriple = try Triple(self.targetTriple)

let targetTriples: [Triple]
if let targetTriple = self.targetTriple {
targetTriples = try [Triple(targetTriple)]
} else {
// when target-triple is unspecified, configure every triple for the SDK
let validBundles = try configurationStore.swiftSDKs(for: sdkID)
targetTriples = validBundles.compactMap(\.targetTriple)
if targetTriples.isEmpty {
throw SwiftSDKError.swiftSDKNotFound(
artifactID: sdkID,
hostTriple: triple,
targetTriple: nil
)
}
}

for targetTriple in targetTriples {
guard let swiftSDK = try configurationStore.readConfiguration(
sdkID: sdkID,
targetTriple: targetTriple
Expand Down Expand Up @@ -216,6 +232,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {

var swiftSDK = swiftSDK
swiftSDK.pathsConfiguration = configuration
swiftSDK.targetTriple = targetTriple
try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: swiftSDK)

observabilityScope.emit(
Expand All @@ -229,6 +246,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
if observabilityScope.errorsReported {
throw ExitCode.failure
}
}
} catch {
commandError = error
}
Expand Down