DEV Community

Chris Wendt
Chris Wendt

Posted on • Updated on

The state of Wasm in Rust, Haskell, and Go

2023

Haskell

  • Use ghc.nix to build a GHC version that targets Wasm
  • It supports WASI
  • It works on Mac M1

Go

  • Go 1.21 added experimental support for WASI (GOOS=wasip1, GOARCH=wasm)
  • tinygo: JSON packages now work (tested on 0.29.0)

2022

Compiling to Webassembly (Wasm) is still rather difficult IMO in 2022. Here I document some of my findings:

Haskell

  • Compiling to Wasm requires an early release of GHC, slated for GHC 9.6
  • It supports WASI
  • It does not work on ARM, such as Mac M1

Rust

  • The wasm32-unknown-unknown target works, but requires low-level memory management and unsafe blocks
  • A bunch of packages like tokio don't work because they transitively depend on net, and WASI doesn't have networking yet (networking is in phase 1 of 5), and it doesn't seem possible to turn off the net feature of transitive dependencies

Go

  • The main Go compiler doesn't yet support WASI, it only supports targeting JavaScript environments (see how the only GOOS/GOARCH pair is js/wasm)
  • TinyGo supports WASI tinygo build -target wasi ., but a ton of packages like encoding/json don't work because not all of the reflect stdlib package has been implemented in the TinyGo runtime. I tried these alternative JSON packages:

Top comments (0)