From 850ea81c6de82426ce6bfeedb370261eadbf9aa5 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 12 Apr 2022 12:32:42 -0700 Subject: [PATCH 1/3] Don't let pkg-config add system lib dirs to the search path In its default configuration, pkg-config adds system-wide library directories to the linker search path (rust-lang/pkg-config-rs#11). This causes these directories to be searched before other paths added by later crates or by `-Clink-arg` in rustflags. If a library is present in the system-wide directory and a later build step wants to specifically link against a different version of that library in another path, the linker will choose the library from the first search directory it finds. If the linker doesn't find a library in any of the specified search directories, it falls back on system-wide paths, so we don't need to print the path we found lubcurl in if it is in one of those system paths. See rust-lang/libz-sys#50 for the same fix to libz that landed a while back. --- curl-sys/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/curl-sys/build.rs b/curl-sys/build.rs index bb173dd55..985f2ad71 100644 --- a/curl-sys/build.rs +++ b/curl-sys/build.rs @@ -477,6 +477,7 @@ fn try_vcpkg() -> bool { fn try_pkg_config() -> bool { let mut cfg = pkg_config::Config::new(); + cfg.print_system_libs(false); cfg.cargo_metadata(false); let lib = match cfg.probe("libcurl") { Ok(lib) => lib, From 119c98ad95ff2e801f14f9a237c0fbb999836983 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 12 Apr 2022 12:37:28 -0700 Subject: [PATCH 2/3] Also don't pick up system libraries for metadata --- curl-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/curl-sys/build.rs b/curl-sys/build.rs index 985f2ad71..fca0250c9 100644 --- a/curl-sys/build.rs +++ b/curl-sys/build.rs @@ -499,7 +499,7 @@ fn try_pkg_config() -> bool { // Re-find the library to print cargo's metadata, then print some extra // metadata as well. - cfg.cargo_metadata(true).probe("libcurl").unwrap(); + cfg.print_system_libs(false).cargo_metadata(true).probe("libcurl").unwrap(); for path in lib.include_paths.iter() { println!("cargo:include={}", path.display()); } From 5706f027e6dba43172d5a40a146a3b8efd25f057 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 12 Apr 2022 12:39:26 -0700 Subject: [PATCH 3/3] rustfmt --- curl-sys/build.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/curl-sys/build.rs b/curl-sys/build.rs index fca0250c9..d70ad5b27 100644 --- a/curl-sys/build.rs +++ b/curl-sys/build.rs @@ -499,7 +499,10 @@ fn try_pkg_config() -> bool { // Re-find the library to print cargo's metadata, then print some extra // metadata as well. - cfg.print_system_libs(false).cargo_metadata(true).probe("libcurl").unwrap(); + cfg.print_system_libs(false) + .cargo_metadata(true) + .probe("libcurl") + .unwrap(); for path in lib.include_paths.iter() { println!("cargo:include={}", path.display()); }