Example of how Rust proc macros could have a shared context, so every macro crate is using the same metadata no matter in which order macros are expanded.
- ctx - Defines common context, logic for generating metadata from source code and functions to store / load metadata
- example - Binary that uses our macros
- macros - Example of macros that use shared metadata
The ctx crate analyzes the code of dependant crate example during execution of its build.rs and generates metadata into build directory. The macros crate uses ctx functionality to load metadata for the example crate during proc macro expanding stage and generates some code using loaded information.
- Execute
cargo runto run it. - Execute
cargo expand -p exampleto see how generated code.
