-
Notifications
You must be signed in to change notification settings - Fork 302
Post: The wasm32-wasip2 target has reached tier 2 support #1391
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
layout: post | ||
title: "The wasm32-wasip2 Target Has Reached Tier 2 Support" | ||
author: Yosh Wuyts | ||
--- | ||
|
||
In April of this year we posted an update about [Rust's WASI | ||
targets](https://blog.rust-lang.org/2024/04/09/updates-to-rusts-wasi-targets.html) | ||
to the main Rust blog. In it we covered the rename of the `wasm32-wasi` target | ||
to `wasm32-wasip1`, and the introduction of the new `wasm32-wasip2` target as a | ||
"tier 3" target. This meant that while the target was available as part of | ||
`rust-lang/rustc`, it was not guaranteed to build. We're pleased to announce | ||
that this is changing. | ||
|
||
For those unfamiliar with WebAssembly (Wasm) components and WASI 0.2, here is a | ||
quick, simplified primer: | ||
|
||
- **Core Wasm** is a (virtual) instruction format for programs to be compiled into (think: x86-64). | ||
- **Wasm components** are a container format and type system that wrap Core Wasm instructions into typed, hermetic binaries and libraries (think: ELF). | ||
- **WASI** is a reserved namespace for a collection of standardized Wasm component interfaces (think: POSIX header files). | ||
|
||
For a more detailed explanation see the [WASI 0.2 announcement | ||
post](https://bytecodealliance.org/articles/WASI-0.2) on the Bytecode Alliance | ||
blog. | ||
|
||
## What's new? | ||
|
||
Starting Rust 1.81 (2024-09-05) the `wasm32-wasip2` (WASI 0.2) target will be | ||
made available as a tier-2 target. Among other things this now means it is | ||
guaranteed to build, and will become available to install as a prebuilt target | ||
via Rustup using the following command: | ||
|
||
```bash | ||
rustup target add wasm32-wasip2 | ||
``` | ||
|
||
Up until now Rust users writing [Wasm | ||
Components](https://component-model.bytecodealliance.org) would use tools (like | ||
[cargo-component]) which target the WASI 0.1 target (`wasm32-wasip1`) which | ||
would be packaged into a WASI 0.2 Component by a post-processing step invoked | ||
separately by the tooling. With the introduction of `wasm32-wasip2` as a tier-2 | ||
target, that tooling can instead directly target WASI 0.2 without the need for | ||
additional tooling or compat shims. | ||
|
||
What this also means is that ecosystem crates can begin targeting WASI 0.2 | ||
directly for platform-specific code. WASI 0.1 did not have support for sockets. | ||
Now that we have a stable tier 2 platform available, crate authors should be | ||
able to finally start writing WASI-compatible network code. To target WASI 0.2 | ||
from Rust, authors can use the following `cfg` attribute: | ||
|
||
[cargo-component]: https://github.com/bytecodealliance/cargo-component | ||
|
||
```rust | ||
#[cfg(all(target_os = "wasi", target_env = "p2"))] | ||
mod wasip2 { | ||
// items go here | ||
} | ||
``` | ||
|
||
## What's next? | ||
|
||
The WASI 0.2 Rust target being on tier 2 means it's supported and stable. But | ||
unfortunately it is also still incomplete. Most notably stdlib support is still | ||
limited. To target platform-native functionality we recommend to either use the | ||
[wasi](https://docs.rs/wasi/latest/wasi/) crate directly, which is the WASI | ||
equivalent to the `libc` crate. Or else generate their own bindings to the [WASI | ||
specifications](https://github.com/WebAssembly/WASI/tree/main/wasip2) using the | ||
[wit-bindgen](https://github.com/bytecodealliance/wit-bindgen/) generator. | ||
|
||
We expect to gradually extend the Rust stdlib with support for WASI 0.2 APIs | ||
throughout the remainder of this year into the next. That work has already | ||
started, with for example | ||
[rust-lang/rust#129638](https://github.com/rust-lang/rust/pull/129638) adding | ||
native support for `std::net` to WASI 0.2. We expect more of these PRs to land | ||
through the remainder of the year. | ||
|
||
## Conclusion | ||
|
||
The `wasm32-wasip2` target will become installable via rustup starting Rust | ||
1.81.0 (2024-09-05). This will make it possible for the Rust compiler to | ||
directly compile to the Wasm Components format, targeting the WASI 0.2 | ||
interfaces. We're excited for Wasm Components and WASI 0.2 to have reached this | ||
milestone, and are excited to see what folks in the ecosystem will be building | ||
with it! |
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.
Uh oh!
There was an error while loading. Please reload this page.