Skip to content

Commit 490b41f

Browse files
committed
Add support for WASI P3
Signed-off-by: Brian Hardock <[email protected]>
1 parent c1cfa4f commit 490b41f

File tree

21 files changed

+1603
-78
lines changed

21 files changed

+1603
-78
lines changed

Cargo.lock

Lines changed: 380 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@ The Spin Rust SDK makes it easy to build Spin components in Rust.
1717
name = "spin_sdk"
1818

1919
[dependencies]
20-
anyhow = "1"
20+
anyhow = { workspace = true }
2121
async-trait = "0.1.74"
2222
chrono = "0.4.38"
2323
form_urlencoded = "1.0"
2424
postgres_range = { version = "0.11.1", optional = true }
2525
rust_decimal = { version = "1.37.2", default-features = false, optional = true }
2626
spin-executor = { version = "5.0.0", path = "crates/executor" }
2727
spin-macro = { version = "5.0.0", path = "crates/macro" }
28-
thiserror = "1.0.37"
28+
spin-wasip3-http = { version = "5.0.0", path = "crates/spin-wasip3-http" }
29+
spin-wasip3-http-macro = { version = "5.0.0", path = "crates/spin-wasip3-http-macro" }
30+
thiserror = { workspace = true }
2931
uuid = { version = "1.18.0", optional = true }
3032
wit-bindgen = { workspace = true }
3133
routefinder = "0.5.3"
3234
once_cell = { workspace = true }
3335
futures = { workspace = true }
34-
bytes = "1"
35-
hyperium = { package = "http", version = "1.0.0" }
36+
bytes = { workspace = true }
37+
hyperium = { workspace = true }
3638
serde_json = { version = "1.0.96", optional = true }
3739
serde = { version = "1.0.163", optional = true }
3840
wasi = { workspace = true }
@@ -65,6 +67,9 @@ members = [
6567
"examples/variables",
6668
"examples/wasi-http-streaming-outgoing-body",
6769
"examples/wasi-http-streaming-file",
70+
"examples/wasip3-http-axum-router",
71+
"examples/wasip3-http-hello-world",
72+
"examples/wasip3-http-send-request",
6873
"test-cases/simple-http",
6974
"test-cases/simple-redis",
7075
"crates/*",
@@ -92,12 +97,19 @@ authors = ["Spin Framework Maintainers <[email protected]>"]
9297
edition = "2021"
9398
license = "Apache-2.0 WITH LLVM-exception"
9499
repository = "https://github.com/spinframework/spin-rust-sdk"
95-
rust-version = "1.78"
100+
rust-version = "1.87"
96101
homepage = "https://spinframework.dev/rust-components"
97102

98103
[workspace.dependencies]
104+
anyhow = "1"
105+
hyperium = { package = "http", version = "1.3.1" }
106+
http-body = "1.0.1"
107+
http-body-util = "0.1.3"
108+
bytes = "1.10.1"
99109
wit-bindgen = "0.43.0"
100110
futures = "0.3.28"
101111
once_cell = "1.18.0"
112+
thiserror = "2.0.17"
102113
# Pin to the last version that targeted WASI 0.2.0
103114
wasi = "=0.13.1"
115+
wasip3 = "0.2.0"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "spin-wasip3-http-macro"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
rust-version.workspace = true
9+
homepage.workspace = true
10+
description = """
11+
Rust procedural macros for Spin and associated WIT files
12+
"""
13+
14+
[lib]
15+
name = "spin_wasip3_http_macro"
16+
proc-macro = true
17+
18+
[dependencies]
19+
proc-macro2 = "1"
20+
quote = "1.0"
21+
syn = { version = "1.0", features = [ "full" ]}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use proc_macro::TokenStream;
2+
use quote::quote;
3+
4+
/// TODO
5+
#[proc_macro_attribute]
6+
pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream {
7+
let func = syn::parse_macro_input!(item as syn::ItemFn);
8+
9+
if func.sig.asyncness.is_none() {
10+
return syn::Error::new_spanned(
11+
func.sig.fn_token,
12+
"the `#[http_component]` function must be `async`",
13+
)
14+
.to_compile_error()
15+
.into();
16+
}
17+
18+
let func_name = &func.sig.ident;
19+
20+
quote!(
21+
#func
22+
mod __spin_wasip3_http {
23+
use ::spin_sdk::http_wasip3::IntoResponse;
24+
25+
struct Spin;
26+
::spin_sdk::http_wasip3::wasip3::http::proxy::export!(Spin);
27+
28+
impl ::spin_sdk::http_wasip3::wasip3::exports::http::handler::Guest for self::Spin {
29+
async fn handle(request: ::spin_sdk::http_wasip3::wasip3::http::types::Request) -> Result<::spin_sdk::http_wasip3::wasip3::http::types::Response, ::spin_sdk::http_wasip3::wasip3::http::types::ErrorCode> {
30+
let request = <::spin_sdk::http_wasip3::IncomingRequest as ::spin_sdk::http_wasip3::FromRequest>::from_request(request)?;
31+
::spin_sdk::http_wasip3::IntoResponse::into_response(super::#func_name(request).await)
32+
}
33+
}
34+
}
35+
)
36+
.into()
37+
}

crates/spin-wasip3-http/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "spin-wasip3-http"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
rust-version.workspace = true
9+
homepage.workspace = true
10+
11+
[dependencies]
12+
anyhow = { workspace = true }
13+
bytes = { workspace = true }
14+
http-body = { workspace = true }
15+
http-body-util = { workspace = true }
16+
hyperium = { workspace = true }
17+
wasip3-http-ext = { version = "5.0.0", path = "../wasip3-http-ext" }
18+
wasip3 = { workspace = true }

0 commit comments

Comments
 (0)