Name Date Size #Lines LOC

..15-May-2026-

byte-array-literals/H15-May-2026-128106

provider/H15-May-2026-16188

src/H15-May-2026-3,5532,736

verify/H15-May-2026-9679

Cargo.tomlH A D15-May-2026669 3327

README.mdH A D15-May-20262.4 KiB6449

build.rsH A D15-May-202610.7 KiB319189

README.md

1# `wasi_snapshot_preview1.wasm`
2
3> **Note**: This repository is a work in progress. This is intended to be an
4> internal tool which not everyone has to look at but many might rely on. You
5> may need to reach out via issues or
6> [Zulip](https://bytecodealliance.zulipchat.com/) to learn more about this
7> repository.
8
9This repository currently contains an implementation of a WebAssembly module:
10`wasi_snapshot_preview1.wasm`. This module bridges the `wasi_snapshot_preview1`
11ABI to the preview2 ABI of the component model. At this time the preview2 APIs
12themselves are not done being specified so a local copy of `wit/*.wit` is used
13instead.
14
15## Building
16
17This adapter can be built with:
18
19```console
20cargo build -p wasi-preview1-component-adapter --target wasm32-unknown-unknown --release
21```
22
23And the artifact will be located at
24`target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm`.
25
26This by default builds a "reactor" adapter which means that it only provides
27adaptation from preview1 to preview2. Alternatively you can also build a
28"command" adapter by passing `--features command --no-default-features` which
29will additionally export a `run` function entrypoint. This is suitable for use
30with preview1 binaries that export a `_start` function.
31
32Alternatively the latest copy of the command and reactor adapters can be
33[downloaded from the `dev` tag assets][dev-tag]
34
35[dev-tag]: https://github.com/bytecodealliance/wasmtime/releases/tag/dev
36
37## Using
38
39With a `wasi_snapshot_preview1.wasm` file on-hand you can create a component
40from a module that imports WASI functions using the [`wasm-tools`
41CLI](https://github.com/bytecodealliance/wasm-tools)
42
43```shell-session
44$ cat foo.rs
45fn main() {
46    println!("Hello, world!");
47}
48$ rustc foo.rs --target wasm32-wasip1
49$ wasm-tools print foo.wasm | grep '(import'
50  (import "wasi_snapshot_preview1" "fd_write" (func ...
51  (import "wasi_snapshot_preview1" "environ_get" (func ...
52  (import "wasi_snapshot_preview1" "environ_sizes_get" ...
53  (import "wasi_snapshot_preview1" "proc_exit" (func ...
54$ wasm-tools component new foo.wasm --adapt wasi_snapshot_preview1.wasm -o component.wasm
55
56# Inspect the generated `component.wasm`
57$ wasm-tools validate component.wasm --features component-model
58$ wasm-tools component wit component.wasm
59```
60
61Here the `component.wasm` that's generated is a ready-to-run component which
62imports wasi preview2 functions and is compatible with the wasi-preview1-using
63module internally.
64