-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http-server): Add WASI reactor support to http-server cap (#359)
- Loading branch information
Showing
23 changed files
with
702 additions
and
607 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,19 @@ | ||
[package] | ||
name = "slight-http-server-macro" | ||
version = "0.1.0" | ||
edition = { workspace = true } | ||
authors = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
|
||
[lib] | ||
proc-macro = true | ||
doctest = false | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
proc-macro2 = "1" | ||
quote = "1" | ||
syn = { version = "1", features = ["full"] } | ||
wit-bindgen-gen-rust-wasm = { git = "https://github.com/fermyon/wit-bindgen-backport" } | ||
wit-bindgen-gen-core = { git = "https://github.com/fermyon/wit-bindgen-backport" } |
This file contains 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,28 @@ | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
|
||
#[proc_macro_attribute] | ||
pub fn on_server_init(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||
// parse the item as rust Fn | ||
let func = syn::parse_macro_input!(item as syn::ItemFn); | ||
let func_name = &func.sig.ident; | ||
|
||
// generate rust code | ||
quote!( | ||
|
||
struct HttpServerExport {} | ||
|
||
impl http_server_export::HttpServerExport for HttpServerExport { | ||
fn on_server_init() -> Result<(), String> { | ||
|
||
#func | ||
|
||
match #func_name() { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e.to_string()), | ||
} | ||
} | ||
} | ||
) | ||
.into() | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.