wasmer compile: Precompile Wasm for Wasmer
wasmer compile ahead-of-time compiles a WebAssembly module into a serialized native artifact for fast reuse.
Like Wasmtime AOT, Wasmer can precompile a module and pick the codegen backend. In CI this trades build time for near-instant startup at run time.
What it does
wasmer compile reads a .wasm, compiles it with the chosen backend (Cranelift by default, LLVM or Singlepass optionally), and writes a .wasmu that wasmer run loads directly.
Common usage
wasmer compile app.wasm -o app.wasmu
wasmer compile --llvm app.wasm -o app.wasmu
wasmer compile --target aarch64-linux-gnu app.wasm -o app.wasmuOptions
| Flag | What it does |
|---|---|
| -o <file> | Output path for the .wasmu artifact |
| --cranelift | Use the Cranelift backend (default, balanced) |
| --llvm | Use the LLVM backend (slowest compile, fastest runtime) |
| --singlepass | Use the Singlepass backend (fastest compile) |
| --target <triple> | Cross-compile for another target triple |
In CI
The LLVM backend needs LLVM installed on the runner and is worth it only for compute-heavy modules run many times. A .wasmu is version and target specific; cache it keyed on the Wasmer version and rebuild on upgrade.
Common errors in CI
"Error: The provided target ... is not supported" means the backend does not support that triple; switch backend or target. LLVM backend errors like "llvm not found" mean LLVM is missing on the runner. A .wasmu built by a different Wasmer version fails to load with an incompatibility error.