[Pre-RFC] Proposal: bound Cargo's implicit upward discovery for config.toml files
Proposal: bound Cargo's implicit upward discovery
Cargo currently walks from cwd toward filesystem root when discovering .cargo/config.toml. That is useful interactively, but tools do not have a supported way to say "only discover config inside this project/build directory".
This affects tools like Pixi, generated build directories, /tmp builds, and other wrappers that can set CARGO_HOME but cannot prevent parent .cargo/config.toml from being loaded.
I propose adding one discovery-boundary primitive, exposed first as an env var because wrappers need it to propagate to nested Cargo invocations:
CARGO_DISCOVERY_CEILINGS=<path-list>
For any upward discovery starting at cwd, Cargo picks the nearest configured ancestor and searches only up to that directory, inclusive.
When used for config discovery:
- load
.cargo/config.tomlfromcwdthrough the active ceiling - do not inspect ancestors above the ceiling
- do not implicitly load
$CARGO_HOME/config.toml - still allow explicit
--config <path>andinclude
The $CARGO_HOME behavior matters: otherwise a tool still cannot describe the implicit config graph it is willing to load. Users who want home config can add it explicitly with --config "$CARGO_HOME/config.toml" or an include.
This is intended to be the config-discovery half of the same problem as workspace/package discovery ceilings. I think config discovery can be phased first, but the primitive should be designed so #7621 and #7871 do not grow separate incompatible knobs.
Related threads:
- rust-lang/cargo#9769: Cargo config search meta issue
- rust-lang/cargo#7887: Fine-grain control of config discovery
- rust-lang/cargo#7894: CARGO_CONFIG_PATH config search override PR
- rust-lang/cargo#7621: Ignore parent directory configs / stop paths
- rust-lang/cargo#8643: --ignore-local-config / isolated config mode
Discussion in the ATmosphere