Description
Problem
The [env] configuration section
(#9539) does not currently impact subcommand invocations. It's not entirely clear whether this is a bug or by design. My instinct is that it's the former, since otherwise setting, say, PATH
in ~/.cargo/config.toml
won't affect which subcommands are available, but it could also be argued that it should be up to subcommands whether they want to pick up the current configuration (e.g., they may to reload the config rooted somewhere else, which would mean not picking up [env]
from ./.cargo/config.toml
).
If this is a bug, it should be fixed.
If it's by design, the documentation should be updated to make it clear that these environment variables do not affect subcommands.
Steps
echo '#!/bin/bash' > ~/.cargo/bin/cargo-issue-10094
echo 'env' >> ~/.cargo/bin/cargo-issue-10094
chmod +x ~/.cargo/bin/cargo-issue-10094
rm -rf cargo-issue-10094-repro
cargo new cargo-issue-10094-repro
pushd cargo-issue-10094-repro
mkdir .cargo
echo '[env]' > .cargo/config.toml
echo 'CARGO_ISSUE_10094 = "1"' >> .cargo/config.toml
env=$(cargo issue-10094)
popd
rm -r cargo-issue-10094-repro
rm ~/.cargo/bin/cargo-issue-10094
# Notice that this produces no output
echo "$env" | grep CARGO_ISSUE_10094
Possible Solution(s)
The code here
Lines 171 to 174 in ad50d0d
needs to pick up environment variables from the config in the same way as is done for compilation invocations in
cargo/src/cargo/core/compiler/compilation.rs
Lines 348 to 358 in ad50d0d
Or, if the decision is to update the documentation instead, this paragraph should be updated
cargo/src/doc/src/reference/config.md
Lines 485 to 486 in ad50d0d
Notes
No response
Version
cargo 1.56.0 (4ed5d137b 2021-10-04)
release: 1.56.0
commit-hash: 4ed5d137baff5eccf1bae5a7b2ae4b57efad4a7d
commit-date: 2021-10-04