How to access current cargo profile (build, te

2020-04-05 06:59发布

问题:

I want to write a custom build.rs script that generates some diagrams to accompany the documentation for a crate I'm working on. I want this script to run only when I run cargo doc, not the other profiles (cargo build, cargo test, ...). What would be the best way to do that?

I was hoping that cargo would pass this info to build.rs in the PROFILE env variable, but that seems to only contain "debug" or "release".

回答1:

This is not possible as of Rust 1.38. Cargo issue #4001 tracks the possibility of supporting this in some fashion.