DEV Community

Chris Wendt
Chris Wendt

Posted on • Edited on

1

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:

Billboard image

Synthetic monitoring. Built for developers.

Join Vercel, Render, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay