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".
Cargo stores the output of a build into the "target" directory. By default, this is the directory named target in the root of your workspace. To change the location, you can set the CARGO_TARGET_DIR environment variable, the build. target-dir config value, or the --target-dir command-line flag.
Placing a file named build.rs in the root of a package will cause Cargo to compile that script and execute it just before building the package. Some example use cases of build scripts are: Building a bundled C library.
By default, cargo bench uses the bench profile, which enables optimizations and disables debugging information. If you need to debug a benchmark, you can use the --profile=dev command-line option to switch to the dev profile. You can then run the debug-enabled benchmark within a debugger.
cargo build --release puts the resulting binary in target/release instead of target/debug . Compiling in debug mode is the default for development-- compilation time is shorter since the compiler doesn't do optimizations, but the code will run slower. Release mode takes longer to compile, but the code will run faster.
This is not possible as of Rust 1.47. Cargo issue #4001 tracks the possibility of supporting this in some fashion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With