mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
Use SwiftPM's SDK computation logic (#1643)
Using `SwiftSDK.deriveTargetSwiftSDK`, which is the same method that SwiftPM's own CLI tools use to determine the SDK from passed-in info (target `--triple`, `--swift-sdk`, and host sdk). This allows us to better uphold the contract in the [Configuration File](d11c101ce2/Documentation/Configuration%20File.md (structure)) docs, namely that the `swiftSDK` param is "Equivalent to SwiftPM's `--swift-sdk` option" and similarly for `triple`.
As concrete examples of where (AFAICT) the current implementation diverges:
- Passing a `--triple` of `wasm32-unknown-wasi` to `swift-build` will use the toolchain-integrated Wasm SDK if one exists. Passing the same value to sourcekit-lsp does not do this.
- Perhaps more relevant: after landing https://github.com/swiftlang/swift-package-manager/pull/6828, this change will make it so that building for iOS is as simple as setting `"triple": "arm64-apple-ios"` in the config! Currently, it's necessary to set C/Swift flags and hardcode the sysroot. Should close https://github.com/swiftlang/sourcekit-lsp/issues/1587.
This PR depends on:
- https://github.com/swiftlang/swift-package-manager/pull/7925
This commit is contained in:
@@ -226,25 +226,23 @@ package actor SwiftPMBuildSystem {
|
||||
let hostSDK = try SwiftSDK.hostSwiftSDK(AbsolutePath(destinationToolchainBinDir))
|
||||
let hostSwiftPMToolchain = try UserToolchain(swiftSDK: hostSDK)
|
||||
|
||||
var destinationSDK: SwiftSDK
|
||||
if let swiftSDK = options.swiftPM.swiftSDK {
|
||||
let bundleStore = try SwiftSDKBundleStore(
|
||||
let destinationSDK = try SwiftSDK.deriveTargetSwiftSDK(
|
||||
hostSwiftSDK: hostSDK,
|
||||
hostTriple: hostSwiftPMToolchain.targetTriple,
|
||||
customCompileTriple: options.swiftPM.triple.map { try Triple($0) },
|
||||
swiftSDKSelector: options.swiftPM.swiftSDK,
|
||||
store: SwiftSDKBundleStore(
|
||||
swiftSDKsDirectory: fileSystem.getSharedSwiftSDKsDirectory(
|
||||
explicitDirectory: options.swiftPM.swiftSDKsDirectory.map { try AbsolutePath(validating: $0) }
|
||||
),
|
||||
fileSystem: fileSystem,
|
||||
observabilityScope: observabilitySystem.topScope,
|
||||
outputHandler: { _ in }
|
||||
)
|
||||
destinationSDK = try bundleStore.selectBundle(matching: swiftSDK, hostTriple: hostSwiftPMToolchain.targetTriple)
|
||||
} else {
|
||||
destinationSDK = hostSDK
|
||||
}
|
||||
),
|
||||
observabilityScope: observabilitySystem.topScope,
|
||||
fileSystem: fileSystem
|
||||
)
|
||||
|
||||
if let triple = options.swiftPM.triple {
|
||||
destinationSDK = hostSDK
|
||||
destinationSDK.targetTriple = try Triple(triple)
|
||||
}
|
||||
let destinationSwiftPMToolchain = try UserToolchain(swiftSDK: destinationSDK)
|
||||
|
||||
var location = try Workspace.Location(
|
||||
|
||||
Reference in New Issue
Block a user