EDIT: Filed https://github.com/rust-lang/cargo/issues/7887
The Cargo manual says in its manual:
Cargo allows local configuration for a particular package as well as global configuration. It looks for configuration files in the current directory and all parent directories.
This makes it extremely hard to precisely control what config Cargo is actually using if you want to run it in a hermetic way. Aside from actually running it in a container or something, you need to run it in a directory where you're certain none of the parents have a stray
.cargo directory (and simply overriding
CARGO_HOME doesn't seem to be enough).
Even if you wanted Cargo's "accumulate configs" behaviour, making it strictly a result of the directory hierarchy makes it hard to use if your project structure isn't laid out in a matching way. For example, I'm experimenting with "out of line vendor dirs", where a
.cargo/config.toml in an adjacent directory can define a vendor dir.
It seems to me that all these problems could be solved by implementing a
CARGO_CONFIG_PATH environment variable which contains an explicit path of directories to search for config files, in a specific order. (If not set, the existing behaviour holds.)
Would this be useful? Or is there some other way of achieving the same effect?