#webassembly #wasm

no-std wasi

Experimental WASI API bindings for Rust

11 releases (breaking)

0.11.0+wasi-snapshot-preview1 Jan 19, 2022
0.10.2+wasi-snapshot-preview1 Jan 28, 2021
0.10.0+wasi-snapshot-preview1 Jun 3, 2020
0.9.0+wasi-snapshot-preview1 Dec 2, 2019
0.0.0 Mar 27, 2019

#84 in WebAssembly

Download history 692269/week @ 2022-12-05 677354/week @ 2022-12-12 632603/week @ 2022-12-19 436713/week @ 2022-12-26 608852/week @ 2023-01-02 713570/week @ 2023-01-09 704535/week @ 2023-01-16 702320/week @ 2023-01-23 745987/week @ 2023-01-30 762518/week @ 2023-02-06 778482/week @ 2023-02-13 768104/week @ 2023-02-20 809090/week @ 2023-02-27 856191/week @ 2023-03-06 802374/week @ 2023-03-13 838312/week @ 2023-03-20

3,368,491 downloads per month
Used in 26,635 crates (23 directly)


1.5K SLoC


A Bytecode Alliance project

WASI API Bindings for Rust

Crates.io version Download docs.rs docs

This crate contains API bindings for WASI system calls in Rust, and currently reflects the wasi_snapshot_preview1 module. This crate is quite low-level and provides conceptually a "system call" interface. In most settings, it's better to use the Rust standard library, which has WASI support.

The wasi crate is also entirely procedurally generated from the *.witx files describing the WASI apis. While some conveniences are provided the bindings here are intentionally low-level!


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

wasi = "0.8.0"

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

fn main() {
    let stdout = 1;
    let message = "Hello, World!\n";
    let data = [wasi::Ciovec {
        buf: message.as_ptr(),
        buf_len: message.len(),
    wasi::fd_write(stdout, &data).unwrap();

Next you can use a tool like cargo wasi to compile and run your project:

To compile Rust projects to wasm using WASI, use the wasm32-wasi target, like this:

$ cargo wasi run
   Compiling wasi v0.8.0+wasi-snapshot-preview1
   Compiling wut v0.1.0 (/code)
    Finished dev [unoptimized + debuginfo] target(s) in 0.34s
     Running `/.cargo/bin/cargo-wasi target/wasm32-wasi/debug/wut.wasm`
     Running `target/wasm32-wasi/debug/wut.wasm`
Hello, World!


The bulk of the wasi crate is generated by the witx-bindgen tool, which lives at crates/witx-bindgen and is part of the cargo workspace.

The src/lib_generated.rs file can be re-generated with the following command:

cargo run -p witx-bindgen -- crates/witx-bindgen/WASI/phases/snapshot/witx/wasi_snapshot_preview1.witx > src/lib_generated.rs

Note that this uses the WASI standard repository as a submodule. If you do not have this submodule present in your source tree, run:

git submodule update --init


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.