Welcome to the SwiftWasm Documentation!
SwiftWasm is an open source project to support the WebAssembly target for Swift.
The goal of this project is to fully support the WebAssembly target for Swift and to be merged into the upstream repository.
You can install latest toolchain of SwiftWasm from Release Page
The toolchains can be installed via
swiftenv like official nightly toolchain.
Here's an example
swiftenv invocation for installing the latest stable SwiftWasm toolchain on macOS Catalina:
$ swiftenv install \ https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.3-SNAPSHOT-2020-08-15-a/swift-wasm-5.3-SNAPSHOT-2020-08-15-a-osx.tar.gz $ swift --version Swift version 5.3-dev (LLVM ba56ef042e, Swift 5855a96018) Target: x86_64-apple-darwin19.3.0
$ echo 'print("Hello, world!")' > hello.swift # Compile Swift code into WebAssembly with WASI $ TOOLCHAIN_PATH=$(dirname $(swiftenv which swiftc))/../ $ swiftc \ -target wasm32-unknown-wasi \ -sdk $TOOLCHAIN_PATH/share/wasi-sysroot \ hello.swift -o hello.wasm
You can the run the produced binary with wasmer (or other WebAssembly runtime):
$ wasmer hello.wasm
The produced binary depends on WASI which is an interface of system call for WebAssembly. So you need to use WASI supported runtime and when you run the binary on browser, you need WASI polyfill library like @wasmer/wasi.
You can also use SwiftPM for managing packages in the same way as other platforms.
$ swiftenv local wasm-DEVELOPMENT-SNAPSHOT-2020-06-07-a $ swift package init --type executable $ swift build --triple wasm32-unknown-wasi $ wasmer ./.build/debug/hello-swiftwasm Hello, world!
swiftwasmis the main develop branch
masteris a mirror of the
masterbranch of the upstream
apple/masterrepository. This branch is necessary to avoid some issues
swiftwasm-release/5.3is the branch where 5.3 release of SwiftWasm is prepared.
release/5.3is a mirror of the upstream
Forked from apple/llvm-project.
swiftwasm branch is based on
swift/master branch of
Please see AppleBranchingScheme.md
Build script and patches for building ICU project for WebAssembly
We are sending patches to upstream repository.
We fork them to build
wasi-sysroot with pthread header. There aren't so many diff from upstream.
First, checkout the project source code.
$ mkdir swiftwasm-source $ cd swiftwasm-source $ git clone https://github.com/swiftwasm/swift.git $ ./swift/utils/update-checkout --scheme wasm --clone
Before building Swift, please install required dependencies.
# On macOS $ ./utils/webassembly/macos/install-dependencies.sh # On Linux $ ./utils/webassembly/linux/install-dependencies.sh
We support both Linux and macOS to build Swift.
These script wraps
./utils/build-script to simplify build options.
You can pass additional build-script options through these scripts.
# On macOS $ ./utils/webassembly/build-mac.sh -R # On Linux $ ./utils/webassembly/build-linux.sh -R
If you want to get more information about build system, please feel free to ask @kateinoigakukun on Twitter.
Compilation time of LLVM project is very long, so we recommend to cache the artifact using
When you want to debug a WebAssembly binary, wasminspect is very helpful to investigate.
We use GitHub Actions to build and run tests continuously. (But jobs without cache takes 3~4 hours to be completed)
Currently (2020/03/12), running test on Linux is disabled because the job exection time and storage reached the limit of GitHub Actions.