DEV Community

Chris Wendt
Chris Wendt

Posted on • Edited 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:

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay