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..3c16f0c 100644 --- a/.github/actions/install-rust/action.yml +++ b/.github/actions/install-rust/action.yml @@ -29,7 +29,15 @@ 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 }}" + + rustup target add wasm32-wasip2 + + if [ "${{ inputs.toolchain }}" = "nightly" ]; then + rustup target add wasm32-wasip3 + fi # Save disk space by avoiding incremental compilation. Also turn down # debuginfo from 2 to 0 to help save disk space. diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1362609..598dd5f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,12 +48,19 @@ 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 - - name: wstd tests + - name: wstd p2 tests run: cargo test -p wstd -p wstd-axum --target wasm32-wasip2 -- --nocapture + - name: wstd p3 tests + if: matrix.rust == 'nightly' + run: cargo test -p wstd -p wstd-axum --target wasm32-wasip3 -- --nocapture + - name: test-programs tests run: cargo test -p test-programs -- --nocapture if: steps.creds.outcome == 'success' @@ -90,4 +97,3 @@ jobs: - run: ./publish bump # Make sure the tree is publish-able as-is - run: ./publish verify - diff --git a/Cargo.toml b/Cargo.toml index fd399e4..2a7e28b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,13 +27,18 @@ http.workspace = true itoa.workspace = true pin-project-lite.workspace = true slab.workspace = true -wasip2.workspace = true wstd-macro.workspace = true # optional serde = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } +[target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies] +wasip2.workspace = true + +[target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies] +wasip3.workspace = true + [dev-dependencies] anyhow.workspace = true clap.workspace = true @@ -59,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 ", @@ -95,13 +100,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..74141e9 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 +wstd = { workspace = true, features = ["json"] } wstd-axum-macro.workspace = true [dev-dependencies] diff --git a/axum/examples/hello_world.rs b/axum/examples/hello_world.rs index 90a9cbd..9931344 100644 --- a/axum/examples/hello_world.rs +++ b/axum/examples/hello_world.rs @@ -1,3 +1,6 @@ +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] + //! Run with //! //! ```sh diff --git a/axum/examples/hello_world_nomacro.rs b/axum/examples/hello_world_nomacro.rs index f3068d1..bc0a39b 100644 --- a/axum/examples/hello_world_nomacro.rs +++ b/axum/examples/hello_world_nomacro.rs @@ -1,3 +1,6 @@ +#![cfg_attr(not(all(target_os = "wasi", target_env = "p2")), no_main)] +#![cfg(all(target_os = "wasi", target_env = "p2"))] + //! Run with //! //! ```sh diff --git a/axum/examples/weather.rs b/axum/examples/weather.rs index 5163fcc..0df8f97 100644 --- a/axum/examples/weather.rs +++ b/axum/examples/weather.rs @@ -1,3 +1,6 @@ +#![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 3272b91..c5a2af1 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -1,3 +1,4 @@ +#![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 703e931..7c3e470 100644 --- a/examples/complex_http_client.rs +++ b/examples/complex_http_client.rs @@ -1,3 +1,6 @@ +#![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}; use std::str::FromStr; diff --git a/examples/http_client.rs b/examples/http_client.rs index f4465a8..178fbeb 100644 --- a/examples/http_client.rs +++ b/examples/http_client.rs @@ -1,3 +1,6 @@ +#![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}; use wstd::http::{Body, BodyExt, Client, Method, Request, Uri}; diff --git a/examples/http_server.rs b/examples/http_server.rs index 8449f83..fa67518 100644 --- a/examples/http_server.rs +++ b/examples/http_server.rs @@ -1,3 +1,6 @@ +#![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}; use http_body_util::{BodyExt, StreamBody}; diff --git a/examples/http_server_proxy.rs b/examples/http_server_proxy.rs index ccad608..8d0cf01 100644 --- a/examples/http_server_proxy.rs +++ b/examples/http_server_proxy.rs @@ -1,3 +1,6 @@ +#![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 //! cargo build --example http_server_proxy --target=wasm32-wasip2 diff --git a/examples/tcp_echo_server.rs b/examples/tcp_echo_server.rs index f1dd895..319f911 100644 --- a/examples/tcp_echo_server.rs +++ b/examples/tcp_echo_server.rs @@ -1,3 +1,6 @@ +#![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; use wstd::net::TcpListener; diff --git a/examples/tcp_stream_client.rs b/examples/tcp_stream_client.rs index 2e93faf..a269b8c 100644 --- a/examples/tcp_stream_client.rs +++ b/examples/tcp_stream_client.rs @@ -1,3 +1,6 @@ +#![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 f840107..c441d87 100644 --- a/examples/udp_echo_server.rs +++ b/examples/udp_echo_server.rs @@ -1,3 +1,6 @@ +#![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 013caee..f26f5d5 100644 --- a/examples/udp_stream_client.rs +++ b/examples/udp_stream_client.rs @@ -1,3 +1,6 @@ +#![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 ebc673d..e7abd6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,30 +55,44 @@ //! These are unique capabilities provided by WASI 0.2, and because this library //! is specific to that are exposed from here. +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod future; +#[cfg(all(target_os = "wasi", target_env = "p2"))] #[macro_use] pub mod http; +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod io; pub mod iter; +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod net; +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod rand; +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod runtime; +#[cfg(all(target_os = "wasi", target_env = "p2"))] pub mod task; +#[cfg(all(target_os = "wasi", target_env = "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(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, +}; -// 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(all(target_os = "wasi", target_env = "p2"))] pub use wasip2; + #[cfg(all(target_os = "wasi", target_env = "p3"))] + pub use wasip3; } +#[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 5fd47be..2162294 100644 --- a/tests/http_first_byte_timeout.rs +++ b/tests/http_first_byte_timeout.rs @@ -1,3 +1,5 @@ +#![cfg(all(target_os = "wasi", target_env = "p2"))] + use wstd::http::{Body, Client, Request, error::ErrorCode}; #[wstd::main] diff --git a/tests/http_get.rs b/tests/http_get.rs index e7a3a5a..1735d22 100644 --- a/tests/http_get.rs +++ b/tests/http_get.rs @@ -1,3 +1,5 @@ +#![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 a4f42b6..641c2b7 100644 --- a/tests/http_get_json.rs +++ b/tests/http_get_json.rs @@ -1,3 +1,5 @@ +#![cfg(all(target_os = "wasi", target_env = "p2"))] + use serde::Deserialize; use std::error::Error; use wstd::http::{Body, Client, Request}; diff --git a/tests/http_handle_error_code.rs b/tests/http_handle_error_code.rs index 6affb90..fa72e0c 100644 --- a/tests/http_handle_error_code.rs +++ b/tests/http_handle_error_code.rs @@ -1,3 +1,5 @@ +#![cfg(all(target_os = "wasi", target_env = "p2"))] + use wstd::http::{Body, Client, Request, error::ErrorCode}; /// Test that `outgoing_handler::handle` errors are properly propagated. diff --git a/tests/http_post.rs b/tests/http_post.rs index 5de184d..1082a40 100644 --- a/tests/http_post.rs +++ b/tests/http_post.rs @@ -1,3 +1,5 @@ +#![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 f9fcf07..f67d050 100644 --- a/tests/http_post_json.rs +++ b/tests/http_post_json.rs @@ -1,3 +1,5 @@ +#![cfg(all(target_os = "wasi", target_env = "p2"))] + use serde::{Deserialize, Serialize}; use std::error::Error; use wstd::http::{Body, Client, HeaderValue, Request}; diff --git a/tests/http_timeout.rs b/tests/http_timeout.rs index 96d40de..6a156d9 100644 --- a/tests/http_timeout.rs +++ b/tests/http_timeout.rs @@ -1,3 +1,5 @@ +#![cfg(all(target_os = "wasi", target_env = "p2"))] + use wstd::future::FutureExt; use wstd::http::{Body, Client, Request}; use wstd::time::Duration; diff --git a/tests/sleep.rs b/tests/sleep.rs index eb55ea0..c888302 100644 --- a/tests/sleep.rs +++ b/tests/sleep.rs @@ -1,3 +1,5 @@ +#![cfg(all(target_os = "wasi", target_env = "p2"))] + use std::error::Error; use wstd::task::sleep; use wstd::time::Duration;