So I recently discovered this neat trick for optimizing compilation times:
[profile.dev.package."*"]
opt-level = 3
This will make all dependencies optimized to maximum, which improves incremental compile times, though it severely hampers clean compilation times.
For development, this setting is perfect, but in CI, compilation is always clean so clearly this is not a good solution.
I would like to set opt-level = 0
only for CI... but what's the best way of doing it? I could just pass a --profile ci
to each step, but I have a lot of steps in CI (clippy
, nextest
, wasm-pack
...), and some of them don't even offer that flag!
Is there some sort of environment variable I could use to set the cargo profile for all subsequent commands?
Note that I also tried to turn the issue around: set opt-level = 0
in the dev
profile, and create a new one local-dev
with opt-level = 3
but then... how can I ensure all commands locally are run using that profile? There's cargo run
, clippy
, cargo-test
, rust-analyzer
... do I have to configure each of them to use that profile?
Any solution seems so cumbersome and error-prone, I think I might be missing something here.
Set CARGO_PROFILE_dev_OPT_LEVEL=0
.
ref: https://doc.rust-lang.org/cargo/reference/environment-variables.html
CARGO_PROFILE_<name>_OPT_LEVEL
— Set the optimization level, seeprofile.<name>.opt-level
.