Skip to content

Commit 3dc9f05

Browse files
authored
add wstd-axum crate (#97)
* add wstd-axum, for http servers written using the axum framework * flatten unnecessary test-programs/artifacts crate into test-programs and add test for axum hello world. rather than need separate test-programs to build the bins, just build the examples. (I have no idea why I didn't do this in the first place.) * add to publish * workspace edition 2024 * wstd-axum-macro requires syn features full * workspace versioning * docs, example that doesnt use macro * add my own weather example for axum * add test for axum weather example. upgrade all tests to ureq 3 * file locking is in std if we lie about msrv policy for 7 days * clippy for new msrv
1 parent dab8e47 commit 3dc9f05

40 files changed

+842
-198
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: actions-rs/cargo@v1
3131
with:
3232
command: check
33-
args: --all --bins --examples
33+
args: --workspace --all --bins --examples
3434

3535
- name: wstd tests
3636
uses: actions-rs/cargo@v1
@@ -42,7 +42,7 @@ jobs:
4242
uses: actions-rs/cargo@v1
4343
with:
4444
command: test
45-
args: -p test-programs-artifacts -- --nocapture
45+
args: -p test-programs -- --nocapture
4646

4747

4848
check_fmt_and_docs:

Cargo.toml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,22 @@ serde_json.workspace = true
4646

4747
[workspace]
4848
members = [
49+
"axum",
50+
"axum/macro",
4951
"macro",
5052
"test-programs",
51-
"test-programs/artifacts",
5253
]
5354
resolver = "2"
5455

5556
[workspace.package]
5657
version = "0.5.6"
57-
edition = "2021"
58+
edition = "2024"
5859
license = "Apache-2.0 WITH LLVM-exception"
5960
repository = "https://github.com/bytecodealliance/wstd"
6061
keywords = ["WebAssembly", "async", "stdlib", "Components"]
6162
categories = ["wasm", "asynchronous"]
6263
# Rust-version policy: stable N-2, same as wasmtime.
63-
rust-version = "1.87"
64+
rust-version = "1.89"
6465
authors = [
6566
"Yoshua Wuyts <rust@yosh.is>",
6667
"Pat Hickey <pat@moreproductive.org>",
@@ -71,6 +72,7 @@ authors = [
7172
anyhow = "1"
7273
async-task = "4.7"
7374
async-trait = "*"
75+
axum = { version = "0.8.6", default-features = false }
7476
bytes = "1.10.1"
7577
cargo_metadata = "0.22"
7678
clap = { version = "4.5.26", features = ["derive"] }
@@ -87,15 +89,18 @@ pin-project-lite = "0.2.8"
8789
quote = "1.0"
8890
serde= "1"
8991
serde_json = "1"
92+
serde_qs = "0.15"
9093
slab = "0.4.9"
9194
syn = "2.0"
9295
test-log = { version = "0.2", features = ["trace"] }
9396
test-programs = { path = "test-programs" }
94-
test-programs-artifacts = { path = "test-programs/artifacts" }
95-
ureq = { version = "2.12.1", default-features = false }
97+
tower-service = "0.3.3"
98+
ureq = { version = "3.1", default-features = false, features = ["json"] }
9699
wasip2 = "1.0"
97-
wstd = { path = "." }
98-
wstd-macro = { path = "macro", version = "=0.5.6" }
100+
wstd = { path = ".", version = "=0.5.6" }
101+
wstd-axum = { path = "./axum", version = "=0.5.6" }
102+
wstd-axum-macro = { path = "./axum/macro", version = "=0.5.6" }
103+
wstd-macro = { path = "./macro", version = "=0.5.6" }
99104

100105
[package.metadata.docs.rs]
101106
all-features = true

axum/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "wstd-axum"
3+
description = "Support for axum as a wasi http server via wstd"
4+
version.workspace = true
5+
license.workspace = true
6+
edition.workspace = true
7+
authors.workspace = true
8+
keywords.workspace = true
9+
categories.workspace = true
10+
repository.workspace = true
11+
rust-version.workspace = true
12+
13+
[dependencies]
14+
axum.workspace = true
15+
tower-service.workspace = true
16+
wstd.workspace = true
17+
wstd-axum-macro.workspace = true
18+
19+
[dev-dependencies]
20+
anyhow.workspace = true
21+
futures-concurrency.workspace = true
22+
serde = { workspace = true, features = ["derive"] }
23+
serde_qs.workspace = true
24+
axum = { workspace = true, features = ["query", "json", "macros"] }

axum/examples/hello_world.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Run with
2+
//!
3+
//! ```sh
4+
//! cargo build -p wstd-axum --examples --target wasm32-wasip2
5+
//! wasmtime serve -Scli target/wasm32-wasip2/debug/examples/hello-world.wasm
6+
//! ```
7+
8+
use axum::{Router, response::Html, routing::get};
9+
10+
#[wstd_axum::http_server]
11+
fn main() -> Router {
12+
// build our application with a route
13+
Router::new().route("/", get(handler))
14+
}
15+
16+
async fn handler() -> Html<&'static str> {
17+
Html("<h1>Hello, World!</h1>")
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Run with
2+
//!
3+
//! ```sh
4+
//! cargo build -p wstd-axum --examples --target wasm32-wasip2
5+
//! wasmtime serve -Scli target/wasm32-wasip2/debug/examples/hello-world-nomacro.wasm
6+
//! ```
7+
8+
use axum::{Router, response::Html, routing::get};
9+
use wstd::http::{Body, Error, Request, Response};
10+
11+
#[wstd::http_server]
12+
async fn main(request: Request<Body>) -> Result<Response<Body>, Error> {
13+
let service = Router::new().route("/", get(handler));
14+
wstd_axum::serve(request, service).await
15+
}
16+
17+
async fn handler() -> Html<&'static str> {
18+
Html("<h1>Hello, World!</h1>")
19+
}

0 commit comments

Comments
 (0)