WASI is a Bytecode Alliance project WASI(X) adds extensions and is managed by the Wasmer Community
This crate contains API bindings for WASI
system calls in Rust, and currently reflects the wasi_snapshot_preview1
namespace
WASIX adds extensions to WASI
as a superset., and currently reflects the wasix_32v1
namespace
What is WASIX?
WASIX is the long term stabilization and support of the existing WASI ABI plus additional non-invasive syscall extensions that complete the missing gaps sufficiently enough to enable real, practical and useful applications to be compiled now. It aims to speed up the ecosystem around the WASI so that the WASM’ification of code bases around the world can really start today.
Additional extensions
// Its now possible to duplicate file handles
pub use fd_dup;
// Events are used by polling functions that can be interrupted such
// as `tokio` and `mio`
pub use fd_event;
// Pipes are required to stream data to and from subprocesses
pub use fd_pipe;
// Yields CPU time without the bloat of `poll_oneoff`
pub use sched_yield;
// Getting and setting the TTY properties
pub use tty_get;
pub use tty_set;
// Changing the current directory is now natively supported
pub use getcwd;
pub use chdir;
// Signals can be blocked (needed by `libc`)
pub use callback_signal;
// Spawning threads as per the experimental threads spec
pub use thread_spawn;
// Extra thread related functions
pub use thread_sleep;
pub use thread_id;
pub use thread_join;
pub use thread_parallelism;
pub use thread_signal;
pub use thread_exit;
// Operating system futex support used for multithread constructs
pub use futex_wait;
pub use futex_wake;
pub use futex_wake_all;
// Longjmp and setjmp used by `libc`
pub use stack_checkpoint;
pub use stack_restore;
// Subprocess support
pub use proc_raise_interval;
pub use proc_fork;
pub use proc_exec;
pub use proc_spawn;
pub use proc_id;
pub use proc_parent;
pub use proc_join;
pub use proc_signal;
// Interface support
pub use port_bridge;
pub use port_unbridge;
pub use port_dhcp_acquire;
pub use port_addr_add;
pub use port_addr_remove;
pub use port_addr_clear;
pub use port_mac;
pub use port_addr_list;
pub use port_gateway_set;
pub use port_route_add;
pub use port_route_remove;
pub use port_route_clear;
pub use port_route_list;
// All the missing socket functionality
pub use sock_status;
pub use sock_addr_local;
pub use sock_addr_peer;
pub use sock_set_opt_flag;
pub use sock_get_opt_flag;
pub use sock_set_opt_time;
pub use sock_get_opt_time;
pub use sock_set_opt_size;
pub use sock_get_opt_size;
pub use sock_join_multicast_v4;
pub use sock_leave_multicast_v4;
pub use sock_join_multicast_v6;
pub use sock_leave_multicast_v6;
pub use sock_bind;
pub use sock_listen;
pub use sock_connect;
pub use sock_open;
pub use sock_recv_from;
pub use sock_send_to;
pub use sock_send_file;
// Ability to perform DNS queries
pub use resolve;
Usage
First you can depend on this crate via Cargo.toml
:
[]
= "0.11"
Next you can use the APIs in the root of the module like so:
Next you can use a tool like cargo wasix
to compile and run your
project:
To compile Rust projects to wasm using WASI, use the wasm32-wasix
target,
like this:
$ wasmer run my-all
Compiling wasix v0.11.0
Compiling wasi v0.11.0+wasix-snapshot-preview1
Compiling wut v0.1.0 (/code)
Finished dev [unoptimized + debuginfo] target(s) in 0.34s
Running `/.cargo/bin/cargo-wasix target/wasm64-wasix/debug/wut.wasm`
Running `target/wasm64-wasix/debug/wut.wasm`
Hello, World!
Development
The bulk of the wasix
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/wasix_v1.witx > src/lib_generated.rs
Note that this uses the WASIX standard repository as a submodule. If you do not have this submodule present in your source tree, run:
git submodule update --init
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.