From 38131ae31fc59c39c3d366af956553faf734fade Mon Sep 17 00:00:00 2001 From: corigan01 Date: Fri, 31 Jan 2025 11:11:53 -0600 Subject: [PATCH] Portal: When macros generate enums and have zero arguments, dont generate members for those enums --- crates/portal-macro/src/type_serde.rs | 27 +++++++++++++++------------ meta/src/main.rs | 2 +- portals/hello-portal/src/lib.rs | 4 ++++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/portal-macro/src/type_serde.rs b/crates/portal-macro/src/type_serde.rs index 6786f5a4..b5ea2bba 100644 --- a/crates/portal-macro/src/type_serde.rs +++ b/crates/portal-macro/src/type_serde.rs @@ -151,18 +151,11 @@ pub fn generate_ast_portal(portal: &PortalMacroInput) -> TokenStream2 { quote! { #portal_vis mod #portal_module_name { + #consts #defined_types #enums - #trait_tokens - #consts - /// Client side communication over this portal - pub mod client { - } - - /// Server side communication over this portal - pub mod server { - } + #trait_tokens } } } @@ -207,8 +200,14 @@ fn endpoints_enum_input(endpoint: &PortalEndpoint, input_enum_ident: &Ident) -> syn::FnArg::Receiver(receiver) => Ident::new("not_supported_self", receiver.span()), }); - quote! { - #input_enum_ident::#endpoint_enum_front( #(#input_argument_names),* ) + if endpoint.input.is_empty() { + quote! { + #input_enum_ident::#endpoint_enum_front + } + } else { + quote! { + #input_enum_ident::#endpoint_enum_front( #(#input_argument_names),* ) + } } } @@ -395,7 +394,11 @@ fn generate_endpoint_enums( metadata: &PortalMetadata, ) -> TokenStream2 { let all_input_types = metadata.input_types.iter().map(|(ident, arguments)| { - quote_spanned! {ident.span()=> #ident(#(#arguments),*) } + if arguments.is_empty() { + quote_spanned! {ident.span()=> #ident } + } else { + quote_spanned! {ident.span()=> #ident(#(#arguments),*) } + } }); let all_output_types = metadata.output_type.iter().map(|(ident, argument)| { diff --git a/meta/src/main.rs b/meta/src/main.rs index d643f8a9..2fa110d9 100644 --- a/meta/src/main.rs +++ b/meta/src/main.rs @@ -48,7 +48,7 @@ async fn build( tokio::join!(build_project(multiboot_mode, emit_asm), DiskImgBaker::new()) }; - let artifacts = artifacts.expect("Failed to build artifacts!"); + let artifacts = artifacts?; let mut disk = disk?; disk.write_bootsector(&artifacts.bootsector).await?; diff --git a/portals/hello-portal/src/lib.rs b/portals/hello-portal/src/lib.rs index 2e3669b5..d1d3d0b8 100644 --- a/portals/hello-portal/src/lib.rs +++ b/portals/hello-portal/src/lib.rs @@ -32,6 +32,10 @@ pub trait HelloPortal { #[event = 1] fn ping_hello_server() -> bool {} + /// Test 2 #[event = 2] fn get_hello() -> u32 {} + + #[event = 3] + fn something_hello() {} }