From 42d7884fb1fc751c83e274db2c7ef89959f670fb Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Tue, 1 Sep 2026 21:09:29 +0000 Subject: [PATCH 01/12] add p3 feature --- Cargo.toml | 70 ++++++++++++++++++++++++++++++++++++++++++++++--- axum/Cargo.toml | 19 +++++++++++++- axum/src/lib.rs | 1 + src/lib.rs | 40 +++++++++++++++++++++------- 4 files changed, 116 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 386afa8..3b4a3b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,13 @@ repository.workspace = true rust-version.workspace = true [features] -default = ["json"] +default = ["json", "p2"] json = ["dep:serde", "dep:serde_json"] +# WASI backend selection. Exactly one of these must be enabled. +p2 = ["dep:wasip2"] +p3 = ["dep:wasip3"] + [dependencies] anyhow.workspace = true async-task.workspace = true @@ -27,9 +31,11 @@ http.workspace = true itoa.workspace = true pin-project-lite.workspace = true slab.workspace = true -wasip2.workspace = true wstd-macro.workspace = true +wasip2 = { workspace = true, optional = true } +wasip3 = { workspace = true, optional = true } + # optional serde = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } @@ -43,6 +49,62 @@ humantime.workspace = true serde = { workspace = true, features = ["derive"] } serde_json.workspace = true +[[test]] +name = "http_first_byte_timeout" +required-features = ["p2"] + +[[test]] +name = "http_get" +required-features = ["p2"] + +[[test]] +name = "http_get_json" +required-features = ["p2"] + +[[test]] +name = "http_handle_error_code" +required-features = ["p2"] + +[[test]] +name = "http_post" +required-features = ["p2"] + +[[test]] +name = "http_post_json" +required-features = ["p2"] + +[[test]] +name = "http_timeout" +required-features = ["p2"] + +[[test]] +name = "sleep" +required-features = ["p2"] + +[[example]] +name = "complex_http_client" +required-features = ["p2"] + +[[example]] +name = "http_client" +required-features = ["p2"] + +[[example]] +name = "http_server" +required-features = ["p2"] + +[[example]] +name = "http_server_proxy" +required-features = ["p2"] + +[[example]] +name = "tcp_echo_server" +required-features = ["p2"] + +[[example]] +name = "tcp_stream_client" +required-features = ["p2"] + [workspace] members = [ "axum", @@ -95,13 +157,13 @@ test-programs = { path = "test-programs" } tower-service = "0.3.3" ureq = { version = "3.1", default-features = false, features = ["json"] } wasip2 = "1.0" -wstd = { path = ".", version = "=0.6.8" } +wasip3 = "0.8" +wstd = { path = ".", version = "=0.6.8", default-features = false } wstd-axum = { path = "./axum", version = "=0.6.8" } wstd-axum-macro = { path = "./axum/macro", version = "=0.6.8" } wstd-macro = { path = "./macro", version = "=0.6.8" } [package.metadata.docs.rs] -all-features = true targets = [ "wasm32-wasip2" ] diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 154a021..baa5da4 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -13,12 +13,29 @@ rust-version.workspace = true [dependencies] axum.workspace = true tower-service.workspace = true -wstd.workspace = true +wstd = { workspace = true, features = ["json"] } wstd-axum-macro.workspace = true +[features] +default = ["p2"] +p2 = ["wstd/p2"] +p3 = ["wstd/p3"] + [dev-dependencies] anyhow.workspace = true futures-concurrency.workspace = true serde = { workspace = true, features = ["derive"] } serde_qs.workspace = true axum = { workspace = true, features = ["query", "json", "macros"] } + +[[example]] +name = "hello_world" +required-features = ["p2"] + +[[example]] +name = "hello_world_nomacro" +required-features = ["p2"] + +[[example]] +name = "weather" +required-features = ["p2"] diff --git a/axum/src/lib.rs b/axum/src/lib.rs index 3272b91..9536c89 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg(feature = "p2")] //! Support for the [`axum`] web server framework in wasi-http components, via //! [`wstd`]. //! diff --git a/src/lib.rs b/src/lib.rs index ebc673d..0dc8ed7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ //! **TCP echo server** //! //! ```rust,no_run -#![doc = include_str!("../examples/tcp_echo_server.rs")] +#![cfg_attr(feature = "p2", doc = include_str!("../examples/tcp_echo_server.rs"))] //! ``` //! //! **HTTP Client** @@ -30,7 +30,7 @@ //! **HTTP Server** //! //! ```rust,no_run -#![doc = include_str!("../examples/http_server.rs")] +#![cfg_attr(feature = "p2", doc = include_str!("../examples/http_server.rs"))] //! ``` //! //! # Design Decisions @@ -55,30 +55,52 @@ //! These are unique capabilities provided by WASI 0.2, and because this library //! is specific to that are exposed from here. +// Exactly one WASI backend must be selected. See the `p2`/`p3` features. +#[cfg(all(feature = "p2", feature = "p3"))] +compile_error!( + "the `p2` and `p3` features are mutually exclusive — enable exactly one WASI backend" +); +#[cfg(not(any(feature = "p2", feature = "p3")))] +compile_error!("exactly one of the `p2` or `p3` features must be enabled"); + +#[cfg(feature = "p2")] pub mod future; +#[cfg(feature = "p2")] #[macro_use] pub mod http; +#[cfg(feature = "p2")] pub mod io; pub mod iter; +#[cfg(feature = "p2")] pub mod net; +#[cfg(feature = "p2")] pub mod rand; +#[cfg(feature = "p2")] pub mod runtime; +#[cfg(feature = "p2")] pub mod task; +#[cfg(feature = "p2")] pub mod time; -pub use wstd_macro::attr_macro_http_server as http_server; -pub use wstd_macro::attr_macro_main as main; -pub use wstd_macro::attr_macro_test as test; +#[cfg(feature = "p2")] +pub use wstd_macro::{ + attr_macro_http_server as http_server, attr_macro_main as main, attr_macro_test as test, +}; -// Re-export the wasip2 crate for use only by `wstd-macro` macros. The proc -// macros need to generate code that uses these definitions, but we don't want -// to treat it as part of our public API with regards to semver, so we keep it -// under `__internal` as well as doc(hidden) to indicate it is private. +// Re-export the active WASI backend crate for use only by `wstd-macro` macros. +// The proc macros need to generate code that uses these definitions, but we +// don't want to treat it as part of our public API with regards to semver, so +// we keep it under `__internal` as well as doc(hidden) to indicate it is +// private. #[doc(hidden)] pub mod __internal { + #[cfg(feature = "p2")] pub use wasip2; + #[cfg(feature = "p3")] + pub use wasip3; } +#[cfg(feature = "p2")] pub mod prelude { pub use crate::future::FutureExt as _; pub use crate::io::AsyncRead as _; From 4a6e65cc71b452d39000f998e47c04e605c38dd0 Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 2 Sep 2026 12:24:53 +0000 Subject: [PATCH 02/12] add p3 test CI job --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1362609..9681c60 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,6 +54,9 @@ jobs: - name: wstd tests run: cargo test -p wstd -p wstd-axum --target wasm32-wasip2 -- --nocapture + - name: p3 wstd tests + run: cargo test -p wstd -p wstd-axum --target wasm32-wasip2 --no-default-features --features p3 -- --nocapture + - name: test-programs tests run: cargo test -p test-programs -- --nocapture if: steps.creds.outcome == 'success' From ea32edf32998964ef18ab766043b98a226fbf5f4 Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Thu, 3 Sep 2026 14:00:43 +0000 Subject: [PATCH 03/12] use cfg alias --- Cargo.toml | 4 ++++ axum/Cargo.toml | 3 +++ axum/build.rs | 10 ++++++++++ axum/src/lib.rs | 2 +- build.rs | 10 ++++++++++ src/lib.rs | 32 ++++++++++++++++---------------- 6 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 axum/build.rs create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 3b4a3b9..90a90cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,9 @@ json = ["dep:serde", "dep:serde_json"] p2 = ["dep:wasip2"] p3 = ["dep:wasip3"] +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] anyhow.workspace = true async-task.workspace = true @@ -134,6 +137,7 @@ async-task = "4.7" axum = { version = "0.8.6", default-features = false } bytes = "1.10.1" cargo_metadata = "0.22" +cfg_aliases = "0.2" clap = { version = "4.5.26", features = ["derive"] } futures-core = "0.3.19" futures-lite = "1.12.0" diff --git a/axum/Cargo.toml b/axum/Cargo.toml index baa5da4..a27ce78 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -21,6 +21,9 @@ default = ["p2"] p2 = ["wstd/p2"] p3 = ["wstd/p3"] +[build-dependencies] +cfg_aliases.workspace = true + [dev-dependencies] anyhow.workspace = true futures-concurrency.workspace = true diff --git a/axum/build.rs b/axum/build.rs new file mode 100644 index 0000000..5a5f457 --- /dev/null +++ b/axum/build.rs @@ -0,0 +1,10 @@ +use cfg_aliases::cfg_aliases; + +fn main() { + cfg_aliases! { + // TODO https://github.com/bytecodealliance/wstd/issues/147: Swap these + // to use `target_env` instead. + p2: { feature = "p2" }, + p3: { feature = "p3" }, + } +} diff --git a/axum/src/lib.rs b/axum/src/lib.rs index 9536c89..c730fd2 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "p2")] +#![cfg(p2)] //! Support for the [`axum`] web server framework in wasi-http components, via //! [`wstd`]. //! diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..5a5f457 --- /dev/null +++ b/build.rs @@ -0,0 +1,10 @@ +use cfg_aliases::cfg_aliases; + +fn main() { + cfg_aliases! { + // TODO https://github.com/bytecodealliance/wstd/issues/147: Swap these + // to use `target_env` instead. + p2: { feature = "p2" }, + p3: { feature = "p3" }, + } +} diff --git a/src/lib.rs b/src/lib.rs index 0dc8ed7..64ac672 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ //! **TCP echo server** //! //! ```rust,no_run -#![cfg_attr(feature = "p2", doc = include_str!("../examples/tcp_echo_server.rs"))] +#![cfg_attr(p2, doc = include_str!("../examples/tcp_echo_server.rs"))] //! ``` //! //! **HTTP Client** @@ -30,7 +30,7 @@ //! **HTTP Server** //! //! ```rust,no_run -#![cfg_attr(feature = "p2", doc = include_str!("../examples/http_server.rs"))] +#![cfg_attr(p2, doc = include_str!("../examples/http_server.rs"))] //! ``` //! //! # Design Decisions @@ -56,33 +56,33 @@ //! is specific to that are exposed from here. // Exactly one WASI backend must be selected. See the `p2`/`p3` features. -#[cfg(all(feature = "p2", feature = "p3"))] +#[cfg(all(p2, p3))] compile_error!( "the `p2` and `p3` features are mutually exclusive — enable exactly one WASI backend" ); -#[cfg(not(any(feature = "p2", feature = "p3")))] +#[cfg(not(any(p2, p3)))] compile_error!("exactly one of the `p2` or `p3` features must be enabled"); -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod future; -#[cfg(feature = "p2")] +#[cfg(p2)] #[macro_use] pub mod http; -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod io; pub mod iter; -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod net; -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod rand; -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod runtime; -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod task; -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod time; -#[cfg(feature = "p2")] +#[cfg(p2)] pub use wstd_macro::{ attr_macro_http_server as http_server, attr_macro_main as main, attr_macro_test as test, }; @@ -94,13 +94,13 @@ pub use wstd_macro::{ // private. #[doc(hidden)] pub mod __internal { - #[cfg(feature = "p2")] + #[cfg(p2)] pub use wasip2; - #[cfg(feature = "p3")] + #[cfg(p3)] pub use wasip3; } -#[cfg(feature = "p2")] +#[cfg(p2)] pub mod prelude { pub use crate::future::FutureExt as _; pub use crate::io::AsyncRead as _; From adb35fcb17d5d6620bf34464b4909c3b4aeacb9c Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 9 Sep 2026 00:49:00 +0000 Subject: [PATCH 04/12] switch from feature to target --- .cargo/config.toml | 6 ++ .github/actions/install-rust/action.yml | 5 ++ .github/workflows/ci.yaml | 8 +-- Cargo.toml | 75 +++---------------------- axum/Cargo.toml | 20 ------- axum/build.rs | 10 ---- axum/examples/hello_world.rs | 3 + axum/examples/hello_world_nomacro.rs | 3 + axum/examples/weather.rs | 3 + axum/src/lib.rs | 2 +- build.rs | 10 ---- examples/complex_http_client.rs | 3 + examples/http_client.rs | 3 + examples/http_server.rs | 3 + examples/http_server_proxy.rs | 3 + examples/tcp_echo_server.rs | 3 + examples/tcp_stream_client.rs | 3 + src/lib.rs | 36 +++++------- tests/http_first_byte_timeout.rs | 2 + tests/http_get.rs | 2 + tests/http_get_json.rs | 2 + tests/http_handle_error_code.rs | 2 + tests/http_post.rs | 2 + tests/http_post_json.rs | 2 + tests/http_timeout.rs | 2 + tests/sleep.rs | 2 + 26 files changed, 80 insertions(+), 135 deletions(-) delete mode 100644 axum/build.rs delete mode 100644 build.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index e9a242c..aa3925b 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,3 +3,9 @@ # * AWS auth environment variables, for running the wstd-aws integration tests. # * . directory is available at . runner = "wasmtime run -Shttp --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_SESSION_TOKEN --dir .::." + +[target.wasm32-wasip3] +# wasmtime is given: +# * AWS auth environment variables, for running the wstd-aws integration tests. +# * . directory is available at . +runner = "wasmtime run -Shttp -Sp3 --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_SESSION_TOKEN --dir .::." diff --git a/.github/actions/install-rust/action.yml b/.github/actions/install-rust/action.yml index 0d11907..57cc11c 100644 --- a/.github/actions/install-rust/action.yml +++ b/.github/actions/install-rust/action.yml @@ -31,6 +31,11 @@ runs: rustup update "${{ steps.select.outputs.version }}" --no-self-update rustup default "${{ steps.select.outputs.version }}" + # Required for -Zbuild-std for the wasip3 target. + if [ "${{ inputs.toolchain }}" = "nightly" ]; then + rustup component add rust-src + fi + # Save disk space by avoiding incremental compilation. Also turn down # debuginfo from 2 to 0 to help save disk space. cat >> "$GITHUB_ENV" < Date: Wed, 9 Sep 2026 13:03:53 +0000 Subject: [PATCH 05/12] merge fixes --- examples/udp_echo_server.rs | 3 +++ examples/udp_stream_client.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/examples/udp_echo_server.rs b/examples/udp_echo_server.rs index f840107..7c10bc3 100644 --- a/examples/udp_echo_server.rs +++ b/examples/udp_echo_server.rs @@ -1,3 +1,6 @@ +#![cfg_attr(not(target_env = "p2"), no_main)] +#![cfg(target_env = "p2")] + use wstd::io; use wstd::net::UdpSocket; diff --git a/examples/udp_stream_client.rs b/examples/udp_stream_client.rs index 013caee..68626d6 100644 --- a/examples/udp_stream_client.rs +++ b/examples/udp_stream_client.rs @@ -1,3 +1,6 @@ +#![cfg_attr(not(target_env = "p2"), no_main)] +#![cfg(target_env = "p2")] + use wstd::io; use wstd::net::{UdpSocket, UdpStream}; From 6435d57d3330a76224630a92c6aeff371354f255 Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 9 Sep 2026 13:12:01 +0000 Subject: [PATCH 06/12] add job printing rust version --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9e2f537..46cbec8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,6 +48,9 @@ jobs: role-to-assume: arn:aws:iam::313377415443:role/wstd-aws-ci-role role-session-name: github-ci + - name: rust version + run: cargo --version + - name: check run: cargo check --workspace --all --bins --examples From 663c532863e5734eadfc2051f9b712c2d0de3062 Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 9 Sep 2026 13:24:11 +0000 Subject: [PATCH 07/12] try override instead of default --- .github/actions/install-rust/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/install-rust/action.yml b/.github/actions/install-rust/action.yml index 57cc11c..c39c4be 100644 --- a/.github/actions/install-rust/action.yml +++ b/.github/actions/install-rust/action.yml @@ -29,7 +29,9 @@ runs: run: | rustup set profile minimal rustup update "${{ steps.select.outputs.version }}" --no-self-update - rustup default "${{ steps.select.outputs.version }}" + # `rustup default` gets overwritten by rust-toolchain.toml, `rustup + # override` has higher precedence though. + rustup override set "${{ steps.select.outputs.version }}" # Required for -Zbuild-std for the wasip3 target. if [ "${{ inputs.toolchain }}" = "nightly" ]; then From d306e06e369563de71ea16cfae143ff3944700bf Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 9 Sep 2026 13:26:41 +0000 Subject: [PATCH 08/12] explicitly add wasi targets --- .github/actions/install-rust/action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/install-rust/action.yml b/.github/actions/install-rust/action.yml index c39c4be..18957d4 100644 --- a/.github/actions/install-rust/action.yml +++ b/.github/actions/install-rust/action.yml @@ -33,8 +33,11 @@ runs: # override` has higher precedence though. rustup override set "${{ steps.select.outputs.version }}" + rustup target add wasm32-wasip2 + # Required for -Zbuild-std for the wasip3 target. if [ "${{ inputs.toolchain }}" = "nightly" ]; then + rustup target add wasm32-wasip3 rustup component add rust-src fi From 2f8c1c2c449946dbb7f6c710ec784a0d7c76cbf8 Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 9 Sep 2026 13:32:48 +0000 Subject: [PATCH 09/12] bump msrv to latest version with p3 target_env --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e990b9e..9b903c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,7 +64,7 @@ license = "Apache-2.0 WITH LLVM-exception" repository = "https://github.com/bytecodealliance/wstd" keywords = ["WebAssembly", "async", "stdlib", "Components"] categories = ["wasm", "asynchronous"] -rust-version = "1.91.1" +rust-version = "1.92.0" authors = [ "Yoshua Wuyts ", "Pat Hickey ", From 5841233cbe314258dfa55c836c32fd517e23f084 Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 9 Sep 2026 13:38:36 +0000 Subject: [PATCH 10/12] include target_os in directives --- Cargo.toml | 4 ++-- axum/examples/hello_world.rs | 4 ++-- axum/examples/hello_world_nomacro.rs | 4 ++-- axum/examples/weather.rs | 4 ++-- axum/src/lib.rs | 2 +- examples/complex_http_client.rs | 4 ++-- examples/http_client.rs | 4 ++-- examples/http_server.rs | 4 ++-- examples/http_server_proxy.rs | 4 ++-- examples/tcp_echo_server.rs | 4 ++-- examples/tcp_stream_client.rs | 4 ++-- examples/udp_echo_server.rs | 4 ++-- examples/udp_stream_client.rs | 4 ++-- src/lib.rs | 24 ++++++++++++------------ tests/http_first_byte_timeout.rs | 2 +- tests/http_get.rs | 2 +- tests/http_get_json.rs | 2 +- tests/http_handle_error_code.rs | 2 +- tests/http_post.rs | 2 +- tests/http_post_json.rs | 2 +- tests/http_timeout.rs | 2 +- tests/sleep.rs | 2 +- 22 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9b903c1..2a7e28b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,10 +33,10 @@ wstd-macro.workspace = true serde = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } -[target.'cfg(target_env = "p2")'.dependencies] +[target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies] wasip2.workspace = true -[target.'cfg(target_env = "p3")'.dependencies] +[target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies] wasip3.workspace = true [dev-dependencies] diff --git a/axum/examples/hello_world.rs b/axum/examples/hello_world.rs index 8cf124c..9931344 100644 --- a/axum/examples/hello_world.rs +++ b/axum/examples/hello_world.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] //! Run with //! diff --git a/axum/examples/hello_world_nomacro.rs b/axum/examples/hello_world_nomacro.rs index 44744e5..bc0a39b 100644 --- a/axum/examples/hello_world_nomacro.rs +++ b/axum/examples/hello_world_nomacro.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] //! Run with //! diff --git a/axum/examples/weather.rs b/axum/examples/weather.rs index f404c0f..0df8f97 100644 --- a/axum/examples/weather.rs +++ b/axum/examples/weather.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] //! This demo app shows a Axum based wasi-http server making an arbitrary //! number of http requests as part of serving a single response. diff --git a/axum/src/lib.rs b/axum/src/lib.rs index d113410..c5a2af1 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] //! Support for the [`axum`] web server framework in wasi-http components, via //! [`wstd`]. //! diff --git a/examples/complex_http_client.rs b/examples/complex_http_client.rs index 7dadebf..7c3e470 100644 --- a/examples/complex_http_client.rs +++ b/examples/complex_http_client.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use anyhow::{Result, anyhow}; use clap::{ArgAction, Parser}; diff --git a/examples/http_client.rs b/examples/http_client.rs index 6850d60..178fbeb 100644 --- a/examples/http_client.rs +++ b/examples/http_client.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use anyhow::{Result, anyhow}; use clap::{ArgAction, Parser}; diff --git a/examples/http_server.rs b/examples/http_server.rs index 5486f0c..fa67518 100644 --- a/examples/http_server.rs +++ b/examples/http_server.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use anyhow::{Context, Result}; use futures_lite::stream::{once_future, unfold}; diff --git a/examples/http_server_proxy.rs b/examples/http_server_proxy.rs index 77bb231..8d0cf01 100644 --- a/examples/http_server_proxy.rs +++ b/examples/http_server_proxy.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] //! Run the example with: //! ```sh diff --git a/examples/tcp_echo_server.rs b/examples/tcp_echo_server.rs index 3e8aef2..319f911 100644 --- a/examples/tcp_echo_server.rs +++ b/examples/tcp_echo_server.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use wstd::io; use wstd::iter::AsyncIterator; diff --git a/examples/tcp_stream_client.rs b/examples/tcp_stream_client.rs index c14b267..a269b8c 100644 --- a/examples/tcp_stream_client.rs +++ b/examples/tcp_stream_client.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use wstd::io::{self, AsyncRead, AsyncWrite}; use wstd::net::TcpStream; diff --git a/examples/udp_echo_server.rs b/examples/udp_echo_server.rs index 7c10bc3..c441d87 100644 --- a/examples/udp_echo_server.rs +++ b/examples/udp_echo_server.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use wstd::io; use wstd::net::UdpSocket; diff --git a/examples/udp_stream_client.rs b/examples/udp_stream_client.rs index 68626d6..f26f5d5 100644 --- a/examples/udp_stream_client.rs +++ b/examples/udp_stream_client.rs @@ -1,5 +1,5 @@ -#![cfg_attr(not(target_env = "p2"), no_main)] -#![cfg(target_env = "p2")] +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use wstd::io; use wstd::net::{UdpSocket, UdpStream}; diff --git a/src/lib.rs b/src/lib.rs index c3442aa..e7abd6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,26 +55,26 @@ //! These are unique capabilities provided by WASI 0.2, and because this library //! is specific to that are exposed from here. -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod future; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] #[macro_use] pub mod http; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod io; pub mod iter; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod net; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod rand; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod runtime; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod task; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod time; -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub use wstd_macro::{ attr_macro_http_server as http_server, attr_macro_main as main, attr_macro_test as test, }; @@ -86,13 +86,13 @@ pub use wstd_macro::{ // private. #[doc(hidden)] pub mod __internal { - #[cfg(target_env = "p2")] + #[cfg(all(target_os = "wasi", target_env = "p2"))] pub use wasip2; - #[cfg(target_env = "p3")] + #[cfg(all(target_os = "wasi", target_env = "p3"))] pub use wasip3; } -#[cfg(target_env = "p2")] +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod prelude { pub use crate::future::FutureExt as _; pub use crate::io::AsyncRead as _; diff --git a/tests/http_first_byte_timeout.rs b/tests/http_first_byte_timeout.rs index fb22cd3..2162294 100644 --- a/tests/http_first_byte_timeout.rs +++ b/tests/http_first_byte_timeout.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use wstd::http::{Body, Client, Request, error::ErrorCode}; diff --git a/tests/http_get.rs b/tests/http_get.rs index 5660e0e..1735d22 100644 --- a/tests/http_get.rs +++ b/tests/http_get.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use std::error::Error; use wstd::http::{Body, Client, HeaderValue, Request}; diff --git a/tests/http_get_json.rs b/tests/http_get_json.rs index 5596e0b..641c2b7 100644 --- a/tests/http_get_json.rs +++ b/tests/http_get_json.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use serde::Deserialize; use std::error::Error; diff --git a/tests/http_handle_error_code.rs b/tests/http_handle_error_code.rs index 0bbdd1d..fa72e0c 100644 --- a/tests/http_handle_error_code.rs +++ b/tests/http_handle_error_code.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use wstd::http::{Body, Client, Request, error::ErrorCode}; diff --git a/tests/http_post.rs b/tests/http_post.rs index 522c47b..1082a40 100644 --- a/tests/http_post.rs +++ b/tests/http_post.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use std::error::Error; use wstd::http::{Client, HeaderValue, Request}; diff --git a/tests/http_post_json.rs b/tests/http_post_json.rs index 1dc07f2..f67d050 100644 --- a/tests/http_post_json.rs +++ b/tests/http_post_json.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use serde::{Deserialize, Serialize}; use std::error::Error; diff --git a/tests/http_timeout.rs b/tests/http_timeout.rs index 04f60fc..6a156d9 100644 --- a/tests/http_timeout.rs +++ b/tests/http_timeout.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use wstd::future::FutureExt; use wstd::http::{Body, Client, Request}; diff --git a/tests/sleep.rs b/tests/sleep.rs index ac8c72a..c888302 100644 --- a/tests/sleep.rs +++ b/tests/sleep.rs @@ -1,4 +1,4 @@ -#![cfg(target_env = "p2")] +#![cfg(all(target_os = "wasi", target_env = "p2"))] use std::error::Error; use wstd::task::sleep; From 14e1bceb47b0d122b5fb35c8fec342a54b9d1a23 Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Wed, 9 Sep 2026 14:44:57 +0000 Subject: [PATCH 11/12] remove build-std --- .github/actions/install-rust/action.yml | 2 -- .github/workflows/ci.yaml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/actions/install-rust/action.yml b/.github/actions/install-rust/action.yml index 18957d4..3c16f0c 100644 --- a/.github/actions/install-rust/action.yml +++ b/.github/actions/install-rust/action.yml @@ -35,10 +35,8 @@ runs: rustup target add wasm32-wasip2 - # Required for -Zbuild-std for the wasip3 target. if [ "${{ inputs.toolchain }}" = "nightly" ]; then rustup target add wasm32-wasip3 - rustup component add rust-src fi # Save disk space by avoiding incremental compilation. Also turn down diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 46cbec8..598dd5f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -59,7 +59,7 @@ jobs: - name: wstd p3 tests if: matrix.rust == 'nightly' - run: cargo test -p wstd -p wstd-axum --target wasm32-wasip3 -Z build-std=std,panic_abort -- --nocapture + run: cargo test -p wstd -p wstd-axum --target wasm32-wasip3 -- --nocapture - name: test-programs tests run: cargo test -p test-programs -- --nocapture From fb62b45f63f79043ad1c76996e5f02a6eaea385d Mon Sep 17 00:00:00 2001 From: Adam Bratschi-Kaye Date: Thu, 10 Sep 2026 13:10:19 +0000 Subject: [PATCH 12/12] cleanup Cargo.tomls after feature removal --- Cargo.toml | 3 ++- axum/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2a7e28b..6db1876 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,12 +101,13 @@ tower-service = "0.3.3" ureq = { version = "3.1", default-features = false, features = ["json"] } wasip2 = "1.0" wasip3 = "0.8" -wstd = { path = ".", version = "=0.6.8", default-features = false } +wstd = { path = ".", version = "=0.6.8" } wstd-axum = { path = "./axum", version = "=0.6.8" } wstd-axum-macro = { path = "./axum/macro", version = "=0.6.8" } wstd-macro = { path = "./macro", version = "=0.6.8" } [package.metadata.docs.rs] +all-features = true targets = [ "wasm32-wasip2" ] diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 74141e9..154a021 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -13,7 +13,7 @@ rust-version.workspace = true [dependencies] axum.workspace = true tower-service.workspace = true -wstd = { workspace = true, features = ["json"] } +wstd.workspace = true wstd-axum-macro.workspace = true [dev-dependencies]