WASI P2
WASI P2 is the most recent stable WASI release. It marked the full rebase of WASI onto the Component Model and the WebAssembly Interface Type (WIT) Interface Description Language, replacing the C-like WITX IDL used in WASI P1.
Overview
The WASI P2 release is characterized by the following key features:
-
Component Model foundation. WASI P2 APIs are defined in WIT and consumed as WebAssembly components. This enables modularity, virtualizability (polyfilling one implementation with another), and cross-language interoperability. A component compiled from Rust can communicate or be combined with a component compiled from Go, JavaScript, Python, or any other language with component tooling.
-
Worlds. WASI P2 defines two standard worlds:
wasi:cli/commandtargets command-line programs that export arunfunction, with access to filesystem, environment variables, stdin/stdout/stderr, and other CLI capabilities.wasi:http/proxytargets HTTP proxies that export anincoming-handler, with support for concurrent streaming of multiple HTTP requests.
-
The
wasi:iopackage. Asynchronous I/O in WASI P2 is modeled through thewasi:iopackage, which provides:- A
pollableresource for non-blocking I/O polling across multiple handles input-streamandoutput-streamabstractions for reading and writing byte data- A
pollfunction for waiting on multiple pollables simultaneously Thewasi:iopackage underpins all other WASI P2 interfaces that perform I/O. In WASI 0.3,wasi:iois removed and replaced by the Component Model's nativestream<T>,future<T>, andasync funcprimitives.
- A
Interfaces
APIs designed for WASI P2 are defined in .wit files. The following interfaces are included:
| API | WIT definitions | Description |
|---|---|---|
| I/O | wit | Pollable resources, input/output streams, error handling |
| Clocks | wit | Wall clock and monotonic clock access |
| Random | wit | Cryptographically secure and insecure random number generation |
| Filesystem | wit | File and directory operations on preopened directories |
| Sockets | wit | TCP and UDP networking, DNS resolution |
| CLI | wit | Environment variables, arguments, stdin/stdout/stderr, process exit |
| HTTP | wit | HTTP request/response handling for clients and servers |
You can explore the types and definitions for a given WASI P2 API in its WIT files. When you're ready to start using the API, you will typically generate bindings between the WIT definitions and the language you will be compiling to Wasm. For more information on WIT, see the WIT section of the Component Model documentation.
Runtime support
WASI P2 portability criteria were met by Wasmtime and jco, both of which passed the WASI P2 test suite at the time of certification. Other runtimes including WAMR and WasmEdge have varying levels of WASI P2 support.
Patch releases
WASI P2 includes several patch releases:
| Version | Changelog |
|---|---|
| 0.2.12 | This release stabilizes interfaces for the next release train and removes CLI: Exit With Code from Phase 2. |
| 0.2.11 | This release includes filesystem and sockets documentation updates, including specifying unlink-file-at in terms of POSIX. |
| 0.2.10 | This release includes documentation updates and release automation tooling. |
| 0.2.9 | This release includes a variety of organizational and documentation updates. |
| 0.2.8 | This is a regular release with no major changes. |
| 0.2.7 | This release adds a caveat about support for sync flags. |
| 0.2.6 | This release adds wasi-otel as a phase 0 proposal as well as a release workflow. |
| 0.2.5 | This release includes minor documentation updates. |
| 0.2.4 | This release adds wasi-tls in Phase 1. |
| 0.2.3 | This release includes minor documentation updates. |
| 0.2.2 | This release includes new WIT features for @deprecated feature gates and is exercised in the wasi:http/proxy world. For more information, see component-model/WIT.md. |
| 0.2.1 | This release includes new WIT features for @since and @unstable feature gates. For more information, see component-model/WIT.md. |
| 0.2.0 | This version officially launched with the vote in the WASI Subgroup January 24th, 2024. |