-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add a new wasm32-wasip3
target to Rust
#147205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexcrichton
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
alexcrichton:wasip3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//! The `wasm32-wasip3` target is the next in the chain of `wasm32-wasip1`, then | ||
//! `wasm32-wasip2`, then WASIp3. The main feature of WASIp3 is native async | ||
//! support in the component model itself. | ||
//! | ||
//! Like `wasm32-wasip2` this target produces a component by default. Support | ||
//! for `wasm32-wasip3` is very early as of the time of this writing so | ||
//! components produced will still import WASIp2 APIs, but that's ok since it's | ||
//! all component-model-level imports anyway. Over time the imports of the | ||
//! standard library will change to WASIp3. | ||
|
||
use crate::spec::Target; | ||
|
||
pub(crate) fn target() -> Target { | ||
// As of now WASIp3 is a lightly edited wasip2 target, so start with that | ||
// and this may grow over time as more features are supported. | ||
let mut target = super::wasm32_wasip2::target(); | ||
target.llvm_target = "wasm32-wasip3".into(); | ||
target.options.env = "p3".into(); | ||
target | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# `wasm32-wasip3` | ||
|
||
**Tier: 3** | ||
|
||
The `wasm32-wasip3` target is the next stage of evolution of the | ||
[`wasm32-wasip2`](./wasm32-wasip2.md) target. The `wasm32-wasip3` target enables | ||
the Rust standard library to use WASIp3 APIs to implement various pieces of | ||
functionality. WASIp3 brings native async support over WASIp2, which integrates | ||
well with Rust's `async` ecosystem. | ||
|
||
> **Note**: As of 2025-10-01 WASIp3 has not yet been approved by the WASI | ||
> subgroup of the WebAssembly Community Group. Development is expected to | ||
> conclude in late 2025 or early 2026. Until then the Rust standard library | ||
> won't actually use WASIp3 APIs on the `wasm32-wasip3` target as they are not | ||
> yet stable and would reduce the stability of this target. Once WASIp3 is | ||
> approved, however, the standard library will update to use WASIp3 natively. | ||
|
||
> **Note**: This target does not yet build as of 2025-10-01 due to and update | ||
> needed in the `libc` crate. Using it will require a `[patch]` for now. | ||
|
||
> **Note**: Until the standard library is fully migrated to use the `wasip3` | ||
> crate then components produced for `wasm32-wasip3` may import WASIp2 APIs. | ||
> This is considered a transitionary phase until fully support of libstd is | ||
> implemented. | ||
|
||
## Target maintainers | ||
|
||
[@alexcrichton](https://github.com/alexcrichton) | ||
|
||
## Requirements | ||
|
||
This target is cross-compiled. The target supports `std` fully. | ||
|
||
## Platform requirements | ||
|
||
The WebAssembly runtime should support both WASIp2 and WASIp3. Runtimes also | ||
are required to support components since this target outputs a component as | ||
opposed to a core wasm module. Two example runtimes for WASIp3 are [Wasmtime] | ||
and [Jco]. | ||
|
||
[Wasmtime]: https://wasmtime.dev/ | ||
[Jco]: https://github.com/bytecodealliance/jco | ||
|
||
## Building the target | ||
|
||
To build this target first acquire a copy of | ||
[`wasi-sdk`](https://github.com/WebAssembly/wasi-sdk/). At this time version 22 | ||
is the minimum needed. | ||
|
||
Next configure the `WASI_SDK_PATH` environment variable to point to where this | ||
is installed. For example: | ||
|
||
```text | ||
export WASI_SDK_PATH=/path/to/wasi-sdk-22.0 | ||
``` | ||
|
||
Next be sure to enable LLD when building Rust from source as LLVM's `wasm-ld` | ||
driver for LLD is required when linking WebAssembly code together. Rust's build | ||
system will automatically pick up any necessary binaries and programs from | ||
`WASI_SDK_PATH`. | ||
|
||
## Testing | ||
|
||
This target is not tested in CI at this time. Locally it can be tested with a | ||
`wasmtime` binary in `PATH` like so: | ||
|
||
```text | ||
./x.py test --target wasm32-wasip3 tests/ui | ||
``` | ||
|
||
## Conditionally compiling code | ||
|
||
It's recommended to conditionally compile code for this target with: | ||
|
||
```text | ||
#[cfg(all(target_os = "wasi", target_env = "p3"))] | ||
``` | ||
|
||
## Enabled WebAssembly features | ||
|
||
The default set of WebAssembly features enabled for compilation is currently the | ||
same as [`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md). See the | ||
documentation there for more information. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question (somewhat off-topic): what are the long term plans for the
wasm32-wasip*
set of targets? Or are the WASIpN more like "profiles" in terms of which WASI APIs are available?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say that the WASI targets are quite like profiles. For today's meeting between T-Lang and the Wasmtime team (unrelated to this PR), Alex wrote the following about the WASI versions. I thought it was really good, so I'll paste it here in full:
The plan is to eventually drive WASI to a 1.0 status, at which point we'll be able to drop the "preview" suffix. From a maintenance perspective WASIp2, WASIp3, and the eventual WASI 1.0 will share most of their infrastructure in the compiler, with most of the differences being in the stdlib. This should make them relatively easy to maintain as a set. This is different for WASI 0.1, which is different enough from the other targets that it needs to be maintained as its own target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense and is helpful context. Thanks.