Starting with SwiftWasm 5.5 you can use
JSPromise objects. This requires
a few additional steps though (you can skip these steps if your app depends on
- Make sure that your target depends on
- Add an explicit import in the code that executes *before you start using
TaskAPIs (most likely in
- Run this function *before you start using
TaskAPIs (again, most likely in
Then you can
await on the
value property of
JSPromise instances, like in the example below:
If you need to execute Swift async functions that can be resumed by JS event loop in your XCTest suites, please add
Linking this module automatically activates JS event loop based global executor by calling
- macOS 11 and Xcode 13.2 or later versions, which support Swift Concurrency back-deployment.
To use earlier versions of Xcode on macOS 11 you'll have to
- Swift 5.5 or later and Ubuntu 18.04 if you'd like to use Linux. Other Linux distributions are currently not supported.
- Edge 84+
- Firefox 79+
- Chrome 84+
- Desktop Safari 14.1+
- Mobile Safari 14.8+
If you need to support older browser versions, you'll have to build with
when compiling. This should lower browser requirements to these versions:
- Edge 16+
- Firefox 61+
- Chrome 66+
- (Mobile) Safari 12+
Not all of these versions are tested on regular basis though, compatibility reports are very welcome!
Usage in a browser application
As a part of these steps
carton via Homebrew on macOS (you can also use the
Docker image if you prefer to run the build steps on Linux). Assuming you already have Homebrew
brew install swiftwasm/tap/carton
If you had
carton installed before this, make sure you have version 0.6.1 or greater:
- Create a directory for your project and make it current:
mkdir SwiftWasmApp && cd SwiftWasmApp
- Initialize the project from a template with
carton init --template basic
- Build the project and start the development server,
carton devcan be kept running during development:
- Open http://127.0.0.1:8080/ in your browser and a developer console
within it. You'll see
Hello, world!output in the console. You can edit the app source code in your favorite editor and save it,
cartonwill immediately rebuild the app and reload all browser tabs that have the app open.
You can also build your project with webpack.js and a manually installed SwiftWasm toolchain. Please see the following sections and the Example directory for more information in this more advanced use case.
Manual toolchain installation
This library only supports
swiftwasm/swift toolchain distribution.
The toolchain can be installed via
the same way as the official Swift nightly toolchain.
Just pass a toolchain archive URL for the latest SwiftWasm 5.6 release appropriate for your platform:
$ swiftenv install "https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.6.0-RELEASE/swift-wasm-5.6.0-RELEASE-macos_$(uname -m).pkg"
You can also use the
install-toolchain.sh helper script that uses a hardcoded toolchain snapshot:
$ ./scripts/install-toolchain.sh $ swift --version Swift version 5.6 (swiftlang-5.6.0) Target: arm64-apple-darwin20.6.0