-
Notifications
You must be signed in to change notification settings - Fork 16
Add support for WASI P3 #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fibonacci1729
wants to merge
6
commits into
main
Choose a base branch
from
wasip3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4142f96
Add support for WASI P3
fibonacci1729 ddd7b29
Address PR comments
fibonacci1729 af614bf
Delete wasip3-http-ext and use upstream wasip3 additions
fibonacci1729 bc2ba7a
Concurrent outbound HTTP P3 example
itowlson c230ba0
Merge pull request #88 from itowlson/wasip3-concurrent-outbound
itowlson 0aa0165
Rename http_component to http_service and use unstable executor
fibonacci1729 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,22 +17,24 @@ The Spin Rust SDK makes it easy to build Spin components in Rust. | |
| name = "spin_sdk" | ||
|
|
||
| [dependencies] | ||
| anyhow = "1" | ||
| anyhow = { workspace = true } | ||
| async-trait = "0.1.74" | ||
| chrono = "0.4.38" | ||
| form_urlencoded = "1.0" | ||
| postgres_range = { version = "0.11.1", optional = true } | ||
| rust_decimal = { version = "1.37.2", default-features = false, optional = true } | ||
| spin-executor = { version = "5.0.0", path = "crates/executor" } | ||
| spin-macro = { version = "5.0.0", path = "crates/macro" } | ||
| thiserror = "1.0.37" | ||
| spin-wasip3-http = { version = "5.0.0", path = "crates/spin-wasip3-http", optional = true } | ||
| spin-wasip3-http-macro = { version = "5.0.0", path = "crates/spin-wasip3-http-macro", optional = true } | ||
| thiserror = { workspace = true } | ||
| uuid = { version = "1.18.0", optional = true } | ||
| wit-bindgen = { workspace = true } | ||
| routefinder = "0.5.3" | ||
| once_cell = { workspace = true } | ||
| futures = { workspace = true } | ||
| bytes = "1" | ||
| hyperium = { package = "http", version = "1.0.0" } | ||
| bytes = { workspace = true } | ||
| hyperium = { workspace = true } | ||
| serde_json = { version = "1.0.96", optional = true } | ||
| serde = { version = "1.0.163", optional = true } | ||
| wasi = { workspace = true } | ||
|
|
@@ -42,6 +44,7 @@ default = ["export-sdk-language", "json", "postgres4-types"] | |
| export-sdk-language = [] | ||
| json = ["dep:serde", "dep:serde_json"] | ||
| postgres4-types = ["dep:rust_decimal", "dep:uuid", "dep:postgres_range", "json"] | ||
| wasip3-unstable = ["dep:spin-wasip3-http", "dep:spin-wasip3-http-macro"] | ||
|
|
||
| [workspace] | ||
| resolver = "2" | ||
|
|
@@ -65,6 +68,9 @@ members = [ | |
| "examples/variables", | ||
| "examples/wasi-http-streaming-outgoing-body", | ||
| "examples/wasi-http-streaming-file", | ||
| "examples/wasip3-http-axum-router", | ||
| "examples/wasip3-http-hello-world", | ||
| "examples/wasip3-http-send-request", | ||
| "test-cases/simple-http", | ||
| "test-cases/simple-redis", | ||
| "crates/*", | ||
|
|
@@ -92,12 +98,18 @@ authors = ["Spin Framework Maintainers <[email protected]>"] | |
| edition = "2021" | ||
| license = "Apache-2.0 WITH LLVM-exception" | ||
| repository = "https://github.com/spinframework/spin-rust-sdk" | ||
| rust-version = "1.78" | ||
| rust-version = "1.86" | ||
| homepage = "https://spinframework.dev/rust-components" | ||
|
|
||
| [workspace.dependencies] | ||
| anyhow = "1" | ||
| hyperium = { package = "http", version = "1.3.1" } | ||
| http-body = "1.0.1" | ||
| http-body-util = "0.1.3" | ||
| bytes = "1.10.1" | ||
| wit-bindgen = "0.43.0" | ||
| futures = "0.3.28" | ||
| once_cell = "1.18.0" | ||
| thiserror = "2.0.17" | ||
| # Pin to the last version that targeted WASI 0.2.0 | ||
| wasi = "=0.13.1" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| [package] | ||
| name = "spin-wasip3-http-macro" | ||
| version.workspace = true | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| rust-version.workspace = true | ||
| homepage.workspace = true | ||
| description = """ | ||
| Rust procedural macros for Spin and WASIp3 | ||
| """ | ||
|
|
||
| [lib] | ||
| name = "spin_wasip3_http_macro" | ||
| proc-macro = true | ||
|
|
||
| [dependencies] | ||
| proc-macro2 = "1" | ||
| quote = "1.0" | ||
| syn = { version = "1.0", features = [ "full" ]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use proc_macro::TokenStream; | ||
| use quote::quote; | ||
|
|
||
| /// Marks an `async fn` as an HTTP component entrypoint for Spin. | ||
| /// | ||
| /// The `#[http_service]` attribute designates an asynchronous function as the | ||
| /// handler for incoming HTTP requests in a Spin component using the WASI Preview 3 | ||
| /// (`wasip3`) HTTP ABI. | ||
| /// | ||
| /// When applied, this macro generates the necessary boilerplate to export the | ||
| /// function to the Spin runtime as a valid HTTP handler. The function must be | ||
| /// declared `async` and take a single argument implementing | ||
| /// [`FromRequest`](::spin_sdk::http_wasip3::FromRequest), typically | ||
| /// [`Request`](::spin_sdk::http_wasip3::Request), and must return a type that | ||
| /// implements [`IntoResponse`](::spin_sdk::http_wasip3::IntoResponse). | ||
| /// | ||
| /// # Requirements | ||
| /// | ||
| /// - The annotated function **must** be `async`. | ||
| /// - The function’s parameter type must implement [`FromRequest`]. | ||
| /// - The return type must implement [`IntoResponse`]. | ||
| /// | ||
| /// If the function is not asynchronous, the macro emits a compile-time error. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ```ignore | ||
| /// use spin_sdk::http_wasip3::{http_service, Request, IntoResponse}; | ||
| /// | ||
| /// #[http_service] | ||
| /// async fn my_handler(request: Request) -> impl IntoResponse { | ||
| /// // Your logic goes here | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// # Generated Code | ||
| /// | ||
| /// The macro expands into a module containing a `Spin` struct that implements the | ||
| /// WASI `http.handler/Guest` interface, wiring the annotated function as the | ||
| /// handler’s entrypoint. This allows the function to be invoked automatically | ||
| /// by the Spin runtime when HTTP requests are received. | ||
| #[proc_macro_attribute] | ||
| pub fn http_service(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||
| let func = syn::parse_macro_input!(item as syn::ItemFn); | ||
|
|
||
| if func.sig.asyncness.is_none() { | ||
| return syn::Error::new_spanned( | ||
| func.sig.fn_token, | ||
| "the `#[http_component]` function must be `async`", | ||
| ) | ||
| .to_compile_error() | ||
| .into(); | ||
| } | ||
|
|
||
| let func_name = &func.sig.ident; | ||
|
|
||
| quote!( | ||
| #func | ||
| mod __spin_wasip3_http { | ||
| use ::spin_sdk::http_wasip3::IntoResponse; | ||
|
|
||
| struct Spin; | ||
| ::spin_sdk::http_wasip3::wasip3::http::proxy::export!(Spin); | ||
|
|
||
| impl ::spin_sdk::http_wasip3::wasip3::exports::http::handler::Guest for self::Spin { | ||
| 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> { | ||
| let request = <::spin_sdk::http_wasip3::Request as ::spin_sdk::http_wasip3::FromRequest>::from_request(request)?; | ||
| ::spin_sdk::http_wasip3::IntoResponse::into_response(super::#func_name(request).await) | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| .into() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [package] | ||
| name = "spin-wasip3-http" | ||
| version.workspace = true | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| rust-version.workspace = true | ||
| homepage.workspace = true | ||
|
|
||
| [dependencies] | ||
| anyhow = { workspace = true } | ||
| bytes = { workspace = true } | ||
| http-body = { workspace = true } | ||
| http-body-util = { workspace = true } | ||
| hyperium = { workspace = true } | ||
| wasip3 = { version = "0.2.1", features = ["http-compat"] } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.