WASI(X)
WASI API Bindings for Rust
WASI(X) API Bindings for Rust
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
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.
```rust // Its now possible to duplicate file handles pub use x::fd_dup;
// Events are used by polling functions that can be interrupted such
// as tokio
and mio
pub use x::fd_event;
// Pipes are required to stream data to and from subprocesses pub use x::fd_pipe;
// Yields CPU time without the bloat of poll_oneoff
pub use x::sched_yield;
// Getting and setting the TTY properties pub use x::ttyget; pub use x::ttyset;
// Changing the current directory is now natively supported pub use x::getcwd; pub use x::chdir;
// Signals can be blocked (needed by libc
)
pub use x::callback_signal;
// Spawning threads as per the experimental threads spec pub use x::thread_spawn;
// Extra thread related functions pub use x::threadsleep; pub use x::threadid; pub use x::threadjoin; pub use x::threadparallelism; pub use x::threadsignal; pub use x::threadexit;
// Operating system futex support used for multithread constructs pub use x::futexwait; pub use x::futexwake; pub use x::futexwakeall;
// Longjmp and setjmp used by libc
pub use x::stackcheckpoint;
pub use x::stackrestore;
// Subprocess support pub use x::procraiseinterval; pub use x::procfork; pub use x::procexec; pub use x::procspawn; pub use x::procid; pub use x::procparent; pub use x::procjoin; pub use x::proc_signal;
// Interface support pub use x::portbridge; pub use x::portunbridge; pub use x::portdhcpacquire; pub use x::portaddradd; pub use x::portaddrremove; pub use x::portaddrclear; pub use x::portmac; pub use x::portaddrlist; pub use x::portgatewayset; pub use x::portrouteadd; pub use x::portrouteremove; pub use x::portrouteclear; pub use x::portroute_list;
// All the missing socket functionality pub use x::sockstatus; pub use x::sockaddrlocal; pub use x::sockaddrpeer; pub use x::socksetoptflag; pub use x::sockgetoptflag; pub use x::socksetopttime; pub use x::sockgetopttime; pub use x::socksetoptsize; pub use x::sockgetoptsize; pub use x::sockjoinmulticastv4; pub use x::sockleavemulticastv4; pub use x::sockjoinmulticastv6; pub use x::sockleavemulticastv6; pub use x::sockbind; pub use x::socklisten; pub use x::sockconnect; pub use x::sockrecvfrom; pub use x::socksendto; pub use x::socksendfile;
// Ability to perform DNS queries pub use x::resolve; ```
First you can depend on this crate via Cargo.toml
:
toml
[dependencies]
wasix = "0.11"
Next you can use the APIs in the root of the module like so:
rust
fn main() {
let stdout = 1;
let message = "Hello, World!\n";
let data = [wasix::Ciovec {
buf: message.as_ptr(),
buf_len: message.len(),
}];
wasix::fd_write(stdout, &data).unwrap();
}
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!
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
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.