From 1166084360f65f1ab5f82c05f2df2203252986c4 Mon Sep 17 00:00:00 2001 From: Lin Yihai Date: Wed, 28 Aug 2024 16:04:01 +0800 Subject: [PATCH] fix: Avoid inserting `search_path` again. --- src/cargo/core/compiler/compilation.rs | 6 +++++- tests/testsuite/build.rs | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 405b17b98841..0c922bedbdba 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -323,7 +323,11 @@ impl<'gctx> Compilation<'gctx> { let dylib_path = paths::dylib_path(); let dylib_path_is_empty = dylib_path.is_empty(); - search_path.extend(dylib_path.into_iter()); + if dylib_path.starts_with(&search_path) { + search_path = dylib_path; + } else { + search_path.extend(dylib_path.into_iter()); + } if cfg!(target_os = "macos") && dylib_path_is_empty { // These are the defaults when DYLD_FALLBACK_LIBRARY_PATH isn't // set or set to an empty string. Since Cargo is explicitly setting diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 98e52cfcbbde..5585ded3f194 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -2190,8 +2190,8 @@ fn issue_14194_deduplicate_library_path_env_var() { .env("LEVEL", 2.to_string()) .with_stdout_data(str![[r#" [ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib -[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib -[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib +[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib +[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib "#]]) .with_stderr_data(str![[r#" @@ -2212,8 +2212,8 @@ fn issue_14194_deduplicate_library_path_env_var() { .env("LEVEL", 2.to_string()) .with_stdout_data(str![[r#" [ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib -[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib -[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib +[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib +[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib "#]]) .with_stderr_data(str![[r#"