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

support reexporting pio_asm! #70

Open
Dirbaio opened this issue Jan 15, 2025 · 2 comments · May be fixed by #72
Open

support reexporting pio_asm! #70

Dirbaio opened this issue Jan 15, 2025 · 2 comments · May be fixed by #72

Comments

@Dirbaio
Copy link
Member

Dirbaio commented Jan 15, 2025

I'd like to reexport pio, pio-proc from embassy-rp, so the user doesn't have to depend on them directly. It's nicer because it ensures the right version is used, so it avoids version mismatch errors of doom.

However, currently pio_asm! generates code that does ::pio::whatever. This doesn't work unless pio is in scope in the end user's crate. I'm not sure if this is fixable with proc macros though? With decl macros you'd use $crate, but that doesn't seem to exist for proc macros.

@Dirbaio Dirbaio changed the title support reexporting in pio_asm! support reexporting pio_asm! Jan 15, 2025
@jannic
Copy link
Member

jannic commented Feb 8, 2025

As it is a function-like macro, this workaround (taken from https://internals.rust-lang.org/t/rfc-crate-for-proc-macro/16968) could work:

#[macro_export]
macro_rules! functionlike {
    ( $($tt:tt)* ) => {
        $crate::__proc_macros::functionlike! {
            #![crate = $crate]
            $($tt)*
        }
    }
}

Ie., define a macro_rules macro which can use $crate, and forward the expanded value of $crate to the proc macro explicitly.

https://github.com/Nullus157/stylish-rs/blob/stylish-macros-0.1.2/core/src/lib.rs#L121 is an example where this method is used.

@Dirbaio
Copy link
Member Author

Dirbaio commented Feb 8, 2025

ooh that's a clever trick. I'm going to give it a try, first step is #71

Dirbaio added a commit to Dirbaio/pio-rs that referenced this issue Feb 9, 2025
@Dirbaio Dirbaio linked a pull request Feb 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants