wat2wasm: Assemble WAT Text to a Wasm Binary
wat2wasm translates the WebAssembly text format (.wat) into a binary .wasm module.
Part of WABT (the WebAssembly Binary Toolkit), wat2wasm is how you hand-write or generate wasm as readable text and assemble it. In CI it builds fixtures and reproduces bug reports.
What it does
wat2wasm parses the S-expression text format and emits a binary module, validating it by default. Proposal features (like SIMD or bulk memory) must be enabled explicitly with --enable-<feature>.
Common usage
wat2wasm module.wat -o module.wasm
wat2wasm module.wat --enable-simd -o module.wasm
wat2wasm module.wat --debug-names -o module.wasm
wat2wasm --no-check module.wat -o module.wasmOptions
| Flag | What it does |
|---|---|
| -o <file> | Output .wasm path (default stdout is not used; -o required to write a file) |
| --enable-<feature> | Enable a proposal (e.g. --enable-simd, --enable-threads) |
| --enable-all | Enable all supported proposals |
| --debug-names | Preserve the name section for readable disassembly |
| --no-check | Skip validation after assembling |
In CI
Enable the exact proposal your source uses; otherwise a feature-gated instruction is rejected even though the syntax is fine. Pin the WABT version so error line/column reporting stays stable across runs.
Common errors in CI
Errors take the form "module.wat:LINE:COL: error: <message>", e.g. "unexpected token", "undefined function variable", or "type mismatch in ...". "error: ... requires simd" (or threads, etc.) means you must add the matching --enable- flag. A missing -o writes nothing rather than erroring, so a later step "cannot find module.wasm".