Since official support for Wasm in Swift 6.2 was announced at WWDC this year, Swift contributors have done a huge amount of work. To provide better visibility and to track progress, here’s a list of notable changes:
Breaking change: wasm32-unknown-wasi triple wasm renamed to wasm32-unknown-wasip1. The p1 suffix explicitly indicates WASI Preview 1, which helps distinguish it from the newer WASI Preview 2 (wasip2) and provides clarity about which version of the WASI specification is being targeted.
Users will need to update build invocations that relied on --triple option. However, the underlying functionality remains identical; only the triple identifier changed. Users that relied on Swift SDK IDs passed to --swift-sdk are not impacted.
Embedded Swift concurrency is now enabled for CLI executables (compatible with swift run) built with main development snapshots of the Swift toolchain. Some async stdlib functions, such as Task.sleep are not available yet.
Surely I missed a few changes in this list unintentionally, so please feel free to post what you found notable in this thread. Many thanks to all of the contributors pushing the ecosystem forward!
I see. So that feature wasn’t necessarily required to be used with Carton. I apologize. I feel like I have been updating and changing how I build my project that I have lost track of where all the parts come into play. I have stayed with 5.10 so I can keep using carton. But I gotta move to 6.1+, so now I’m trying to move to whatever the newest way to do things is. I just finished building a new Ubuntu VM to test. The project compiled fine using the instructions form the page your provided.
Is there a mechanism to run 'wasm-opt’ after it is built?
I see. So the tool is installed. But the binary is at 120mb (should be like 20mb after wasm-opt). Is the stripped file being moved somewhere else? I guess, what I mean is there a folder like “Bundle” that is being created somewhere?
Hmm, if you build with release configuration, debug symbols should be stripped unless you explicitly pass --debug-info-format option. Can you share your build command?
The "Bundle" directory is generated under .build/plugins/PackageToJS/outputs/Package by default. If you pass --output option with --allow-writing-to-package-directory plugin option, you can keep the existing directory layout:
The major binary size difference in the recent versions is ICU data. Recent Foundation brought full-featured ICU data into our binary, so you might be able to reduce the size into what we had before by replacing the data with slimmed version: GitHub - GoodNotes/swift-icudata-slim: A slimmed-down version of ICU for Swift
I did not realize at all that the increase in ICU data would cause an approaching 30MB (I fathom that some of the size increase is from other stuff too?) . I suppose it is not awful. The site will just take about twice as long to load, which given the niche-ness of it that is ok.
Lastly is there an argument to get the index.html file to copy into the ./Bundle folder? Other than that (which I can definitely do myself), this looks like it is going to be mostly a good replacement.
So I am a little confused, when I do --wasm-optimizations none with Carton on 5.10, the resulting binary is only about 32MB (with optimization it is about 20MB), but when I run it using the new method under 6.1 the resulting binary is larger than when there is no optimization at all on the old version.
I am wondering if something else is happening here that I am either skipping or missing. Like maybe certain unused functions are not being stripped?
I was hoping that Embedded Swift (in the browser) would be able to (directly) import JS functions (as if they're written in C), export Swift functions (that can then be invoked by JavaScript) and use pointers for memory mapped IO. At least, something like that.
In short, I’d like to use Swift instead of WAT (which doesn’t require WASI). I don't know exactly how the API would work; I just assumed it'd be an option. Embedded Swift doesn't require an OS, so shouldn't really need WASI, IIUC.
For any non-trivial code you'll have to use a libc (heap allocation, RNG etc). Pretty much everything in a libc, except heap allocation and maybe some formatting functions, has to be backed by host imports. You can spend time rolling your own libc and imports ABI, or can use readily available WASI 0.1 imports. We've chosen the latter as the default and officially supported approach.
Additionally, you don't pay for what you don't use with Embedded Swift. With full optimizations unused WASI imports are removed from the final binary, so If you need only a heap allocator and nothing else, you'll technically get a WASI-less binary even with a WASI triple.