Skip to content

Commit

Permalink
fix: make our #[sdk::main] macro more feature rich
Browse files Browse the repository at this point in the history
This change takes other attrs into account, instead of throwing it away
  • Loading branch information
shekohex committed Nov 6, 2024
1 parent 69020b9 commit 585415a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ cargo-generate = { version = "0.21.3", default-features = false }
cfg-if = "1.0.0"
clap = "4.5.16"
clap-cargo = "0.14"
eyre = { version = "0.6.12" }
color-eyre = { version = "0.6", features = ["tracing-error", "color-spantrace"] }
ed25519-zebra = { version = "4" }
elliptic-curve = { version = "0.13.8" }
Expand Down
11 changes: 8 additions & 3 deletions macros/blueprint-proc-macro/src/sdk_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,24 @@ pub(crate) fn sdk_main_impl(args: &SdkMainArgs, input: &ItemFn) -> syn::Result<T

// Next, we need to consider the input. It should be in the form "async fn main() { ... }"
// We must remove all the async fn main() and keep everything else
let main_ret = match &input.sig.output {
syn::ReturnType::Default => quote! { Result<(), Box<dyn std::error::Error>> },
syn::ReturnType::Type(_, ty) => quote! { #ty },
};
let input_attrs = input.attrs.iter();
let input = input.block.clone();

let tokens = quote! {
use gadget_sdk::tokio;
#[tokio::main #tokio_args]
#[gadget_sdk::tokio::main #tokio_args]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
#logger
#standard_setup
inner_main(#env_passed_var).await?;
Ok(())
}

async fn inner_main(#env_function_signature) -> Result<(), Box<dyn std::error::Error>> {
#(#input_attrs)*
async fn inner_main(#env_function_signature) -> #main_ret {
#input
}
};
Expand Down

0 comments on commit 585415a

Please sign in to comment.