Description
Describe the problem you are trying to solve
The cargo command line API has some -Z
flags that allow to opt-in to unstable functionality. Examples are -Z build-std
, which recompiles the sysroot for custom targets, or -Z features=build_dep
, which fixes the long-standing problem tracked by #5730.
The problem with these flags is that they need to be explicitly passed to every invocation of cargo, which has many downsides:
- It makes the build/check command much more cumbersome to type.
- Your project might not build if you forget to pass the flags (e.g. with
-Z build-std
).- This means that you need to adjust all
cargo
invocations in CI scripts etc. - Users of your (nightly) crate need to use the adjusted build command too.
- Tools like
rust-analyzer
also need to be adjusted to pass the required flag.
- This means that you need to adjust all
- The changed build command is not recorded in the git history. So if you check out an old commit at some point, you need to manually remember which build command was used at that time.
As a result of these downsides, many people refrain from using unstable command line features for their (nightly) projects. This means that the features are less tested by the community before they are stabilized at some point.
Describe the solution you'd like
To solve these problems, I think there should be a way to enable cargo command line flags from a configuration file. One possibility for this could be to introduce a new build.cargoflags
key in .cargo/config
files, similar to the existing build.rustflags
and build.rustdocsflags
keys. This would be a relatively simple change that solves all the mentioned problems.
Notes
Given that it's already possible to enable unstable features of the rustc
command line API through build.rustflags
, there is already a precedent for enabling unstable command line features from .cargo/config
files.