Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 .::."
5 changes: 5 additions & 0 deletions .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" <<EOF
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ jobs:
- 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 -Z build-std=std,panic_abort -- --nocapture

- name: test-programs tests
run: cargo test -p test-programs -- --nocapture
if: steps.creds.outcome == 'success'
Expand Down Expand Up @@ -90,4 +94,3 @@ jobs:
- run: ./publish bump
# Make sure the tree is publish-able as-is
- run: ./publish verify

11 changes: 8 additions & 3 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(target_env = "p2")'.dependencies]
wasip2.workspace = true

[target.'cfg(target_env = "p3")'.dependencies]
wasip3.workspace = true

[dev-dependencies]
anyhow.workspace = true
clap.workspace = true
Expand Down Expand Up @@ -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"
]
2 changes: 1 addition & 1 deletion axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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(target_env = "p2"), no_main)]
#![cfg(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(target_env = "p2"), no_main)]
#![cfg(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(target_env = "p2"), no_main)]
#![cfg(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(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(target_env = "p2"), no_main)]
#![cfg(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(target_env = "p2"), no_main)]
#![cfg(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(target_env = "p2"), no_main)]
#![cfg(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(target_env = "p2"), no_main)]
#![cfg(target_env = "p2")]

//! Run the example with:
//! ```sh
//! cargo build --example http_server_proxy --target=wasm32-wasip2
Expand Down
3 changes: 3 additions & 0 deletions examples/tcp_echo_server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg_attr(not(target_env = "p2"), no_main)]
#![cfg(target_env = "p2")]

use wstd::io;
use wstd::iter::AsyncIterator;
use wstd::net::TcpListener;
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(target_env = "p2"), no_main)]
#![cfg(target_env = "p2")]

use wstd::io::{self, AsyncRead, AsyncWrite};
use wstd::net::TcpStream;

Expand Down
28 changes: 21 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(target_env = "p2")]
pub mod future;
#[cfg(target_env = "p2")]
#[macro_use]
pub mod http;
#[cfg(target_env = "p2")]
pub mod io;
pub mod iter;
#[cfg(target_env = "p2")]
pub mod net;
#[cfg(target_env = "p2")]
pub mod rand;
#[cfg(target_env = "p2")]
pub mod runtime;
#[cfg(target_env = "p2")]
pub mod task;
#[cfg(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(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(target_env = "p2")]
pub use wasip2;
#[cfg(target_env = "p3")]
pub use wasip3;
}

#[cfg(target_env = "p2")]
pub mod prelude {
pub use crate::future::FutureExt as _;
pub use crate::io::AsyncRead as _;
Expand Down
2 changes: 2 additions & 0 deletions tests/http_first_byte_timeout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use wstd::http::{Body, Client, Request, error::ErrorCode};

#[wstd::main]
Expand Down
2 changes: 2 additions & 0 deletions tests/http_get.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use std::error::Error;
use wstd::http::{Body, Client, HeaderValue, Request};

Expand Down
2 changes: 2 additions & 0 deletions tests/http_get_json.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use serde::Deserialize;
use std::error::Error;
use wstd::http::{Body, Client, Request};
Expand Down
2 changes: 2 additions & 0 deletions tests/http_handle_error_code.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use wstd::http::{Body, Client, Request, error::ErrorCode};

/// Test that `outgoing_handler::handle` errors are properly propagated.
Expand Down
2 changes: 2 additions & 0 deletions tests/http_post.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use std::error::Error;
use wstd::http::{Client, HeaderValue, Request};

Expand Down
2 changes: 2 additions & 0 deletions tests/http_post_json.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use serde::{Deserialize, Serialize};
use std::error::Error;
use wstd::http::{Body, Client, HeaderValue, Request};
Expand Down
2 changes: 2 additions & 0 deletions tests/http_timeout.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use wstd::future::FutureExt;
use wstd::http::{Body, Client, Request};
use wstd::time::Duration;
Expand Down
2 changes: 2 additions & 0 deletions tests/sleep.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(target_env = "p2")]

use std::error::Error;
use wstd::task::sleep;
use wstd::time::Duration;
Expand Down
Loading