WebAssembly Swift SDK selection in Swift 6.2

i get this now, i think because the triple wasm32-unknown-wasip1 is matching both the normal wasm SDK, and the embedded one, and it is selecting the embedded one for some reason

warning: multiple Swift SDKs match target triple `wasm32-unknown-wasip1` and host triple x86_64-unknown-linux-gnu, selected one at /home/ubuntu/.swiftpm/swift-sdks/swift-wasm-6.2-RELEASE-wasm32-unknown-wasip1.artifactbundle/6.2-RELEASE-wasm32-unknown-wasip1/wasm32-unknown-wasip1/embedded-swift-sdk.json
Building for debugging...
[0/51] Write swift-version-19424B39D8A021E3.txt
error: emit-module command failed with exit code 1 (use -v to see invocation)
[2/71] Emitting module JavaScriptEventLoop
.build.wasm/checkouts/JavaScriptKit/Sources/JavaScriptEventLoop/JavaScriptEventLoop+ExecutorFactory.swift:15:32: error: cannot find type 'MainExecutor' in scope
13 | // MainExecutor is used by the main actor to execute tasks on the main thread
14 | @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999, *)
15 | extension JavaScriptEventLoop: MainExecutor {
   |                                `- error: cannot find type 'MainExecutor' in scope
16 |     public func run() throws {
17 |         // This method is called from `swift_task_asyncMainDrainQueueImpl`.

the swift-collections package also seems to be broken, but i suspect this is related to the previous issue.

/.build.wasm/checkouts/swift-collections/Sources/InternalCollectionsUtilities/autogenerated/Descriptions.swift:129:5: error: cannot find 'debugPrint' in scope
127 |       result += ", "
128 |     }
129 |     debugPrint(key, terminator: "", to: &result)
    |     `- error: cannot find 'debugPrint' in scope
130 |     result += ": "
131 |     debugPrint(value, terminator: "", to: &result)

for anyone coming across this, it seems the latest JavaScriptKit release (0.36) is incompatible with the Swift 6.2 SDK. using the main branch of that repo makes it compile though, probably from this commit on.

switching to main branch JavaScriptKit also seems to resolve the swift-collections build failure, although i am baffled as to why, seeing as they are completely unrelated packages.

I recommend selecting Swift SDKs by their IDs per swift sdk list output and not triple, as both Swift SDKs (embedded and non-embedded) use the same triple. This command would work for any toolchain version, assuming you have jq installed:

 swift build --swift-sdk \
  "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm"

For Embedded Swift use the corresponding suffix:

 swift build --swift-sdk \
  "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm-embedded"
4 Likes