-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo subcommands do not pick up [env] #10094
Comments
A couple of notes from today's Cargo meeting:
We should definitely fix this, but in doing so, we should address corner cases like those. Personally, I would propose that setting PATH should work, setting CARGO_HOME should not (to avoid dealing with recursion), setting configuration environment variables should not (since people can just as easily set those elsewhere in the same |
I agree on all points. For those last two, I would actually suggest that those should never work, not just for subcommands, and that those cases should error out in the code that reads the environment variables from the config in the first place. |
@jonhoo Right, those were meant to be things that should always be true about |
Picking up the discussion from #10780 here. My implementation: master...lovesegfault:cargo:fix-10094 Regarding the questions posed by @joshtriplett:
One remaining question is what should the default behavior be, we have two options:
In my current PR, I took the route of (2). Changing it to (1) is trivial, all I need is to flip this value. Which option should we take? |
There's also the smaller question of what the option for retaining the old behavior should be named. And arguably, if we're willing to make a breaking change (so option 1), whether there even should be an option for retaining the current behavior. I happen to have a specific use-case where I explicitly want the current behavior, so would strongly prefer the option to be included regardless of whether we change the default or not. As for naming, I like
|
Another note for later: we'll want to make sure that |
We had a pretty lengthy discussion about this issue today, but unfortunately didn't come to a direct conclusion. One thing we would like to see is an overview of alternatives so that we can consider the merits of setting the environment for external subcommands versus other solutions. One concern is that if the environment was set, external subcommands would then begin behaving differently than cargo itself. Cargo doesn't read the An alternative is to make it easier for external subcommands to access cargo's config. If that were easier, then external subcommands can decide if they want the Another idea is to somehow make this an opt-in behavior for external subcommands. Perhaps others could share some comments if there are other considerations or ideas? |
Because of a bug(?) in cargo preventing subcommands like publish from reading env variables set by the build script there isn't an effective way currently to communicate the location of generated source files to pass to include!() This is potentially related to rust-lang/cargo#10094
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
Possible Solution(s)
The code here
cargo/src/bin/cargo/main.rs
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
The text was updated successfully, but these errors were encountered: