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

Merged
merged 19 commits into from
Jul 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
72fb717
Allow omitting the target triple for swift sdk configure
marcprux Jun 21, 2025
4fdc6fe
Move SDK configuration to SwiftSDKConfigurationStore and add tests
marcprux Jun 24, 2025
018e73d
Make swiftSDKs(for:) private
marcprux Jun 24, 2025
1524b41
Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift
marcprux Jun 24, 2025
6d090cd
Update Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
marcprux Jun 24, 2025
94f0e72
Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift
marcprux Jun 24, 2025
7323ea6
Update Tests/PackageModelTests/SwiftSDKBundleTests.swift
marcprux Jun 24, 2025
d7ce846
Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift
marcprux Jun 24, 2025
bbc9e15
Update Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
marcprux Jun 24, 2025
bb6a0d8
Update format of if statement
marcprux Jun 24, 2025
bf6ea45
Make SwiftSDK.merge function internal and fix line-length formatting
marcprux Jun 24, 2025
6735809
Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift
marcprux Jun 24, 2025
dec4007
Add comments for PathsConfiguration
marcprux Jun 24, 2025
62596eb
Make SwiftSDKConfigurationStore.configure package accessible and add …
marcprux Jun 24, 2025
8271ac3
Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift
marcprux Jun 24, 2025
b8bc8d8
Fix line lengths in test case
marcprux Jun 24, 2025
b155f05
Fix windows path for sdkRootPath test case
marcprux Jun 27, 2025
de50fd3
Merge branch 'main' into issue-8584
marcprux Jul 7, 2025
2bd6b3e
Merge branch 'swiftlang:main' into issue-8584
marcprux Jul 11, 2025
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 @@ -21,7 +21,7 @@ sdk configure [--package-path=<package-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]
[--show-configuration] <sdk-id> [target-triple...] [--version]
[--help]
```

Expand Down
222 changes: 120 additions & 102 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,16 @@ 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 Expand Up @@ -259,14 +265,17 @@ public struct SwiftSDK: Equatable {
/// deserialization.
public private(set) var toolset: Toolset

public struct PathsConfiguration: Equatable {
/// The paths associated with a Swift SDK. The Path type can be a `String`
/// to encapsulate the arguments for the `SwiftSDKConfigurationStore.configure`
/// function, or can be a fully-realized `AbsolutePath` when deserialized from a configuration.
public struct PathsConfiguration<Path: Equatable>: Equatable {
public init(
sdkRootPath: Basics.AbsolutePath?,
swiftResourcesPath: Basics.AbsolutePath? = nil,
swiftStaticResourcesPath: Basics.AbsolutePath? = nil,
includeSearchPaths: [Basics.AbsolutePath]? = nil,
librarySearchPaths: [Basics.AbsolutePath]? = nil,
toolsetPaths: [Basics.AbsolutePath]? = nil
sdkRootPath: Path? = nil,
swiftResourcesPath: Path? = nil,
swiftStaticResourcesPath: Path? = nil,
includeSearchPaths: [Path]? = nil,
librarySearchPaths: [Path]? = nil,
toolsetPaths: [Path]? = nil
) {
self.sdkRootPath = sdkRootPath
self.swiftResourcesPath = swiftResourcesPath
Expand All @@ -277,22 +286,22 @@ public struct SwiftSDK: Equatable {
}

/// Root directory path of the SDK used to compile for the target triple.
public var sdkRootPath: Basics.AbsolutePath?
public var sdkRootPath: Path?

/// Path containing Swift resources for dynamic linking.
public var swiftResourcesPath: Basics.AbsolutePath?
public var swiftResourcesPath: Path?

/// Path containing Swift resources for static linking.
public var swiftStaticResourcesPath: Basics.AbsolutePath?
public var swiftStaticResourcesPath: Path?

/// Array of paths containing headers.
public var includeSearchPaths: [Basics.AbsolutePath]?
public var includeSearchPaths: [Path]?

/// Array of paths containing libraries.
public var librarySearchPaths: [Basics.AbsolutePath]?
public var librarySearchPaths: [Path]?

/// Array of paths containing toolset files.
public var toolsetPaths: [Basics.AbsolutePath]?
public var toolsetPaths: [Path]?

/// Initialize paths configuration from values deserialized using v3 schema.
/// - Parameters:
Expand All @@ -301,92 +310,53 @@ public struct SwiftSDK: Equatable {
fileprivate init(
_ properties: SerializedDestinationV3.TripleProperties,
swiftSDKDirectory: Basics.AbsolutePath? = nil
) throws {
if let swiftSDKDirectory {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
includeSearchPaths: try properties.includeSearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
librarySearchPaths: try properties.librarySearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
toolsetPaths: try properties.toolsetPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
}
)
} else {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath),
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0)
},
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
try AbsolutePath(validating: $0)
},
includeSearchPaths: try properties.includeSearchPaths?.map {
try AbsolutePath(validating: $0)
},
librarySearchPaths: try properties.librarySearchPaths?.map {
try AbsolutePath(validating: $0)
},
toolsetPaths: try properties.toolsetPaths?.map {
try AbsolutePath(validating: $0)
}
)
}
) throws where Path == Basics.AbsolutePath {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
includeSearchPaths: try properties.includeSearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
librarySearchPaths: try properties.librarySearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
toolsetPaths: try properties.toolsetPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
}
)
}

/// Initialize paths configuration from values deserialized using v4 schema.
/// - Parameters:
/// - properties: properties of a Swift SDK for the given triple.
/// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths.
fileprivate init(_ properties: SwiftSDKMetadataV4.TripleProperties, swiftSDKDirectory: Basics.AbsolutePath? = nil) throws {
if let swiftSDKDirectory {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
includeSearchPaths: try properties.includeSearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
librarySearchPaths: try properties.librarySearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
toolsetPaths: try properties.toolsetPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
}
)
} else {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath),
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0)
},
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
try AbsolutePath(validating: $0)
},
includeSearchPaths: try properties.includeSearchPaths?.map {
try AbsolutePath(validating: $0)
},
librarySearchPaths: try properties.librarySearchPaths?.map {
try AbsolutePath(validating: $0)
},
toolsetPaths: try properties.toolsetPaths?.map {
try AbsolutePath(validating: $0)
}
)
}
fileprivate init(
_ properties: SwiftSDKMetadataV4.TripleProperties,
swiftSDKDirectory: Basics.AbsolutePath? = nil
) throws where Path == Basics.AbsolutePath {
self.init(
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
swiftResourcesPath: try properties.swiftResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
includeSearchPaths: try properties.includeSearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
librarySearchPaths: try properties.librarySearchPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
},
toolsetPaths: try properties.toolsetPaths?.map {
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
}
)
}

public mutating func merge(with newConfiguration: Self) {
Expand Down Expand Up @@ -414,10 +384,48 @@ public struct SwiftSDK: Equatable {
self.toolsetPaths = toolsetPaths
}
}

mutating func merge(
with newConfiguration: PathsConfiguration<String>,
relativeTo basePath: Path?
) throws -> [String] where Path == Basics.AbsolutePath {
var updatedProperties: [String] = []
if let sdkRootPath = newConfiguration.sdkRootPath {
self.sdkRootPath = try AbsolutePath(validating: sdkRootPath, relativeTo: basePath)
updatedProperties.append("sdkRootPath")
}

if let swiftResourcesPath = newConfiguration.swiftResourcesPath {
self.swiftResourcesPath = try AbsolutePath(validating: swiftResourcesPath, relativeTo: basePath)
updatedProperties.append("swiftResourcesPath")
}

if let swiftStaticResourcesPath = newConfiguration.swiftStaticResourcesPath {
self.swiftResourcesPath = try AbsolutePath(validating: swiftStaticResourcesPath, relativeTo: basePath)
updatedProperties.append("swiftStaticResourcesPath")
}

if let includeSearchPaths = newConfiguration.includeSearchPaths, !includeSearchPaths.isEmpty {
self.includeSearchPaths = try includeSearchPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) }
updatedProperties.append("includeSearchPath")
}

if let librarySearchPaths = newConfiguration.librarySearchPaths, !librarySearchPaths.isEmpty {
self.librarySearchPaths = try librarySearchPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) }
updatedProperties.append("librarySearchPath")
}

if let toolsetPaths = newConfiguration.toolsetPaths, !toolsetPaths.isEmpty {
self.toolsetPaths = try toolsetPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) }
updatedProperties.append("toolsetPath")
}

return updatedProperties
}
}

/// Configuration of file system paths used by this Swift SDK when building.
public var pathsConfiguration: PathsConfiguration
public var pathsConfiguration: PathsConfiguration<Basics.AbsolutePath>

/// Creates a Swift SDK with the specified properties.
@available(*, deprecated, message: "use `init(targetTriple:sdkRootDir:toolset:)` instead")
Expand Down Expand Up @@ -464,7 +472,7 @@ public struct SwiftSDK: Equatable {
hostTriple: Triple? = nil,
targetTriple: Triple? = nil,
toolset: Toolset,
pathsConfiguration: PathsConfiguration,
pathsConfiguration: PathsConfiguration<Basics.AbsolutePath>,
supportsTesting: Bool
) {
let xctestSupport: XCTestSupport
Expand All @@ -489,7 +497,7 @@ public struct SwiftSDK: Equatable {
hostTriple: Triple? = nil,
targetTriple: Triple? = nil,
toolset: Toolset,
pathsConfiguration: PathsConfiguration,
pathsConfiguration: PathsConfiguration<Basics.AbsolutePath>,
xctestSupport: XCTestSupport = .supported
) {
self.hostTriple = hostTriple
Expand Down Expand Up @@ -1201,7 +1209,7 @@ extension Optional where Wrapped == [Basics.AbsolutePath] {
}
}

extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
extension SwiftSDK.PathsConfiguration: CustomStringConvertible where Path == Basics.AbsolutePath {
public var description: String {
"""
sdkRootPath: \(sdkRootPath.configurationString)
Expand All @@ -1213,3 +1221,13 @@ extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
"""
}
}

extension Basics.AbsolutePath {
fileprivate init(validating string: String, relativeTo basePath: Basics.AbsolutePath?) throws {
if let basePath {
try self.init(validating: string, relativeTo: basePath)
} else {
try self.init(validating: string)
}
}
}
2 changes: 1 addition & 1 deletion Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final class SwiftSDKBundleStore {
let fileSystem: any FileSystem

/// Observability scope used for logging.
private let observabilityScope: ObservabilityScope
let observabilityScope: ObservabilityScope

/// Closure invoked for output produced by this store during its operation.
private let outputHandler: (Output) -> Void
Expand Down
Loading