Skip to content

std: Start supporting WASIp2 natively #145944

Merged
bors merged 2 commits intorust-lang:masterfrom
alexcrichton:native-wasip2
Sep 3, 2025
Merged

std: Start supporting WASIp2 natively #145944
bors merged 2 commits intorust-lang:masterfrom
alexcrichton:native-wasip2

Conversation

@alexcrichton
Copy link
Member

This commit is the start of an effort to support WASIp2 natively in the
standard library. Before this commit the wasm32-wasip2 target behaved
exactly like wasm32-wasip1 target by importing APIs from the core wasm
module wasi_snapshot_preview1. These APIs are satisfied by the
wasm-component-ld target by using an adapter which implements WASIp1
in terms of WASIp2. This adapter comes at a cost, however, in terms of
runtime indirection and instantiation cost, so ideally the adapter would
be removed entirely. The purpose of this adapter was to provide a
smoother on-ramp from WASIp1 to WASIp2 when it was originally created.

The wasm32-wasip2 target has been around for long enough now that it's
much more established. Additionally the only thing historically blocking
using WASIp2 directly was implementation effort. Work is now underway to
migrate wasi-libc itself to using WASIp2 directly and now seems as good
a time as any to migrate the Rust standard library too.

Implementation-wise the milestones here are:

  • The wasm32-wasip2 target now also depends on the wasi crate at
    version 0.14.* in addition to the preexisting dependency of 0.11..
    The 0.14.
    release series binds WASIp2 APIs instead of WASIp1 APIs.
  • Some preexisting naming around mod wasi or wasi.rs was renamed to
    wasip1 where appropriate. For example std::sys::pal::wasi is now
    called std::sys::pal::wasip1.
  • More platform-specific WASI modules are now split between WASIp1 and
    WASIp2. For example getting the current time, randomness, and
    process arguments now use WASIp2 APIs directly instead of using WASIp1
    APIs that require an adapter.

It's worth pointing out that this PR does not migrate the entire
standard library away from using WASIp1 APIs on the wasm32-wasip2
target. Everything related to file descriptors and filesystem APIs is
still using WASIp1. Migrating that is left for a future PR. In the
meantime the goal of this change is to lay the groundwork necessary for
migrating in the future. Eventually the goal is to drop the wasi
0.11.* dependency on the wasm32-wasip2 target (the wasm32-wasip1
target will continue to retain this dependency).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-tidy Area: The tidy tool O-wasi Operating system: Wasi, Webassembly System Interface S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants