From 0d515084e116d0b7ed8b588e3e779d3ed70d0c91 Mon Sep 17 00:00:00 2001 From: maciektr Date: Thu, 21 Mar 2024 20:58:39 +0100 Subject: [PATCH] Fix: expand with actual expansion name instead of package name commit-id:2136619c --- plugins/cairo-lang-macro/src/lib.rs | 2 +- scarb/src/compiler/plugin/proc_macro/ffi.rs | 10 ++++++---- scarb/src/compiler/plugin/proc_macro/host.rs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/cairo-lang-macro/src/lib.rs b/plugins/cairo-lang-macro/src/lib.rs index b60440e60..112570475 100644 --- a/plugins/cairo-lang-macro/src/lib.rs +++ b/plugins/cairo-lang-macro/src/lib.rs @@ -101,7 +101,7 @@ pub unsafe extern "C" fn expand( None } }) - .expect("proc macro not found"); + .expect("procedural macro not found"); let result = fun(token_stream); let result: StableProcMacroResult = result.into_stable(); cairo_lang_macro_stable::StableResultWrapper { diff --git a/scarb/src/compiler/plugin/proc_macro/ffi.rs b/scarb/src/compiler/plugin/proc_macro/ffi.rs index 9da6674a4..6e1634f40 100644 --- a/scarb/src/compiler/plugin/proc_macro/ffi.rs +++ b/scarb/src/compiler/plugin/proc_macro/ffi.rs @@ -116,13 +116,15 @@ impl ProcMacroInstance { /// /// Please be aware that the memory management of values passing the FFI-barrier is tricky. /// The memory must be freed on the same side of the barrier, where the allocation was made. - pub(crate) fn generate_code(&self, token_stream: TokenStream) -> ProcMacroResult { + pub(crate) fn generate_code( + &self, + item_name: SmolStr, + token_stream: TokenStream, + ) -> ProcMacroResult { // This must be manually freed with call to from_owned_stable. let stable_token_stream = token_stream.into_stable(); // Allocate proc macro name. - let item_name = CString::new(self.package_id.name.to_string()) - .unwrap() - .into_raw(); + let item_name = CString::new(item_name.to_string()).unwrap().into_raw(); // Call FFI interface for code expansion. // Note that `stable_result` has been allocated by the dynamic library. let stable_result = (self.plugin.vtable.expand)(item_name, stable_token_stream); diff --git a/scarb/src/compiler/plugin/proc_macro/host.rs b/scarb/src/compiler/plugin/proc_macro/host.rs index dc569d084..3bc3908d5 100644 --- a/scarb/src/compiler/plugin/proc_macro/host.rs +++ b/scarb/src/compiler/plugin/proc_macro/host.rs @@ -227,7 +227,7 @@ impl MacroPlugin for ProcMacroHostPlugin { .iter() .find(|m| m.package_id() == input.package_id) .expect("procedural macro must be registered in proc macro host"); - match instance.generate_code(token_stream.clone()) { + match instance.generate_code(input.expansion.name.clone(), token_stream.clone()) { ProcMacroResult::Replace { token_stream: new_token_stream, aux_data: new_aux_data,