Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Look up WasmKit in the host toolchain directory
  • Loading branch information
MaxDesiatov committed May 14, 2025
commit c3f31d0963de2749a3318b555c9e8e77e77f3bba
4 changes: 1 addition & 3 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,7 @@ extension SwiftSDK {
[:]
}
let pathStrings = properties.toolsetPaths ?? []
let toolset = try pathStrings.reduce(
into: Toolset(knownTools: defaultTools, rootPaths: [hostToolchainBinDir])
) {
let toolset = try pathStrings.reduce(into: Toolset(knownTools: defaultTools, rootPaths: [])) {
try $0.merge(
with: Toolset(
from: .init(validating: $1, relativeTo: swiftSDKDirectory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ protocol ConfigurationSubcommand: SwiftSDKSubcommand {
extension ConfigurationSubcommand {
func run(
hostTriple: Triple,
hostToolchain: UserToolchain,
_ swiftSDKsDirectory: AbsolutePath,
_ observabilityScope: ObservabilityScope
) throws {
fputs("warning: `swift sdk configuration` command is deprecated and will be removed in a future version of SwiftPM. Use `swift sdk configure` instead.\n", stderr)

let bundleStore = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: hostToolchain.swiftCompilerPath.parentDirectory,
fileSystem: self.fileSystem,
observabilityScope: observabilityScope,
outputHandler: { print($0) }
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
do {
let bundleStore = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: hostToolchain.swiftCompilerPath.parentDirectory,
fileSystem: self.fileSystem,
observabilityScope: observabilityScope,
outputHandler: { print($0) }
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftSDKCommand/InstallSwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct InstallSwiftSDK: SwiftSDKSubcommand {

func run(
hostTriple: Triple,
hostToolchain: UserToolchain,
_ swiftSDKsDirectory: AbsolutePath,
_ observabilityScope: ObservabilityScope
) async throws {
Expand All @@ -58,6 +59,7 @@ struct InstallSwiftSDK: SwiftSDKSubcommand {

let store = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: hostToolchain.swiftCompilerPath.parentDirectory,
fileSystem: self.fileSystem,
observabilityScope: observabilityScope,
outputHandler: { print($0.description) },
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftSDKCommand/ListSwiftSDKs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ package struct ListSwiftSDKs: SwiftSDKSubcommand {

func run(
hostTriple: Triple,
hostToolchain: UserToolchain,
_ swiftSDKsDirectory: AbsolutePath,
_ observabilityScope: ObservabilityScope
) throws {
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: hostToolchain.swiftCompilerPath.parentDirectory,
fileSystem: fileSystem,
observabilityScope: observabilityScope,
outputHandler: { print($0.description) }
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftSDKCommand/RemoveSwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ package struct RemoveSwiftSDK: SwiftSDKSubcommand {

func run(
hostTriple: Triple,
hostToolchain: UserToolchain,
_ swiftSDKsDirectory: Basics.AbsolutePath,
_ observabilityScope: ObservabilityScope
) async throws {
Expand All @@ -47,6 +48,7 @@ package struct RemoveSwiftSDK: SwiftSDKSubcommand {
} else {
let bundleStore = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: hostToolchain.swiftCompilerPath.parentDirectory,
fileSystem: self.fileSystem,
observabilityScope: observabilityScope,
outputHandler: { print($0) }
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftSDKCommand/SwiftSDKSubcommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protocol SwiftSDKSubcommand: AsyncParsableCommand {
/// - observabilityScope: observability scope used for logging.
func run(
hostTriple: Triple,
hostToolchain: UserToolchain,
_ swiftSDKsDirectory: AbsolutePath,
_ observabilityScope: ObservabilityScope
) async throws
Expand Down Expand Up @@ -71,7 +72,7 @@ extension SwiftSDKSubcommand {

var commandError: Error? = nil
do {
try await self.run(hostTriple: triple, swiftSDKsDirectory, observabilityScope)
try await self.run(hostTriple: triple, hostToolchain: hostToolchain, swiftSDKsDirectory, observabilityScope)
if observabilityScope.errorsReported {
throw ExitCode.failure
}
Expand Down
13 changes: 11 additions & 2 deletions Tests/PackageModelTests/SwiftSDKBundleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ final class SwiftSDKBundleTests: XCTestCase {
var output = [SwiftSDKBundleStore.Output]()
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: tmpDir,
hostToolchainBinDir: tmpDir,
fileSystem: localFileSystem,
observabilityScope: observabilityScope,
outputHandler: {
Expand Down Expand Up @@ -208,6 +209,7 @@ final class SwiftSDKBundleTests: XCTestCase {
var output = [SwiftSDKBundleStore.Output]()
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: "/tmp",
fileSystem: fileSystem,
observabilityScope: system.topScope,
outputHandler: {
Expand Down Expand Up @@ -300,6 +302,7 @@ final class SwiftSDKBundleTests: XCTestCase {
var output = [SwiftSDKBundleStore.Output]()
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: "/tmp",
fileSystem: fileSystem,
observabilityScope: system.topScope,
outputHandler: {
Expand Down Expand Up @@ -340,6 +343,7 @@ final class SwiftSDKBundleTests: XCTestCase {
var output = [SwiftSDKBundleStore.Output]()
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: "/tmp",
fileSystem: fileSystem,
observabilityScope: system.topScope,
outputHandler: {
Expand Down Expand Up @@ -381,9 +385,11 @@ final class SwiftSDKBundleTests: XCTestCase {
let system = ObservabilitySystem.makeForTesting()
let hostSwiftSDK = try SwiftSDK.hostSwiftSDK(environment: [:])
let hostTriple = try! Triple("arm64-apple-macosx14.0")
let hostToolchainBinDir = AbsolutePath("/tmp")
let archiver = MockArchiver()
let store = SwiftSDKBundleStore(
swiftSDKsDirectory: swiftSDKsDirectory,
hostToolchainBinDir: hostToolchainBinDir,
fileSystem: fileSystem,
observabilityScope: system.topScope,
outputHandler: { _ in }
Expand Down Expand Up @@ -434,7 +440,7 @@ final class SwiftSDKBundleTests: XCTestCase {
// With a target SDK selector, SDK should be chosen from the store.
XCTAssertEqual(targetSwiftSDK.targetTriple, targetTriple)
// No toolset in the SDK, so it should be the same as the host SDK.
XCTAssertEqual(targetSwiftSDK.toolset.rootPaths, hostSwiftSDK.toolset.rootPaths)
XCTAssertEqual(targetSwiftSDK.toolset.rootPaths, [hostToolchainBinDir] + hostSwiftSDK.toolset.rootPaths)
}

do {
Expand All @@ -447,7 +453,10 @@ final class SwiftSDKBundleTests: XCTestCase {
fileSystem: fileSystem
)
// With toolset in the target SDK, it should contain the host toolset roots at the end.
XCTAssertEqual(targetSwiftSDK.toolset.rootPaths, [toolsetRootPath] + hostSwiftSDK.toolset.rootPaths)
XCTAssertEqual(
targetSwiftSDK.toolset.rootPaths,
[toolsetRootPath, hostToolchainBinDir] + hostSwiftSDK.toolset.rootPaths
)
}

do {
Expand Down
49 changes: 48 additions & 1 deletion Tests/PackageModelTests/SwiftSDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private let hostTriple = try! Triple("arm64-apple-darwin22.1.0")
private let olderHostTriple = try! Triple("arm64-apple-darwin20.1.0")
private let linuxGNUTargetTriple = try! Triple("x86_64-unknown-linux-gnu")
private let linuxMuslTargetTriple = try! Triple("x86_64-unknown-linux-musl")
private let wasiTargetTriple = try! Triple("wasm32-unknown-wasi")
private let extraFlags = BuildFlags(
cCompilerFlags: ["-fintegrated-as"],
cxxCompilerFlags: ["-fno-exceptions"],
Expand Down Expand Up @@ -139,6 +140,22 @@ private let invalidToolsetDestinationV3 = (
"""# as SerializedJSON
)


private let wasiWithoutToolsetsSwiftSDKv4 = (
path: bundleRootPath.appending(component: "wasiSwiftSDKv4.json"),
json: #"""
{
"targetTriples": {
"\#(wasiTargetTriple.tripleString)": {
"sdkRootPath": "\#(sdkRootDir)",
"toolsetPaths": []
}
},
"schemaVersion": "4.0"
}
"""# as SerializedJSON
)

private let toolsetNoRootSwiftSDKv4 = (
path: bundleRootPath.appending(component: "toolsetNoRootSwiftSDKv4.json"),
json: #"""
Expand Down Expand Up @@ -347,12 +364,13 @@ private let testFiles: [(path: AbsolutePath, json: SerializedJSON)] = [
missingToolsetSwiftSDKv4,
invalidVersionSwiftSDKv4,
invalidToolsetSwiftSDKv4,
wasiWithoutToolsetsSwiftSDKv4,
otherToolsNoRoot,
someToolsWithRoot,
invalidToolset,
]

final class DestinationTests: XCTestCase {
final class SwiftSDKTests: XCTestCase {
func testDestinationCodable() throws {
let fs = InMemoryFileSystem()
try fs.createDirectory(AbsolutePath(validating: "/tools"))
Expand All @@ -367,6 +385,7 @@ final class DestinationTests: XCTestCase {

let destinationV1Decoded = try SwiftSDK.decode(
fromFile: destinationV1.path,
hostToolchainBinDir: bundleRootPath.appending(toolchainBinDir),
fileSystem: fs,
observabilityScope: observability
)
Expand All @@ -389,6 +408,7 @@ final class DestinationTests: XCTestCase {

let destinationV2Decoded = try SwiftSDK.decode(
fromFile: destinationV2.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)
Expand All @@ -397,6 +417,7 @@ final class DestinationTests: XCTestCase {

let toolsetNoRootDestinationV3Decoded = try SwiftSDK.decode(
fromFile: toolsetNoRootDestinationV3.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)
Expand All @@ -405,6 +426,7 @@ final class DestinationTests: XCTestCase {

let toolsetRootDestinationV3Decoded = try SwiftSDK.decode(
fromFile: toolsetRootDestinationV3.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)
Expand All @@ -413,6 +435,7 @@ final class DestinationTests: XCTestCase {

XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: missingToolsetDestinationV3.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)) {
Expand All @@ -429,12 +452,14 @@ final class DestinationTests: XCTestCase {
}
XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: invalidVersionDestinationV3.path,
hostToolchainBinDir: bundleRootPath.appending(toolchainBinDir),
fileSystem: fs,
observabilityScope: observability
))

XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: invalidToolsetDestinationV3.path,
hostToolchainBinDir: bundleRootPath.appending(toolchainBinDir),
fileSystem: fs,
observabilityScope: observability
)) {
Expand All @@ -447,6 +472,7 @@ final class DestinationTests: XCTestCase {

let toolsetNoRootSwiftSDKv4Decoded = try SwiftSDK.decode(
fromFile: toolsetNoRootSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)
Expand All @@ -455,6 +481,7 @@ final class DestinationTests: XCTestCase {

let toolsetRootSwiftSDKv4Decoded = try SwiftSDK.decode(
fromFile: toolsetRootSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)
Expand All @@ -463,6 +490,7 @@ final class DestinationTests: XCTestCase {

XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: missingToolsetSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)) {
Expand All @@ -479,12 +507,14 @@ final class DestinationTests: XCTestCase {
}
XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: invalidVersionSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
))

XCTAssertThrowsError(try SwiftSDK.decode(
fromFile: invalidToolsetSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)) {
Expand All @@ -494,6 +524,23 @@ final class DestinationTests: XCTestCase {
.hasPrefix("Couldn't parse toolset configuration at `\(toolsetDefinition)`: ") ?? false
)
}

let wasiWithoutToolsetsDecoded = try SwiftSDK.decode(
fromFile: wasiWithoutToolsetsSwiftSDKv4.path,
hostToolchainBinDir: toolchainBinAbsolutePath,
fileSystem: fs,
observabilityScope: observability
)

XCTAssertEqual(wasiWithoutToolsetsDecoded.count, 1)

let wasmKitProperties = Toolset.ToolProperties(
path: toolchainBinAbsolutePath.appending("wasmkit"),
extraCLIOptions: ["run"]
)
XCTAssertEqual(wasiWithoutToolsetsDecoded[0].toolset.knownTools[.debugger], wasmKitProperties)

XCTAssertEqual(wasiWithoutToolsetsDecoded[0].toolset.knownTools[.testRunner], wasmKitProperties)
}

func testSelectDestination() throws {
Expand Down
1 change: 1 addition & 0 deletions Tests/PackageModelTests/ToolsetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ final class ToolsetTests: XCTestCase {

let store = SwiftSDKBundleStore(
swiftSDKsDirectory: "/",
hostToolchainBinDir: usrBinTools[.swiftCompiler]!.parentDirectory,
fileSystem: fileSystem,
observabilityScope: observability.topScope,
outputHandler: { _ in }
Expand Down