Skip to main content

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/command targets command-line programs that export a run function, with access to filesystem, environment variables, stdin/stdout/stderr, and other CLI capabilities.
    • wasi:http/proxy targets HTTP proxies that export an incoming-handler, with support for concurrent streaming of multiple HTTP requests.
  • The wasi:io package. Asynchronous I/O in WASI P2 is modeled through the wasi:io package, which provides:

    • A pollable resource for non-blocking I/O polling across multiple handles
    • input-stream and output-stream abstractions for reading and writing byte data
    • A poll function for waiting on multiple pollables simultaneously The wasi:io package underpins all other WASI P2 interfaces that perform I/O. In WASI 0.3, wasi:io is removed and replaced by the Component Model's native stream<T>, future<T>, and async func primitives.

Interfaces

APIs designed for WASI P2 are defined in .wit files. The following interfaces are included:

APIWIT definitionsDescription
I/OwitPollable resources, input/output streams, error handling
ClockswitWall clock and monotonic clock access
RandomwitCryptographically secure and insecure random number generation
FilesystemwitFile and directory operations on preopened directories
SocketswitTCP and UDP networking, DNS resolution
CLIwitEnvironment variables, arguments, stdin/stdout/stderr, process exit
HTTPwitHTTP 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:

VersionChangelog
0.2.12This release stabilizes interfaces for the next release train and removes CLI: Exit With Code from Phase 2.
0.2.11This release includes filesystem and sockets documentation updates, including specifying unlink-file-at in terms of POSIX.
0.2.10This release includes documentation updates and release automation tooling.
0.2.9This release includes a variety of organizational and documentation updates.
0.2.8This is a regular release with no major changes.
0.2.7This release adds a caveat about support for sync flags.
0.2.6This release adds wasi-otel as a phase 0 proposal as well as a release workflow.
0.2.5This release includes minor documentation updates.
0.2.4This release adds wasi-tls in Phase 1.
0.2.3This release includes minor documentation updates.
0.2.2This 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.1This release includes new WIT features for @since and @unstable feature gates. For more information, see component-model/WIT.md.
0.2.0This version officially launched with the vote in the WASI Subgroup January 24th, 2024.

Further reading