Skip to content

Commit ce20876

Browse files
committed
Add a new wasm32-wasip3 target to Rust
This commit adds a new tier 3 target to rustc, `wasm32-wasip3`. This follows in the footsteps of the previous `wasm32-wasip2` target and is used to represent binding to the WASIp3 set of APIs managed by the WASI subgroup to the WebAssembly Community Group. As of now the WASIp3 set of APIs are not finalized nor standardized. They're in the process of doing so and the current trajectory is to have the APIs published in December of this year. The goal here is to get the wheels turning in Rust to have the target in a more-ready-than-nonexistent state by the time this happens in December. For now the `wasm32-wasip3` target looks exactly the same as `wasm32-wasip2` except that `target_env = "p3"` is specified. This indicates to crates in the ecosystem that WASIp3 APIs should be used, such as the [`wasip3` crate]. Over time this target will evolve as implementation in guest toolchains progress, notably: * The standard library will use WASIp3 APIs natively once they're finalized in the WASI subgroup. * Support through `wasi-libc` will be updated to use WASIp3 natively which Rust will then transitively use. * Longer-term, features such as cooperative multithreading will be added to the WASIp3-track of targets to enable using `std::thread`, for example, on this target. These changes are all expected to be non-breaking changes for users of this target. Runtimes supporting WASIp3, currently Wasmtime and Jco, support WASIp2 APIs as well and will work with components whether or not they import WASIp2, both WASIp2 and WASIp3, or just WASIp3 APIs. This means that changing the internal implementation details of libstd over time is expected to be a non-breaking change. [`wasip3` crate]: https://crates.io/crates/wasip3
1 parent 5c7ae0c commit ce20876

File tree

17 files changed

+135
-11
lines changed

17 files changed

+135
-11
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,7 @@ supported_targets! {
16241624
("wasm32v1-none", wasm32v1_none),
16251625
("wasm32-wasip1", wasm32_wasip1),
16261626
("wasm32-wasip2", wasm32_wasip2),
1627+
("wasm32-wasip3", wasm32_wasip3),
16271628
("wasm32-wasip1-threads", wasm32_wasip1_threads),
16281629
("wasm32-wali-linux-musl", wasm32_wali_linux_musl),
16291630
("wasm64-unknown-unknown", wasm64_unknown_unknown),
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! The `wasm32-wasip3` target is the next in the chain of `wasm32-wasip1`, then
2+
//! `wasm32-wasip2`, then WASIp3. The main feature of WASIp3 is native async
3+
//! support in the component model itself.
4+
//!
5+
//! Like `wasm32-wasip2` this target produces a component by default. Support
6+
//! for `wasm32-wasip3` is very early as of the time of this writing so
7+
//! components produced will still import WASIp2 APIs, but that's ok since it's
8+
//! all component-model-level imports anyway. Over time the imports of the
9+
//! standard library will change to WASIp3.
10+
11+
use crate::spec::Target;
12+
13+
pub(crate) fn target() -> Target {
14+
// As of now WASIp3 is a lightly edited wasip2 target, so start with that
15+
// and this may grow over time as more features are supported.
16+
let mut target = super::wasm32_wasip2::target();
17+
target.llvm_target = "wasm32-wasip3".into();
18+
target.options.env = "p3".into();
19+
target
20+
}

library/std/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ wasip2 = { version = '0.14.4', features = [
8585
'rustc-dep-of-std',
8686
], default-features = false, package = 'wasi' }
8787

88+
[target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies]
89+
wasip2 = { version = '0.14.4', features = [
90+
'rustc-dep-of-std',
91+
], default-features = false, package = 'wasi' }
92+
8893
[target.'cfg(target_os = "uefi")'.dependencies]
8994
r-efi = { version = "5.2.0", features = ['rustc-dep-of-std'] }
9095
r-efi-alloc = { version = "2.0.0", features = ['rustc-dep-of-std'] }

library/std/src/os/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub mod linux;
103103
all(target_vendor = "fortanix", target_env = "sgx")
104104
)
105105
)))]
106-
#[cfg(any(target_os = "wasi", doc))]
106+
#[cfg(any(target_os = "wasi", any(target_env = "p1", target_env = "p2"), doc))]
107107
pub mod wasi;
108108

109109
#[cfg(any(all(target_os = "wasi", target_env = "p2"), doc))]

library/std/src/sys/args/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cfg_select! {
3636
mod wasip1;
3737
pub use wasip1::*;
3838
}
39-
all(target_os = "wasi", target_env = "p2") => {
39+
all(target_os = "wasi", any(target_env = "p2", target_env = "p3")) => {
4040
mod wasip2;
4141
pub use wasip2::*;
4242
}

library/std/src/sys/net/connection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cfg_select! {
33
all(target_family = "unix", not(target_os = "l4re")),
44
target_os = "windows",
55
target_os = "hermit",
6-
all(target_os = "wasi", target_env = "p2"),
6+
all(target_os = "wasi", any(target_env = "p2", target_env = "p3")),
77
target_os = "solid_asp3",
88
) => {
99
mod socket;

library/std/src/sys/net/connection/socket/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cfg_select! {
2525
mod unix;
2626
pub use unix::*;
2727
}
28-
all(target_os = "wasi", target_env = "p2") => {
28+
all(target_os = "wasi", any(target_env = "p2", target_env = "p3")) => {
2929
mod wasip2;
3030
pub use wasip2::*;
3131
}

library/std/src/sys/pal/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cfg_select! {
4949
mod vexos;
5050
pub use self::vexos::*;
5151
}
52-
all(target_os = "wasi", target_env = "p2") => {
52+
all(target_os = "wasi", any(target_env = "p2", target_env = "p3")) => {
5353
mod wasip2;
5454
pub use self::wasip2::*;
5555
}

library/std/src/sys/random/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ cfg_select! {
9090
mod wasip1;
9191
pub use wasip1::fill_bytes;
9292
}
93-
all(target_os = "wasi", target_env = "p2") => {
93+
all(target_os = "wasi", any(target_env = "p2", target_env = "p3")) => {
9494
mod wasip2;
9595
pub use wasip2::{fill_bytes, hashmap_random_keys};
9696
}
@@ -115,7 +115,7 @@ cfg_select! {
115115
target_os = "linux",
116116
target_os = "android",
117117
all(target_family = "wasm", target_os = "unknown"),
118-
all(target_os = "wasi", target_env = "p2"),
118+
all(target_os = "wasi", not(target_env = "p1")),
119119
target_os = "xous",
120120
target_os = "vexos",
121121
)))]

library/std/src/sys/stdio/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cfg_select! {
3737
mod wasip1;
3838
pub use wasip1::*;
3939
}
40-
all(target_os = "wasi", target_env = "p2") => {
40+
all(target_os = "wasi", any(target_env = "p2", target_env = "p3")) => {
4141
mod wasip2;
4242
pub use wasip2::*;
4343
}

0 commit comments

Comments
 (0)