-
Notifications
You must be signed in to change notification settings - Fork 892
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
Deduplicate PATH entries added during build (e.g. ~/.cargo/bin
)
#2848
Comments
I believe the approach which would work here would be in: https://github.com/rust-lang/rustup/blob/master/src/env_var.rs#L24-L37 We should, for each value in the new values we want to prepend, if they exist in the old values, remove them first from there. This would be fairly easy to do by means of a If someone wants to give this a go, I'm happy to mentor/help. |
~/.cargo/bin
)
I would like to send PR |
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.
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.
Problem
When running
cargo build
(orcargo check
,cargo clippy
), the$PATH
env var contains~/.cargo/bin
twice. My$PATH
contains it once (by sourcing~/.cargo/env
as per standard rustup install)This addition to
$PATH
is mostly harmless, except when:cargo:rerun-if-env-changed=PATH
cargo build
and using something likerust-analyzer
The problem being:
rust-analyzer
is building and writes the "non-duplicated" $PATH into the fingerprinting filecargo build
or similar, cargo adds the duplicated entry and the fingerprinter detects that$PATH
changes and triggers a rebuildIn short, the different $PATH causes lots of additional rebuilds (in some cases)
One example of this being pyo3:
PyO3/pyo3#1708
..which does have to re-run if $PATH changes, because a different Python interpreter might be added via a virtualenv
Steps (simpler)
Smallest reproduction case I can think of is:
(Noting the
[build.rs:2] env!("PATH")
contains/home/dbr/.cargo/bin
twice, whereasecho $PATH
is "correct")If I bypass rustup (..I think..) by setting $PATH to only include a specific toolchain, the duplication doesn't occur:
Steps (real world)
Larger repro is to:
pyo3 = "*"
as a dependencyrust-analyzer
and make some trivial changes..and note the lines similar to:
Possible Solution(s)
🤷
Notes
Output of
rustup --version
:Output of
rustup show
:The text was updated successfully, but these errors were encountered: