]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
1 | <div align="center"> |
2 | <h1><code>wasi</code></h1> | |
e1599b0c | 3 | |
60c5eb7d | 4 | <strong>A <a href="https://bytecodealliance.org/">Bytecode Alliance</a> project</strong> |
e1599b0c | 5 | |
60c5eb7d XL |
6 | <p> |
7 | <strong>WASI API Bindings for Rust</strong> | |
8 | </p> | |
e1599b0c | 9 | |
60c5eb7d XL |
10 | <p> |
11 | <a href="https://crates.io/crates/wasi"><img src="https://img.shields.io/crates/v/wasi.svg?style=flat-square" alt="Crates.io version" /></a> | |
12 | <a href="https://crates.io/crates/wasi"><img src="https://img.shields.io/crates/d/wasi.svg?style=flat-square" alt="Download" /></a> | |
13 | <a href="https://docs.rs/wasi/"><img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square" alt="docs.rs docs" /></a> | |
14 | </p> | |
15 | </div> | |
e1599b0c | 16 | |
60c5eb7d XL |
17 | This crate contains API bindings for [WASI](https://github.com/WebAssembly/WASI) |
18 | system calls in Rust, and currently reflects the `wasi_snapshot_preview1` | |
19 | module. This crate is quite low-level and provides conceptually a "system call" | |
20 | interface. In most settings, it's better to use the Rust standard library, which | |
21 | has WASI support. | |
e1599b0c | 22 | |
60c5eb7d XL |
23 | The `wasi` crate is also entirely procedurally generated from the `*.witx` files |
24 | describing the WASI apis. While some conveniences are provided the bindings here | |
25 | are intentionally low-level! | |
26 | ||
27 | # Usage | |
28 | ||
29 | First you can depend on this crate via `Cargo.toml`: | |
30 | ||
31 | ```toml | |
32 | [dependencies] | |
33 | wasi = "0.8.0" | |
34 | ``` | |
35 | ||
36 | Next you can use the APIs in the root of the module like so: | |
37 | ||
38 | ```rust | |
39 | fn main() { | |
40 | let stdout = 1; | |
41 | let message = "Hello, World!\n"; | |
42 | let data = [wasi::Ciovec { | |
43 | buf: message.as_ptr(), | |
44 | buf_len: message.len(), | |
45 | }]; | |
46 | wasi::fd_write(stdout, &data).unwrap(); | |
47 | } | |
48 | ``` | |
49 | ||
50 | Next you can use a tool like [`cargo | |
51 | wasi`](https://github.com/bytecodealliance/cargo-wasi) to compile and run your | |
52 | project: | |
e1599b0c XL |
53 | |
54 | To compile Rust projects to wasm using WASI, use the `wasm32-wasi` target, | |
55 | like this: | |
56 | ||
57 | ``` | |
60c5eb7d XL |
58 | $ cargo wasi run |
59 | Compiling wasi v0.8.0+wasi-snapshot-preview1 | |
60 | Compiling wut v0.1.0 (/code) | |
61 | Finished dev [unoptimized + debuginfo] target(s) in 0.34s | |
62 | Running `/.cargo/bin/cargo-wasi target/wasm32-wasi/debug/wut.wasm` | |
63 | Running `target/wasm32-wasi/debug/wut.wasm` | |
64 | Hello, World! | |
e1599b0c | 65 | ``` |
60c5eb7d XL |
66 | |
67 | # License | |
68 | ||
69 | This project is licensed under the Apache 2.0 license with the LLVM exception. | |
70 | See [LICENSE](LICENSE) for more details. | |
71 | ||
72 | ### Contribution | |
73 | ||
74 | Unless you explicitly state otherwise, any contribution intentionally submitted | |
75 | for inclusion in this project by you, as defined in the Apache-2.0 license, | |
76 | shall be licensed as above, without any additional terms or conditions. |