How can the compilation properties be determined in a procedural macro?

瘦欲@ 提交于 2020-01-03 18:56:15

问题


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:

  1. Why the macro is being executed: Build/Run, Documentation, Testing
  2. 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.

来源:https://stackoverflow.com/questions/56231963/how-can-the-compilation-properties-be-determined-in-a-procedural-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!