liveBook · Manning

Wasm32-wasi

As explained in Server-Side WebAssembly

wasm32-wasip1 is a 32-bit WebAssembly compilation target using WASI Preview 1 bindings.

wasm32-wasip1 is a 32-bit WebAssembly target associated with WASI Preview 1. It may look like a WASI 0.1 target, but cargo component can compile to it while using an adapter module to provide WASI Preview 2 behavior. section 4.2.1

The target is useful when compiling command-line programs or bridging existing Wasm modules into the component model. Direct wasm32-wasip2 compilation is preferable when the source language supports it, while wasm32-wasip1 remains valuable for legacy code, third-party modules, and gradual migration. section 4.2.1 section 4.3

A practical workflow combines compilation, inspection, adaptation, and execution:

  • Compile a Rust project with cargo build --target wasm32-wasip1 --release, or create and build a component project with cargo component. section 4.2.1 section 4.3
  • Inspect the resulting binary with wasm-tools to distinguish a core module from a component and examine its WIT interfaces. section 4.2.1 section 4.3
  • Adapt a Preview 1 module with wasi_snapshot_preview1.reactor.wasm when Preview 2 component APIs are needed. section 4.3
  • Run a compatible binary with Wasmtime, or package it for the wasi/wasm32 container platform and execute it through containerd. section 4.2.1 section 7.3.2

Hello World across the target boundary

A hello_world_wasi02 project builds to target/wasm32-wasip1/release/hello_world_wasi02.wasm, even though cargo component uses an adapter to expose WASI 0.2 interfaces. Running wasm-tools component wit reveals imports such as wasi:cli/stdout@0.2.0 and an exported wasi:cli/run@0.2.0. A separately compiled Preview 1 guest can be converted with the same adapter strategy. section 4.2.1 section 4.3

cargo component build --release 

Use the supplied cargo-component commands to create and release-build a project targeting the wasm32-wasip1 output path. section 4.2.1

wasm-tools component new <wherever>/
➥p1-hello_world_guest.wasm --adapt 
➥wasi_snapshot_preview1=wasi_snapshot_preview1
➥.reactor.wasm -o p1-hello_world_guest_component.wasm

Use the supplied wasm-tools command to adapt a wasm32-wasip1 module with the WASI Preview 1 reactor adapter and produce a component. section 4.3

How Server-Side WebAssembly covers it

How deep it goes
Explains compilation paths, adapters, WIT inspection, and execution, while noting direct wasm32-wasip2 support remains experimental.
Examples
Uses hello_world_wasi02, a converted Preview 1 guest, wasm-tools WIT output, and a wasi/wasm32 hello container.
What it assumes
Assumes a Rust or compatible Wasm project and introduces the target, adapters, component tooling, and runtime commands through examples.
What you can do after
Build it from scratch, adapt Preview 1 modules into components, inspect WIT interfaces, and run binaries with Wasmtime or containerd.
How it connects
Connects WASI Preview 1 with WASI Preview 2, WebAssembly components, adapter modules, WIT, Wasmtime, containerd, and OCI images.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.