Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIlow to unset .cargo/config settings through a new reset config key #8687

Open
phil-opp opened this issue Sep 7, 2020 · 0 comments
Open
Labels
A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@phil-opp
Copy link
Contributor

phil-opp commented Sep 7, 2020

Describe the problem you are trying to solve

Cargo configuration files (.cargo/config) are very useful for setting reasonable default values for a project. Since there are sometimes special cases where these default value do not work, cargo allows overriding config settings through a lower-level .cargo/config file, the config cli feature, or environment variables.

While it is possible to override a configuration key with a different value, there is currently no way to unset a configuration key. This is problematic because for some keys the behavior of cargo already changes if the key is present, independent of the assigned value. One example is the build.target flag for specifying a default target, which configures cargo to pass a --target argument to rustc. This leads to different behavior than a build with no --target argument, e.g. the output is placed in target/target-name/debug instead of target/debug.

Another example is the unstable table, for example the unstable.build-std key. As soon as it's present, cargo tries to recompile (parts of) the standard library, which fails when no --target argument is passed. As for the build.target key, there is no way to unset the config key again as soon as it's enabled.

Another class of config keys that cannot be unset are array keys like build.rustflags. Since they are merged with previous arrays, there is no way to remove a rustflags argument set in a parent directory.

Describe the solution you'd like

Add a new reset array to cargo configuration files, which specfies a list of configuration keys that should be unset again. For example, reset = ["build"] would unset the complete [build] table of previously parsed configuration and reset = ["build.target", "unstable.build-std"] would only reset the two specific keys.

The reset key would be processed by Cargo in the configuration merge step. It would result in the removal of the specified config keys from the parsed data. As a result, lower-level config files or the config-cli feature would be able to reset specfic keys of already parsed config files back to their "not set" state. After the reset, it is still possible to set new values. This way, it would be possible to replace a build.rustflags array with a different array without any merging.

Since the reset key is a normal config value, it can not only be set from config files, but also through a --config command line argument or even through a config environment variable.

Notes

This would resolve #8112, #8638, and #6775.

I originally had this idea while writing the internals post about .cargo/config problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants