⚡ Zig Guide LiveUnofficialbut fully verified
✓ Zig 0.17.0-dev.1503+1f1bee62eOn an older Zig?

WebAssembly

Zig treats wasm as an ordinary target, which makes it one of the shortest paths to shipping compiled code to a browser. These chapters cover what a freestanding module actually is, exporting functions to JavaScript, moving strings and structs across a boundary that only passes numbers, instantiating the module on a page, and building a WASI command. This site runs on the result.

  1. wasm is an ordinary target. Nothing about the language changes, and the same source builds for your machine and for a browser.
  2. The boundary only passes numbers. A string crosses as a pointer and a length into linear memory, and both sides have to agree who owns it.
  3. Freestanding means no libc, no WASI and no allocator you did not bring yourself.

6 chapters.