From 8acb39b9e337a65ee957451ef44af04d175bad49 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 15 Jan 2021 11:02:12 +0100 Subject: [PATCH 1/3] fix Libs in testlib pc files --- src/tests/testlib-2.0.pc | 2 +- src/tests/testlib-3.0.pc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/testlib-2.0.pc b/src/tests/testlib-2.0.pc index 8b7b3a2..1ad7013 100644 --- a/src/tests/testlib-2.0.pc +++ b/src/tests/testlib-2.0.pc @@ -6,5 +6,5 @@ includedir=${prefix}/include/testlib Name: Test Library Description: A fake library to test pkg-config. Version: 2.0.0 -Libs: L${libdir} -ltest +Libs: -L${libdir} -ltest Cflags: -I${includedir} diff --git a/src/tests/testlib-3.0.pc b/src/tests/testlib-3.0.pc index 59e07f3..224b122 100644 --- a/src/tests/testlib-3.0.pc +++ b/src/tests/testlib-3.0.pc @@ -6,5 +6,5 @@ includedir=${prefix}/include/testlib Name: Test Library Description: A fake library to test pkg-config. Version: 3.0.0 -Libs: L${libdir} -ltest +Libs: -L${libdir} -ltest Cflags: -I${includedir} From e57f204a0d80449ccd438f5ba00b90acc173d756 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 15 Jan 2021 11:23:43 +0100 Subject: [PATCH 2/3] test: check that system libs are skipped as expected --- src/test.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test.rs b/src/test.rs index bd7c768..2c915ce 100644 --- a/src/test.rs +++ b/src/test.rs @@ -20,6 +20,7 @@ fn create_config(path: &str, env: Vec<(&'static str, &'static str)>) -> Config { "PKG_CONFIG_PATH", &env::current_dir().unwrap().join("src").join("tests"), ); + env::set_var("PKG_CONFIG_SYSTEM_LIBRARY_PATH", "/usr/lib64/"); } let mut hash = HashMap::new(); @@ -756,3 +757,12 @@ fn build_internal_override_name() { assert_eq!(called, true); assert!(libraries.get("test_lib").is_some()); } + +#[test] +fn system_libs() { + let config = create_config("toml-testlib64", vec![]); + let (libraries, _) = config.probe_full().unwrap(); + let testlib = libraries.get("testlib64").unwrap(); + // Link path is stripped as it's a system lib (PKG_CONFIG_SYSTEM_LIBRARY_PATH) + assert!(testlib.link_paths.is_empty()); +} From 3defd65fdc7412c01a32070a8f378e3f26c711d3 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 15 Jan 2021 11:43:30 +0100 Subject: [PATCH 3/3] add Config::preserve_system_libs() Needed for sodiumoxide, see https://github.com/sodiumoxide/sodiumoxide/pull/449 --- src/lib.rs | 16 +++++++++++++++- src/test.rs | 6 ++++++ src/tests/testlib64.pc | 10 ++++++++++ src/tests/toml-testlib64/Cargo.toml | 2 ++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/tests/testlib64.pc create mode 100644 src/tests/toml-testlib64/Cargo.toml diff --git a/src/lib.rs b/src/lib.rs index c1613a4..d5858b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -281,6 +281,7 @@ type FnBuildInternal = pub struct Config { env: EnvVariables, build_internals: HashMap>, + print_system_libs: bool, } impl Default for Config { @@ -299,6 +300,18 @@ impl Config { Self { env, build_internals: HashMap::new(), + print_system_libs: false, + } + } + + /// By default `pkg-config` strips libs flags pointing to standard system path, such as `-L/usr/lib64`. + /// Calling this function will ensure that those flags are preserved. + /// This is equivalent of setting the `PKG_CONFIG_ALLOW_SYSTEM_LIBS` environment variable when using `pkg-config` directly. + pub fn preserve_system_libs(self) -> Self { + Self { + env: self.env, + build_internals: self.build_internals, + print_system_libs: true, } } @@ -334,6 +347,7 @@ impl Config { Self { env: self.env, build_internals, + print_system_libs: self.print_system_libs, } } @@ -492,7 +506,7 @@ impl Config { } else { match pkg_config::Config::new() .atleast_version(&version) - .print_system_libs(false) + .print_system_libs(self.print_system_libs) .cargo_metadata(false) .probe(lib_name) { diff --git a/src/test.rs b/src/test.rs index 2c915ce..75eb93f 100644 --- a/src/test.rs +++ b/src/test.rs @@ -765,4 +765,10 @@ fn system_libs() { let testlib = libraries.get("testlib64").unwrap(); // Link path is stripped as it's a system lib (PKG_CONFIG_SYSTEM_LIBRARY_PATH) assert!(testlib.link_paths.is_empty()); + + // Request system libs to not be stripped + let config = create_config("toml-testlib64", vec![]).preserve_system_libs(); + let (libraries, _) = config.probe_full().unwrap(); + let testlib = libraries.get("testlib64").unwrap(); + assert_eq!(testlib.link_paths[0], Path::new("/usr/lib64")); } diff --git a/src/tests/testlib64.pc b/src/tests/testlib64.pc new file mode 100644 index 0000000..216e71c --- /dev/null +++ b/src/tests/testlib64.pc @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib64/ +includedir=${prefix}/include/testlib + +Name: Test Library +Description: A fake library to test pkg-config. +Version: 1.2.3 +Libs: -L${libdir} -ltest +Cflags: -I${includedir} \ No newline at end of file diff --git a/src/tests/toml-testlib64/Cargo.toml b/src/tests/toml-testlib64/Cargo.toml new file mode 100644 index 0000000..fb74413 --- /dev/null +++ b/src/tests/toml-testlib64/Cargo.toml @@ -0,0 +1,2 @@ +[package.metadata.system-deps] +testlib64 = "1"