std: Start supporting WASIp2 natively #145944
Merged
bors merged 2 commits intorust-lang:masterfrom Sep 3, 2025
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit is the start of an effort to support WASIp2 natively in the
standard library. Before this commit the
wasm32-wasip2target behavedexactly like
wasm32-wasip1target by importing APIs from the core wasmmodule
wasi_snapshot_preview1. These APIs are satisfied by thewasm-component-ldtarget by using an adapter which implements WASIp1in 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-wasip2target has been around for long enough now that it'smuch 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:
wasm32-wasip2target now also depends on thewasicrate atversion 0.14.* in addition to the preexisting dependency of 0.11..
The 0.14. release series binds WASIp2 APIs instead of WASIp1 APIs.
mod wasiorwasi.rswas renamed towasip1where appropriate. For examplestd::sys::pal::wasiis nowcalled
std::sys::pal::wasip1.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-wasip2target. 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
wasi0.11.* dependency on the
wasm32-wasip2target (thewasm32-wasip1target will continue to retain this dependency).