Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
42d7884
add p3 feature
adamrk Sep 1, 2026
4a6e65c
add p3 test CI job
adamrk Sep 2, 2026
ea32edf
use cfg alias
adamrk Sep 3, 2026
0487755
Require `&mut` for Streams
adamrk Sep 2, 2026
443ef72
remove &self stream methods
adamrk Sep 2, 2026
cabda1f
Add `wstd::main` and `wstd::test` macros for WASIp3
adamrk Sep 2, 2026
adb35fc
switch from feature to target
adamrk Sep 9, 2026
7e37d58
Merge branch 'main' into abk/p3-feature-base
adamrk Sep 9, 2026
26bea8b
merge fixes
adamrk Sep 9, 2026
6435d57
add job printing rust version
adamrk Sep 9, 2026
663c532
try override instead of default
adamrk Sep 9, 2026
d306e06
explicitly add wasi targets
adamrk Sep 9, 2026
2f8c1c2
bump msrv to latest version with p3 target_env
adamrk Sep 9, 2026
5841233
include target_os in directives
adamrk Sep 9, 2026
d880934
Merge branch 'abk/p3-feature-base' into abk/shared-ref-changes
adamrk Sep 9, 2026
47b889b
Merge branch 'abk/shared-ref-changes' into abk/main-macro-for-wasip3
adamrk Sep 9, 2026
114abd0
fixes from merge
adamrk Sep 9, 2026
9d58000
use wit_bindgen::block_on in macros
adamrk Sep 9, 2026
14e1bce
remove build-std
adamrk Sep 9, 2026
2adec58
remove dead code
adamrk Sep 9, 2026
6150b98
no main for non-wasi targets
adamrk Sep 9, 2026
d8994a6
Merge branch 'abk/p3-feature-base' into abk/shared-ref-changes
adamrk Sep 9, 2026
2c7a618
Merge branch 'abk/shared-ref-changes' into abk/main-macro-for-wasip3
adamrk Sep 9, 2026
64f20f5
change block_on static requirement
adamrk Sep 9, 2026
c3a377c
cleanup Cargo.tomls after feature removal
adamrk Sep 10, 2026
fb62b45
cleanup Cargo.tomls after feature removal
adamrk Sep 10, 2026
d3826e3
Merge branch 'abk/p3-feature-base' into abk/shared-ref-changes
adamrk Sep 10, 2026
d4fd717
Merge branch 'abk/shared-ref-changes' into abk/main-macro-for-wasip3
adamrk Sep 10, 2026
fdb266c
keep http macro only in p2
adamrk Sep 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .::."
10 changes: 9 additions & 1 deletion .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -90,4 +97,3 @@ jobs:
- run: ./publish bump
# Make sure the tree is publish-able as-is
- run: ./publish verify

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <rust@yosh.is>",
"Pat Hickey <pat@moreproductive.org>",
Expand Down Expand Up @@ -95,6 +100,7 @@ test-programs = { path = "test-programs" }
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" }
wstd-axum = { path = "./axum", version = "=0.6.8" }
wstd-axum-macro = { path = "./axum/macro", version = "=0.6.8" }
Expand Down
3 changes: 3 additions & 0 deletions axum/examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions axum/examples/hello_world_nomacro.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions axum/examples/weather.rs
Original file line number Diff line number Diff line change
@@ -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.
//!
Expand Down
1 change: 1 addition & 0 deletions axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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`].
//!
Expand Down
3 changes: 3 additions & 0 deletions examples/complex_http_client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions examples/http_client.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 3 additions & 0 deletions examples/http_server.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 3 additions & 0 deletions examples/http_server_proxy.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions examples/macro_main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![cfg_attr(not(target_os = "wasi"), no_main)]
#![cfg(target_os = "wasi")]

//! Verifies that the `main` macro is compiling.

#[wstd::main]
async fn main() {
println!("Hello world");
}
9 changes: 7 additions & 2 deletions examples/tcp_echo_server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#![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;

#[wstd::main]
async fn main() -> io::Result<()> {
let listener = TcpListener::bind("127.0.0.1:8080").await?;
let mut listener = TcpListener::bind("127.0.0.1:8080").await?;
println!("Listening on {}", listener.local_addr()?);
println!("type `nc localhost 8080` to create a TCP client");

Expand All @@ -14,7 +17,9 @@ async fn main() -> io::Result<()> {
println!("Accepted from: {}", stream.peer_addr()?);
wstd::runtime::spawn(async move {
// If echo copy fails, we can ignore it.
let _ = io::copy(&stream, &stream).await;
let mut stream = stream;
let (mut read_half, mut write_half) = stream.split();
let _ = io::copy(&mut read_half, &mut write_half).await;
})
.detach();
}
Expand Down
3 changes: 3 additions & 0 deletions examples/tcp_stream_client.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 3 additions & 0 deletions examples/udp_echo_server.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 3 additions & 0 deletions examples/udp_stream_client.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
12 changes: 6 additions & 6 deletions src/http/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::http::{
error::Context as _,
fields::{header_map_from_wasi, header_map_to_wasi},
};
use crate::io::{AsyncInputStream, AsyncOutputStream};
use crate::io::{AsyncInputStream, AsyncOutputStream, AsyncWrite};
use crate::runtime::{AsyncPollable, Reactor, WaitFor};

pub use ::http_body::{Body as HttpBody, Frame, SizeHint};
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Body {
match self.0 {
BodyInner::Incoming(incoming) => incoming.send(outgoing_body).await,
BodyInner::Boxed(box_body) => {
let out_stream = AsyncOutputStream::new(
let mut out_stream = AsyncOutputStream::new(
outgoing_body
.write()
.expect("outgoing body already written"),
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Body {
}
}
BodyInner::Complete { data, trailers } => {
let out_stream = AsyncOutputStream::new(
let mut out_stream = AsyncOutputStream::new(
outgoing_body
.write()
.expect("outgoing body already written"),
Expand Down Expand Up @@ -348,14 +348,14 @@ impl Incoming {
}
async fn send(self, outgoing_body: WasiOutgoingBody) -> Result<(), Error> {
let in_body = self.body;
let in_stream =
let mut in_stream =
AsyncInputStream::new(in_body.stream().expect("incoming body already read"));
let out_stream = AsyncOutputStream::new(
let mut out_stream = AsyncOutputStream::new(
outgoing_body
.write()
.expect("outgoing body already written"),
);
in_stream.copy_to(&out_stream).await.map_err(|e| {
in_stream.copy_to(&mut out_stream).await.map_err(|e| {
Error::from(e).context("copying incoming body stream to outgoing body stream")
})?;
drop(in_stream);
Expand Down
4 changes: 2 additions & 2 deletions src/io/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait AsyncRead {
// If the `AsyncRead` implementation is an unbuffered wrapper around an
// `AsyncInputStream`, some I/O operations can be more efficient.
#[inline]
fn as_async_input_stream(&self) -> Option<&io::AsyncInputStream> {
fn as_async_input_stream(&mut self) -> Option<&mut io::AsyncInputStream> {
None
}
}
Expand All @@ -45,7 +45,7 @@ impl<R: AsyncRead + ?Sized> AsyncRead for &mut R {
}

#[inline]
fn as_async_input_stream(&self) -> Option<&io::AsyncInputStream> {
fn as_async_input_stream(&mut self) -> Option<&mut io::AsyncInputStream> {
(**self).as_async_input_stream()
}
}
8 changes: 4 additions & 4 deletions src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl AsyncRead for Stdin {
}

#[inline]
fn as_async_input_stream(&self) -> Option<&AsyncInputStream> {
Some(&self.stream)
fn as_async_input_stream(&mut self) -> Option<&mut AsyncInputStream> {
Some(&mut self.stream)
}
}

Expand Down Expand Up @@ -93,7 +93,7 @@ impl AsyncWrite for Stdout {
}

#[inline]
fn as_async_output_stream(&self) -> Option<&AsyncOutputStream> {
fn as_async_output_stream(&mut self) -> Option<&mut AsyncOutputStream> {
self.stream.as_async_output_stream()
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ impl AsyncWrite for Stderr {
}

#[inline]
fn as_async_output_stream(&self) -> Option<&AsyncOutputStream> {
fn as_async_output_stream(&mut self) -> Option<&mut AsyncOutputStream> {
self.stream.as_async_output_stream()
}
}
Expand Down
Loading
Loading