Skip to content

Commit ddd7b29

Browse files
committed
Address PR comments
Signed-off-by: Brian Hardock <[email protected]>
1 parent 4142f96 commit ddd7b29

File tree

19 files changed

+274
-150
lines changed

19 files changed

+274
-150
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ 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-
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" }
28+
spin-wasip3-http = { version = "5.0.0", path = "crates/spin-wasip3-http", optional = true }
29+
spin-wasip3-http-macro = { version = "5.0.0", path = "crates/spin-wasip3-http-macro", optional = true }
3030
thiserror = { workspace = true }
3131
uuid = { version = "1.18.0", optional = true }
3232
wit-bindgen = { workspace = true }
@@ -44,6 +44,7 @@ default = ["export-sdk-language", "json", "postgres4-types"]
4444
export-sdk-language = []
4545
json = ["dep:serde", "dep:serde_json"]
4646
postgres4-types = ["dep:rust_decimal", "dep:uuid", "dep:postgres_range", "json"]
47+
wasip3-unstable = ["dep:spin-wasip3-http", "dep:spin-wasip3-http-macro"]
4748

4849
[workspace]
4950
resolver = "2"
@@ -112,4 +113,3 @@ once_cell = "1.18.0"
112113
thiserror = "2.0.17"
113114
# Pin to the last version that targeted WASI 0.2.0
114115
wasi = "=0.13.1"
115-
wasip3 = "0.2.0"

crates/spin-wasip3-http-macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository.workspace = true
88
rust-version.workspace = true
99
homepage.workspace = true
1010
description = """
11-
Rust procedural macros for Spin and associated WIT files
11+
Rust procedural macros for Spin and WASIp3
1212
"""
1313

1414
[lib]

crates/spin-wasip3-http-macro/src/lib.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
use proc_macro::TokenStream;
22
use quote::quote;
33

4-
/// TODO
4+
/// Marks an `async fn` as an HTTP component entrypoint for Spin.
5+
///
6+
/// The `#[http_component]` attribute designates an asynchronous function as the
7+
/// handler for incoming HTTP requests in a Spin component using the WASI Preview 3
8+
/// (`wasip3`) HTTP ABI.
9+
///
10+
/// When applied, this macro generates the necessary boilerplate to export the
11+
/// function to the Spin runtime as a valid HTTP handler. The function must be
12+
/// declared `async` and take a single argument implementing
13+
/// [`FromRequest`](::spin_sdk::http_wasip3::FromRequest), typically
14+
/// [`Request`](::spin_sdk::http_wasip3::Request), and must return a type that
15+
/// implements [`IntoResponse`](::spin_sdk::http_wasip3::IntoResponse).
16+
///
17+
/// # Requirements
18+
///
19+
/// - The annotated function **must** be `async`.
20+
/// - The function’s parameter type must implement [`FromRequest`].
21+
/// - The return type must implement [`IntoResponse`].
22+
///
23+
/// If the function is not asynchronous, the macro emits a compile-time error.
24+
///
25+
/// # Generated Code
26+
///
27+
/// The macro expands into a module containing a `Spin` struct that implements the
28+
/// WASI `http.handler/Guest` interface, wiring the annotated function as the
29+
/// handler’s entrypoint. This allows the function to be invoked automatically
30+
/// by the Spin runtime when HTTP requests are received.
531
#[proc_macro_attribute]
632
pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream {
733
let func = syn::parse_macro_input!(item as syn::ItemFn);
@@ -27,7 +53,7 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream {
2753

2854
impl ::spin_sdk::http_wasip3::wasip3::exports::http::handler::Guest for self::Spin {
2955
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)?;
56+
let request = <::spin_sdk::http_wasip3::Request as ::spin_sdk::http_wasip3::FromRequest>::from_request(request)?;
3157
::spin_sdk::http_wasip3::IntoResponse::into_response(super::#func_name(request).await)
3258
}
3359
}

crates/spin-wasip3-http/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ bytes = { workspace = true }
1414
http-body = { workspace = true }
1515
http-body-util = { workspace = true }
1616
hyperium = { workspace = true }
17-
wasip3-http-ext = { version = "5.0.0", path = "../wasip3-http-ext" }
18-
wasip3 = { workspace = true }
17+
wasip3-http-ext = { version = "5.0.0", path = "../wasip3-http-ext" }

0 commit comments

Comments
 (0)