Proc_macro_attribute crate relies on another crate, how to use only one crate?

It's hard to articulate the title properly, but basically I'm making a proc_macro_attribute crate which of course has proc_macros inside it, and because of it this crate cannot export anything else than proc_macros. But this crate relies on functionality that should be accessed from the client / user code, so I can't put that functionality into the proc_macro crate itself. I can create 2 crates such as crate_a and crate_a_macro where crate_a_macro depends on crate_a, but then in the code I have to include both crates, and crate_a_macros won't work without the crate_a.

How do mainstream crates solve this, do they just use 2 separate crates, one for functionality and one for macros?

You can have crate_a re-export the proc macros from crate_a_macro. This is what eg serde does.

3 Likes

I didn't know I could do that, but tried it with pub use ::crate_a_macro; in crate_a and it works as expected, and solves my issue. Thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.