What languages are supported in WebAssembly running outside the browser? This is a question I often hear people ask. It’s has a complicated answer because:
- WebAssembly outside the browser needs WASI and not all languages have WASI support in their toolchain.
- Even if WASI is supported well in a language, WASI has its own limitations that you need to take into account.
In short, you can’t take any code written in any language and expect to compile and run it as a Wasm+Wasi module right now. Documentation on what’s supported is patchy or misleading at times. Unfortunately, you often need to try things out before knowing what works and what doesn’t.
Let’s take a look in more detail.
Resources on language support
I found 2 resources to understand the language support in Wasm+Wasi.
First one is WebAssembly Support in Top 20 Languagess from Fermyon:
Second one is the WebAssembly Introduction page from Enarx:
Both are good resources to understand the level of support in each language but they should be taken with a grain of salt.
“Excellent” support languages
Rust, C, C++, Go are supposed to have excellent Wasm+Wasi support but what does excellent mean in this case?
Almost all of the Wasm+Wasi tutorials show Rust because it’s trivial to take a Rust application and compile it to Wasm+Wasi (I show it in this sample) with the regular Rust tooling. However, you have to keep in mind the WASI limitations. In WASI, there’s no threading or socket support which translates to no Tokio or async support in Rust.
Similarly, in C/C++, you can’t have C++ exceptions or threads. Go is supported by TinyGo (and more recently with Go 1.21 RC) but no reflection features of Go are supported in WASI.
As you see, some of the basic features you take for granted in languages are not yet supported due to WASI limitations. Excellent support in this case is a little misleading. It basically means you can compile a WASI limited code using the standard tools of the language but not full language support.
Experimental support languages
In experimental support languages, the situation is even more complicated.
In .NET, there was a Wasi SDK for .NET 7 to compile .NET apps to WASI but it
got replaced by
wasi-experimental workload in .NET 8 preview (see a demo
video here). It feels like the .NET team wants to
support Wasm+Wasi but the tools are changing from release to release.
As you can see, the language support in Wasm+Wasi is still in its infancy and changing all the time. Right now, it’s not so easy to understand what parts of a language works in a Wasm+Wasi setup without actually trying it out but hopefully, this will get better as WASI and languages mature. In the meantime, I update my wasm-basics repo, as I work on samples in different languages.