<div align="center">
  <h1><code>wasip2</code></h1>

<strong>A <a href="https://bytecodealliance.org/">Bytecode Alliance</a> project</strong>

  <p>
    <strong>WASIp2 API Bindings for Rust</strong>
  </p>

  <p>
    <a href="https://crates.io/crates/wasip2"><img src="https://img.shields.io/crates/v/wasip2.svg?style=flat-square" alt="Crates.io version" /></a>
    <a href="https://crates.io/crates/wasip2"><img src="https://img.shields.io/crates/d/wasip2.svg?style=flat-square" alt="Download" /></a>
    <a href="https://docs.rs/wasip2/"><img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square" alt="docs.rs docs" /></a>
  </p>
</div>

This crate contains bindings for [WASIp2](https://github.com/WebAssembly/WASI)
APIs for the worlds:

* [`wasi:cli/command`]
* [`wasi:http/proxy`]

This crate is procedurally generated from [WIT] files using [`wit-bindgen`].

[`wasi:cli/command`]: https://github.com/WebAssembly/wasi-cli
[`wasi:http/proxy`]: https://github.com/WebAssembly/wasi-http
[WIT]: https://component-model.bytecodealliance.org/design/wit.html
[`wit-bindgen`]: https://github.com/bytecodealliance/wit-bindgen
[components]: https://component-model.bytecodealliance.org/
[`wasm-tools`]: https://github.com/bytecodealliance/wasm-tools

# Usage

Depending on this crate can be done by adding it to your dependencies:

```sh
$ cargo add wasip2
```

Next you can use the APIs in the root of the module like so:

```rust
fn main() {
    let stdout = wasip2::cli::stdout::get_stdout();
    stdout.blocking_write_and_flush(b"Hello, world!\n").unwrap();
}
```

Next you can run this by [configuring a runner][runner] and using the
`wasm32-wasip2` target:

```
$ cargo run --target wasm32-wasip2 --config 'target."wasm32-wasip2".runner="wasmtime"'
...
Hello, world!
```

[runner]: https://doc.rust-lang.org/cargo/reference/config.html#targettriplerunner

# Development

The bulk of the `wasip2` crate is generated by the [`wit-bindgen`] tool. The
various files can be regenerated from the root of this repository with:

```
$ ./ci/regenerate.sh
```

WASI definitions are located in the `wit` directory of this folder.
Currently they're copied from upstream repositories but are hoped to be better
managed in the future.
