no-std wasi

WASI API bindings for Rust

12 releases (breaking)

0.12.0+wasi-0.2.0 Feb 8, 2024
0.11.0+wasi-snapshot-prev… Jan 19, 2022
0.10.3+wasi-snapshot-prev… Jan 18, 2022
0.10.2+wasi-snapshot-prev… Jan 28, 2021
0.0.0 Mar 27, 2019

#1301 in WebAssembly

Download history 1251072/week @ 2023-11-01 1188947/week @ 2023-11-08 1219578/week @ 2023-11-15 966653/week @ 2023-11-22 1147885/week @ 2023-11-29 1166419/week @ 2023-12-06 1126287/week @ 2023-12-13 799878/week @ 2023-12-20 704909/week @ 2023-12-27 1133279/week @ 2024-01-03 1167934/week @ 2024-01-10 1247775/week @ 2024-01-17 1191111/week @ 2024-01-24 1275666/week @ 2024-01-31 1277290/week @ 2024-02-07 1001782/week @ 2024-02-14

4,977,721 downloads per month
Used in 35,673 crates (26 directly)


14K SLoC


A Bytecode Alliance project

WASI API Bindings for Rust

Crates.io version Download docs.rs docs

This crate contains bindings for WASI APIs for the worlds:

This crate is procedurally generated from WIT files using wit-bindgen.


First you can depend on this crate via Cargo.toml:

wasi = "0.12.0"

Next you can use the APIs in the root of the module like so:

fn main() {
    let stdout = wasi::cli::stdout::get_stdout();
    stdout.blocking_write_and_flush(b"Hello, world!\n").unwrap();

This crate is intended to target components but today you need to go through the intermediate build step of a core WebAssembly module using the wasm32-wasi target:

$ cargo build --target wasm32-wasi

Next you'll want an "adapter" to convert the Rust standard library's usage of wasi_snapshot_preview1 to the component model. An example adapter can be found from Wasmtime's release page.

$ curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.0/wasi_snapshot_preview1.command.wasm

Next to create a component you'll use the wasm-tools CLI to create a component:

$ cargo install wasm-tools
$ wasm-tools component new target/wasm32-wasi/debug/foo.wasm \
    --adapt ./wasi_snapshot_preview1.command.wasm \
    -o component.wasm

And finally the component can be run by a runtime that has Component Model support, such as Wasmtime:

$ wasmtime run component.wasm
Hello, world!


The bulk of the wasi crate is generated by the wit-bindgen tool. The src/bindings.rs file can be regenerated with:

$ ./ci/regenerate.sh

WASI definitions are located in the wit directory of this repository. Currently they're copied from upstream repositories but are hoped to be better managed in the future.


This project is licensed under the Apache 2.0 license with the LLVM exception. See LICENSE for more details.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.