Apply a procedural macro to all the compiled code

Is there a way to apply a procedural macro to all the compiled code of a crate?

Adding a #![my_proc_macro] to all the source code files would do what I want, but I’m looking for a more automatic way. For example, a “rustc --preprocess-with my_proc_macro program.rs” flag, or a way to run a procedural macro from rustc_driver::Callbacks.

Macros at the crate root level are not currently supported and are hard to implement for reasons described in https://github.com/rust-lang/rust/issues/54726 (some form of eager expansion is required).

The workaround is to make an inner module and apply the macro to it.

I see, thanks!