WASM Support


(George) #1

I'm not sure if this is the correct section for this, but WebAssembly support was brought up in this thread. Is there any ongoing work on this front? Is there some place we can track that work? If we wanted to pitch in, is there a good place to start?


(Lukas Stabe 🙃) #2

There has been some discussion and a little work (but no working compilation to wasm) in this GitHub issue a few months ago: https://github.com/kripken/emscripten/issues/2427.


(George) #3

I have seen that issue. Do folks think using emscripten is the right path forward? I may be misremembering but I think the Rust folks started with emscripten and then rolled their own wasm target.


(Lukas Stabe 🙃) #4

I'm neither a compiler- nor wasm-expert, but at least some of the changes posted in the last few comments on the issue look like they'd be relevant either way. From the little research on wasm vs. emscripten I did just now, it looks to me like the first step would be to allow the LLVM wasm backend to work with Swift, which I think is the backend both Clang and Rust (which indeed switched from the backend coming with emscripten) use.

Even when using that, It looks to me like emscripten can still be used to generate glue code and provide shims for libc, opengl and such things (I think that's what it is at least). Rust is using their own system, wasm-bindgen for at least a part of what emscripten provides, but I'm not sure whether they are still using emscripten for other functionality.

The wasm project also has at least some of the features emscripten provides on their roadmap


(Max Desiatov) #5

While the original issue has been created in the emscripten repository, it contains the discussion of using LLVM WebAssembly backend and a few patches for the Swift toolchain for enabling that. I haven't seen any more work done on that in the Swift toolchain for the last half a year, but LLVM 7.0 had some good progress on WebAssembly target since then. I've pulled LLVM 7.0 updates and rebased the patches, which now live in these branches:

Swift compiler support
compiler-rt with LLVM 7.0 updates
Swift's fork of LLVM with 7.0 updates
Swift's clang fork with 7.0 updates

It looks like the main blocker is going to be the dependency on glibc. My understanding is being able to switch from glibc to musl in Swift toolchain would be super helpful, especially as there was some progress in porting musl to WebAssembly: https://github.com/jfbastien/musl


(Daniel Dunbar) #6

FWIW, I have been a tiny bit of poking at this, primarily in the context of purely native (non-emscripten) support. Tracking status here: https://bugs.swift.org/browse/SR-9307