#webassembly #wasm

no-std wasi

Experimental WASI API bindings for Rust

7 releases (breaking)

✓ Uses Rust 2018 edition

new 0.9.0+wasi-snapshot-preview1 Dec 2, 2019
0.7.0 Aug 29, 2019
0.6.0 Aug 29, 2019
0.5.0 Jul 23, 2019
0.0.0 Mar 27, 2019

#18 in WebAssembly

Download history 20542/week @ 2019-08-19 21364/week @ 2019-08-26 26429/week @ 2019-09-02 34230/week @ 2019-09-09 35225/week @ 2019-09-16 34527/week @ 2019-09-23 36603/week @ 2019-09-30 36623/week @ 2019-10-07 37079/week @ 2019-10-14 38010/week @ 2019-10-21 40883/week @ 2019-10-28 44355/week @ 2019-11-04 44677/week @ 2019-11-11 46685/week @ 2019-11-18 47290/week @ 2019-11-25

166,987 downloads per month
Used in 688 crates (2 directly)

Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT

75KB
1K SLoC

wasi

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!

Usage

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

[dependencies]
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!

License

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

Contribution

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.

Dependencies

~140KB