wasip1

Crates.iowasip1
lib.rswasip1
version1.0.0
created_at2025-09-09 20:06:34.771221+00
updated_at2025-09-09 20:06:34.771221+00
descriptionWASIp1 API bindings for Rust
homepage
repositoryhttps://github.com/bytecodealliance/wasi
max_upload_size
id1831463
size134,004
Alex Crichton (alexcrichton)

documentation

https://docs.rs/wasi

README

wasip1

A Bytecode Alliance project

WASIp1 API Bindings for Rust

Crates.io version Download docs.rs docs

Note: Development of WASIp1 has ceased at the standards body level and development of this crate has all but ceased as well. This is present for ongoing maintenance but is not expected to receive any further major updates. See the wasip2 crate for a more up-to-date experience.

This crate contains API bindings for WASIp1 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 wasip1 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!

Usage

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

[dependencies]
wasip1 = "1.0.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 = [wasip1::Ciovec {
        buf: message.as_ptr(),
        buf_len: message.len(),
    }];
    wasip1::fd_write(stdout, &data).unwrap();
}

Development

The bulk of the wasip1 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/wasip1/wasi_snapshot_preview1.witx > crates/wasip1/src/lib_generated.rs

The *.witx files are vendored with ./ci/vendor-wit.sh and are located at crates/wasip1/*.witx.

Commit count: 117

cargo fmt