Open nathaniel-daniel opened 2 months ago
Thanks for the report.
By looking at the duplicate env vars, I am guessing that this is a Windows specific issue. Cargo prepend paths to dylib search paths to ensure its own executable to be searched first. On Windows unfortunately the environment variable of dylib search pats is PATH
. And that is why.
perhaps just avoiding adding a path if the path occurs within the first 3 paths is sufficient?
Checking if PATH
contains our paths-to-prepend in the desired order is sufficient I believe.
Hmm… not really Windows specific. If a build script checks LD_LIBRARY_PATH
in rerun-if-env-changed, same thing happens on Unix.
BTW, for recursive call into cargo
, the recommended way is using std::env!("CARGO")
so that you don't need to re-resolve the rustup proxy again. Cargo set CARGO
env when building each crate.
FYI, I tried to deduplicate the path in https://github.com/rust-lang/cargo/pull/14464/commits/b7c18805e6a96ef89eeb4c1344ec4b855a683ff8, but it still recomplie.
(The commit can pass on linux platform since it hard the path output)
Problem
cargo
appears to be appending paths to thePATH
environment variable without checking if those paths are already present in it, causing unneeded rebuilds in some situations. I would expect cargo to not add to the path if it doesn't have to.Steps
This issue can be reduced to a single file.
main.rs
:fn main() { for path in std::env::split_paths(&std::env::var("PATH").unwrap()) { println!("{}", path.to_string_lossy()); }
}
C:\Users\natha\OneDrive\Desktop\cargo-path-duplicate\target\debug\deps C:\Users\natha\OneDrive\Desktop\cargo-path-duplicate\target\debug C:\Users\natha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib ...rest of PATH
C:\Users\natha\OneDrive\Desktop\cargo-path-duplicate\target\debug\deps C:\Users\natha\OneDrive\Desktop\cargo-path-duplicate\target\debug C:\Users\natha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib C:\Users\natha\OneDrive\Desktop\cargo-path-duplicate\target\debug\deps C:\Users\natha\OneDrive\Desktop\cargo-path-duplicate\target\debug C:\Users\natha\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib ...rest of PATH