I'm working on a procedural macro that does a lot of work that can slow down compilation considerably. The work done does not effect the semantics of the function; that is, if given the same set of arguments, the returned value is does not change depending on whether the macro is applied.
In an effort to make the edit-comp-test loop quicker, I would like to make the macro a no-op depending on conditions that relate to how the crate is being compiled. I would like to be able to determine two properties in particular:
- Why the macro is being executed: Build/Run, Documentation, Testing
- Whether the macro being executed for optimized builds.
Cargo exposes the optimization level to build scripts (through environment variables OPT_LEVEL
and PROFILE
) but does not expose the mode (Build, Documentation, ..). However, none of this information seems to be exposed to procedural macros at all.
rustc-env=VAR=VALUE
or withrustc-cfg=FEATURE
. See the documentation on build scripts for more details. – Moneyer