Skip to content
A human library for easily using wasi
Rust Makefile
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

libw docs

This library is meant to be a more human wrapper around only the strict capabilities of wasi

  • only uses #[no_std] and alloc to encourage non-bloated wasm binaries
  • does not require rust be built with wasm32-wasi ( doing so increases file size )
  • high level operations independent of POSIX
  • great way to learn exactly how wasi works!.

hello world

name = "my_app"
version = "0.0.1"

crate-type = ["cdylib"]

lto = true

libw = "0"

pub fn _start() {
	@RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release
	@cp target/wasm32-unknown-unknown/release/wasp.wasm .
wasmer my_app.wasm

working with files

wasi modules are only able to work on folders they have been given explicit permission to access. By default wasi has 3 basic files:

  • 0 - application text input stream
  • 1 - application text output stream
  • 2 - application error text output stream

The file that you give explicit permission to will be given file descriptor number on startup. You must do this manually by specifying the directory.

In libw can get list of accessible directories with accessible_directores(). You must specify a full path that has a prefix of one of the accessible paths.

let path = "/foo/hello.txt";
let mut txt = libw::read_text(path);
libw::write_text(path, txt);
wasmer my_app.wasm --dir=/foo 


data streams

  • read_line - read input characters until you hit enter
  • print - print characters
  • println - print characters ending with newline
  • error - print error


  • current_time - milliseconds since unix epoc
  • unix_time - seconds since unix epoc
  • high_precision_time - get the current realtime value of host clock


  • exit - stop the current process
  • sleep - yield control of thread for n milliseconds


  • accessible_directories - gets a vector of directories your wasi module has access to
  • environment_variables - get a vector of environment variables
  • command_arguments - get a vec of strings of command line arguments


  • read_text - read a text file into a string
  • write_text - write a text file from a string
  • read_bytes - read all bytes from file
  • write_bytes - write all bytes to a file
  • is_readable - can this file be read from
  • is_writeable - can this file be written to
  • is_directory - is the file a directory
  • is_stream - is this file a stream


  • random - get a random f32


This project is licensed under either of

at your option.


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

You can’t perform that action at this time.