Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove macro_commons #1185

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading