Swift SDKs for WebAssembly now available on swift.org

As the Platform Steering Group accepted the vision document for WebAssembly support, we’re excited to announce that Swift SDKs for Wasm are now available at swift.org/install. The website now also hosts a getting started guide for Wasm with installation and build instructions.

You may notice "Swift SDKs" is in plural. The reason is that artifact bundles for Wasm distributed from swift.org include two Swift SDKs: one with the full feature set of the Swift standard library and Swift Testing, and the other with a subset of features available in Embedded Swift. The latter is a big improvement over previous Embedded Swift for Wasm build workflows, which frequently required a manually crafted set of options passed to the compiler and the linker. With new Embedded Swift SDK for Wasm, pass --swift-sdk option as for any other cross-compilation build to get a tiny binary. For example, a fully optimized print("Hello, World!") built with Embedded Swift SDK for Wasm is only 9.7 kB.

Another major addition is the inclusion of WasmKit in toolchains distributed from swift.org. This means you can use swift run with Swift SDKs to run WASI-compatible binaries on the command line. There's ongoing work to fully enable swift test in the same manner.

While Swift Testing (not compatible with Embedded Swift yet) is already available in the Swift SDK, Foundation and XCTest will be included for greater compatibility with existing code in future development snapshots.

As WebAssembly started as a community project, we'd like to thank everyone who helped us to get to this milestone over the years. Special thanks (in alphabetical order) to @al45tair, @bnbarham, @carsonkatri, @danielle, @daveverwer, @finestructure, @fjtrujy, @Geordie_J, @j-f1, @kabiroberai, @kateinoigakukun, @mishal_shah, @shial4, @STREGA, @yonihemi, and Zhuowei Zhang.

Can't wait to see what you build with Swift for Wasm!

69 Likes

What a journey it's been! Really proud to see this finally reach official support. Thanks to everyone who contributed along the way.
This is just the beginning though, there's still plenty of exciting improvements and optimizations ahead. Looking forward to continuing to push Swift/Wasm forward!

26 Likes

Thanks to every one of you who pushed for this in various ways. I definitely don’t feel my acknowledgment here is warranted, I’m just a grateful user of the amazing work you‘ve all been putting in :folded_hands:t2:

2 Likes

Great to see this become official, congrats to Max, Yuta, and all the contributors to this platform. :smile:

I just read the instructions and what would really make it sing is after you show the output from running it, if you added some instructions on how to take the same wasm executable and run it on a completely different OS with the Swift toolchain installed, demonstrating the great portability of Wasm. :laughing:

Also, rather than having to carefully check the SDK snapshot dates by hand, we really need to put some guardrails into SwiftPM, where it will simply error and tell you that the SDK snapshot version does not match the toolchain version or can pick the right snapshot date if multiple SDK snapshots are installed.

5 Likes

Will carton get compatibility with this build system?

I no longer maintain carton, so I can't answer that. I would recommend having a look at the new swift package js command plugin provided by JavaScriptKit. Tutorials and articles in its DocC catalogue provide a nice introduction to it. If there's anything missing in this plugin you'd like to see added in the future, all feedback and feature requests on the JavaScriptKit repository are appreciated!

3 Likes

this is incredible!

2 Likes

Thanks to everyone for this amazing (and hard) work!

I would like to bring Swift into the Spin framework, which is an open source developer tool for building and running serverless applications powered by WebAssembly.

If anybody is working on it, or wants to help, please contact me and lets bring Swift into the Spin framework :slight_smile:

Again, thanks and congratulations to everyone!

2 Likes