Website | Source | Docs ("the SwiftWasm book")
We use LLVM as a compiler backend to produce WebAssembly binaries. Our resulting binaries also depend on WASI, which is a modular system interface for WebAssembly. WASI is mainly required to compile Swift Standard Library.
Important note: In 2024, Apple introduced Swift Embedded. While both projects benefit from each other, it is important to understand that they are different targets at the build phase, consequentially with different sets of abilities. Embedded Swift very limited but can produce small binaries. Example.
Project Status: All compiler and standard library changes have been upstreamed to the official Swift repository, and the upstream CI is now testing WebAssembly targets.
The remaining works are: Integrating the build system with the official Swift CI.
Before installing the Swift SDK, you need to ensure the following:
Please ensure you have installed the Swift 6.1 Open Source toolchain.
Toolchain | Output |
---|---|
❌ Xcode | Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3) |
✅ Open Source (macOS) | Apple Swift version 6.1 (swift-6.1-RELEASE) |
✅ Open Source (Others) | Swift version 6.1 (swift-6.1-RELEASE) |
Once you have installed the Open Source toolchain, you can install the Swift SDK for WebAssembly:
swift sdk install "https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.1-RELEASE/swift-wasm-6.1-RELEASE-wasm32-unknown-wasi.artifactbundle.zip" --checksum "7550b4c77a55f4b637c376f5d192f297fe185607003a6212ad608276928db992"
After installing the Swift SDK, you can see 6.1-RELEASE-wasm32-unknown-wasi in the Swift SDK list:
swift sdk list
You can also find other SDKs from the GitHub Releases page.
First, create a new directory for your project and navigate into it:
$ mkdir hello && cd hello
Create a new Swift package:
$ swift package init --type executable
You can use the installed SDKs to cross-compile Swift packages for WebAssembly:
$ swift build --swift-sdk wasm32-unknown-wasi
...
$ file .build/wasm32-unknown-wasi/debug/hello.wasm
.build/wasm32-unknown-wasi/debug/hello.wasm: WebAssembly (wasm) binary module version 0x1 (MVP)
You can run the built WebAssembly module using wasmtime:
$ wasmtime .build/wasm32-unknown-wasi/debug/hello.wasm
Hello, world!
How to check if I am using Open Source toolchain or Xcode toolchain?
$ swift --version | head -n1
Toolchain | Output |
---|---|
Xcode | Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3) |
Open Source (macOS) | Apple Swift version 6.1 (swift-6.1-RELEASE) |
Open Source (Others) | Swift version 6.1 (swift-6.1-RELEASE) |
This error occurs when the Swift toolchain version you are using is different from the version of the Swift SDK you have installed.
To resolve this issue, you can either:
Switch the Swift toolchain to the same version as the Swift SDK you have installed. Check the official guide for how to switch the toolchain.
Install the Swift SDK for the same version as the Swift toolchain you are using. Use the following shell snippet to query compatible Swift SDK for your current toolchain version:
(
V="$(swiftc --version | head -n1)"; \
TAG="$(curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/tag-by-version.json" | jq -r --arg v "$V" '.[$v] | .[-1]')"; \
curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/builds/$TAG.json" | \
jq -r '.["swift-sdks"]["wasm32-unknown-wasi"] | "swift sdk install \"\(.url)\" --checksum \"\(.checksum)\""'
)
What is the difference between the Swift Toolchain and the Swift SDK?
The Swift toolchain is a complete package that includes the Swift compiler, standard library, and other tools.
The Swift SDK includes a subset of the Swift toolchain that includes only the necessary components for cross-compilation and some supplementary resources.
What is included in the Swift SDK for WebAssembly?
The Swift SDK for WebAssembly includes only the pre-built Swift standard libraries for WebAssembly. It does not include the Swift compiler or other tools that are part of the Swift toolchain.
6.2 release:
swift sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.2-RELEASE/swift-wasm-6.2-RELEASE-wasm32-unknown-wasip1-threads.artifactbundle.zip --checksum df8dee548a572f9325e997e1378f4dbab1dbfc986f92a35887b313e19007835d
swift sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.2-RELEASE/swift-wasm-6.2-RELEASE-wasm32-unknown-wasip1.artifactbundle.zip --checksum f206a9ff2352f726d88a59d2241b9581264326471265229b7ffd133d2593b92b
Awesome-SwiftWasm: A community-driven curated list of SwiftWasm projects and content
Last modified 11 October 2025