-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cargo should not prepend $HOME/.cargo/bin
to PATH
for subcommands when it's already in PATH
, to avoid unnecessary recompilations
#7431
Comments
I've been doing some digging, and I can't actually find where this is added. From what I can tell, nothing in Cargo sets Lines 206 to 210 in 65c8266
which does search Instead, I wonder if what's going on is that something in the call hierarchy is invoking export PATH="$HOME/.cargo/bin:$PATH" or source "$HOME/.cargo/env" which in turn contains #!/bin/sh
# rustup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
*:"$HOME/.cargo/bin":*)
;;
*)
# Prepending path in case a system-installed rustc needs to be overridden
export PATH="$HOME/.cargo/bin:$PATH"
;;
esac And that's what ends up adding to |
Hmm, no, that doesn't seem right. Even when commenting out all those, and using a subcommand to print the env implemented purely in Rust, I still see |
Aha! Rustup is the culprit, not Cargo: |
See also rust-lang/rustup#2922 and rust-lang/rustup#2848. |
The current logic forces nested invocations to execute `cargo` and friends from `$CARGO_HOME/bin`. This makes rustup break in environments where the appropriate rustup proxies to use happen to be installed elsewhere (earlier on `$PATH`), and using the binaries in `$CARGO_HOME/bin` would not work correctly. It also ensures that Rustup won't change `$PATH` "just for the heck of it", which _should_ help reduce unnecessary re-compilations when downstream build logic notices that `$PATH` changes (since it will no longer). Helps with rust-lang#2848. Fixes rust-lang/cargo#7431.
Filed a fix for this in rust-lang/rustup#2978. |
Closed as rustup patch was released in 1.25.0. Thank you all involving in this issue. |
The current logic forces nested invocations to execute `cargo` and friends from `$CARGO_HOME/bin`. This makes rustup break in environments where the appropriate rustup proxies to use happen to be installed elsewhere (earlier on `$PATH`), and using the binaries in `$CARGO_HOME/bin` would not work correctly. It also ensures that Rustup won't change `$PATH` "just for the heck of it", which _should_ help reduce unnecessary re-compilations when downstream build logic notices that `$PATH` changes (since it will no longer). Helps with rust-lang#2848. Fixes rust-lang/cargo#7431.
cargo
is prepending$HOME/.cargo/bin
/%HOME%\.cargo\bin
toPATH
, even ifPATH
already contains this dir.Cargo should only prepend it if it's not already in
PATH
!Currently this behavior causes unnecessarily recompilations when any dependency uses
rerun-if-env-changed=PATH
, such aslibsqlite3-sys
.(I have to wait several minutes every time when switching between
cargo check
in my editor and havingcargo watch -x run
running in cmd.exe, because cargo passes an unnecessarily modified PATH to cargo-watch, even though my PATH already contains%HOME%\.cargo\bin
.)The text was updated successfully, but these errors were encountered: