Skip to content

Commit

Permalink
Remove macro_commons (#1185)
Browse files Browse the repository at this point in the history
commit-id:6c362eae

---

**Stack**:
- #1186
- #1185⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do
not merge manually using the UI - doing so may have unexpected results.*
  • Loading branch information
maciektr authored Mar 14, 2024
1 parent c7290d1 commit f87f290
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
10 changes: 0 additions & 10 deletions plugins/cairo-lang-macro-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,3 @@ pub fn attribute_macro(_args: TokenStream, input: TokenStream) -> TokenStream {
};
TokenStream::from(expanded)
}

#[proc_macro]
pub fn macro_commons(_input: TokenStream) -> TokenStream {
TokenStream::from(quote! {
#[no_mangle]
pub unsafe extern "C" fn free_result(result: cairo_lang_macro_stable::StableProcMacroResult) {
cairo_lang_macro::ProcMacroResult::from_owned_stable(result);
}
})
}
15 changes: 15 additions & 0 deletions plugins/cairo-lang-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ use std::num::NonZeroU8;
use std::slice;
use std::vec::IntoIter;

/// Free the memory allocated for the [`StableProcMacroResult`].
///
/// This function needs to be accessible through the FFI interface,
/// of the dynamic library re-exporting it.
/// The name of this function will not be mangled by the Rust compiler (through the `no_mangle` attribute).
/// This means that the name will not be extended with neither additional prefixes nor suffixes
/// by the Rust compiler and the corresponding symbol will be available by the name of the function as id.
///
/// # Safety
#[no_mangle]
#[doc(hidden)]
pub unsafe extern "C" fn free_result(result: StableProcMacroResult) {
ProcMacroResult::from_owned_stable(result);
}

#[derive(Debug)]
pub enum ProcMacroResult {
/// Plugin has not taken any action.
Expand Down
20 changes: 5 additions & 15 deletions scarb/tests/build_cairo_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ fn simple_project_with_code(t: &impl PathChild, code: impl ToString) {

fn simple_project(t: &impl PathChild) {
let code = indoc! {r#"
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons};
macro_commons!();
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro};
#[attribute_macro]
pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult {
Expand Down Expand Up @@ -268,9 +266,7 @@ fn can_emit_plugin_warning() {
simple_project_with_code(
&t,
indoc! {r#"
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons, Diagnostic};
macro_commons!();
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, Diagnostic};
#[attribute_macro]
pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult {
Expand Down Expand Up @@ -317,10 +313,8 @@ fn can_emit_plugin_error() {
simple_project_with_code(
&t,
indoc! {r#"
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons, Diagnostic};
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, Diagnostic};
macro_commons!();
#[attribute_macro]
pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult {
let _code = token_stream.to_string();
Expand Down Expand Up @@ -366,9 +360,7 @@ fn can_remove_original_node() {
simple_project_with_code(
&t,
indoc! {r#"
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons};
macro_commons!();
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro};
#[attribute_macro]
pub fn some_macro(_: TokenStream) -> ProcMacroResult {
Expand Down Expand Up @@ -415,9 +407,7 @@ fn can_replace_original_node() {
simple_project_with_code(
&t,
indoc! {r##"
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons};
macro_commons!();
use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro};
#[attribute_macro]
pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult {
Expand Down

0 comments on commit f87f290

Please sign in to comment.