From 8c8298ba23ede6ab509bded146b90447bd4145bc Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Sat, 8 Jun 2024 01:22:21 +0000 Subject: [PATCH] Add support for linker flags These are already detected in the pkg-config crate, but were not made available to system-deps consumers. In particular `-Wl,-rpath,/a/b/c` flags are essential to loading relocated libraries in Apple platforms. --- src/lib.rs | 37 ++++++++++++++++ src/test.rs | 76 +++++++++++++++++++++++++++++++++ src/tests/testlibwithrpath.pc | 10 +++++ src/tests/toml-rpath/Cargo.toml | 4 ++ 4 files changed, 127 insertions(+) create mode 100644 src/tests/testlibwithrpath.pc create mode 100644 src/tests/toml-rpath/Cargo.toml diff --git a/src/lib.rs b/src/lib.rs index 37479ce..b9692d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -370,6 +370,18 @@ impl Dependencies { self.aggregate_path_buf(|l| &l.include_paths) } + /// Returns a vector of [Library::linker_args] of each library, removing duplicates. + pub fn all_linker_args(&self) -> Vec<&Vec> { + let mut v = self + .libs + .values() + .flat_map(|l| &l.ld_args) + .collect::>(); + v.sort_unstable(); + v.dedup(); + v + } + /// Returns a vector of [Library::defines] of each library, removing duplicates. pub fn all_defines(&self) -> Vec<(&str, &Option)> { let mut v = self @@ -416,6 +428,12 @@ impl Dependencies { if let Some(value) = env.get(&EnvVariable::new_include(name)) { lib.include_paths = split_paths(&value); } + if let Some(value) = env.get(&EnvVariable::new_linker_args(name)) { + lib.ld_args = split_string(&value) + .into_iter() + .map(|l| l.split(',').map(|l| l.to_string()).collect()) + .collect(); + } } } @@ -448,6 +466,9 @@ impl Dependencies { lib.frameworks .iter() .for_each(|f| flags.add(BuildFlag::LibFramework(f.clone()))); + lib.ld_args + .iter() + .for_each(|f| flags.add(BuildFlag::LinkArg(f.clone()))) } // Export DEP_$CRATE_INCLUDE env variable with the headers paths, @@ -528,6 +549,7 @@ enum EnvVariable { NoPkgConfig(String), BuildInternal(Option), Link(Option), + LinkerArgs(String), } impl EnvVariable { @@ -551,6 +573,10 @@ impl EnvVariable { Self::Include(lib.to_string()) } + fn new_linker_args(lib: &str) -> Self { + Self::LinkerArgs(lib.to_string()) + } + fn new_no_pkg_config(lib: &str) -> Self { Self::NoPkgConfig(lib.to_string()) } @@ -573,6 +599,7 @@ impl EnvVariable { EnvVariable::NoPkgConfig(_) => "NO_PKG_CONFIG", EnvVariable::BuildInternal(_) => "BUILD_INTERNAL", EnvVariable::Link(_) => "LINK", + EnvVariable::LinkerArgs(_) => "LDFLAGS", } } @@ -586,6 +613,7 @@ impl EnvVariable { add_to_flags(flags, EnvVariable::new_search_native(name)); add_to_flags(flags, EnvVariable::new_search_framework(name)); add_to_flags(flags, EnvVariable::new_include(name)); + add_to_flags(flags, EnvVariable::new_linker_args(name)); add_to_flags(flags, EnvVariable::new_no_pkg_config(name)); add_to_flags(flags, EnvVariable::new_build_internal(Some(name))); add_to_flags(flags, EnvVariable::new_link(Some(name))); @@ -600,6 +628,7 @@ impl fmt::Display for EnvVariable { | EnvVariable::SearchNative(lib) | EnvVariable::SearchFramework(lib) | EnvVariable::Include(lib) + | EnvVariable::LinkerArgs(lib) | EnvVariable::NoPkgConfig(lib) | EnvVariable::BuildInternal(Some(lib)) | EnvVariable::Link(Some(lib)) => { @@ -978,6 +1007,8 @@ pub struct Library { pub framework_paths: Vec, /// directories where the compiler should look for header files pub include_paths: Vec, + /// flags that should be passed to the linker + pub ld_args: Vec>, /// macros that should be defined by the compiler pub defines: HashMap>, /// library version @@ -1034,6 +1065,7 @@ impl Library { .collect(), link_paths: l.link_paths, include_paths: l.include_paths, + ld_args: l.ld_args, frameworks: l.frameworks, framework_paths: l.framework_paths, defines: l.defines, @@ -1049,6 +1081,7 @@ impl Library { libs: Vec::new(), link_paths: Vec::new(), include_paths: Vec::new(), + ld_args: Vec::new(), frameworks: Vec::new(), framework_paths: Vec::new(), defines: HashMap::new(), @@ -1168,6 +1201,7 @@ enum BuildFlag { Lib(String, bool), // true if static LibFramework(String), RerunIfEnvChanged(EnvVariable), + LinkArg(Vec), } impl fmt::Display for BuildFlag { @@ -1185,6 +1219,9 @@ impl fmt::Display for BuildFlag { } BuildFlag::LibFramework(lib) => write!(f, "rustc-link-lib=framework={}", lib), BuildFlag::RerunIfEnvChanged(env) => write!(f, "rerun-if-env-changed={}", env), + BuildFlag::LinkArg(ld_option) => { + write!(f, "rustc-link-arg=-Wl,{}", ld_option.join(",")) + } } } } diff --git a/src/test.rs b/src/test.rs index 8e0826b..3a7720c 100644 --- a/src/test.rs +++ b/src/test.rs @@ -89,12 +89,14 @@ cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -279,6 +281,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LINK @@ -306,6 +309,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LINK @@ -334,6 +338,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TEST_LIB_LINK @@ -402,12 +407,14 @@ cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -441,12 +448,14 @@ cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -487,12 +496,14 @@ cargo:rustc-link-lib=other-test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -526,12 +537,14 @@ cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=overridden-framework cargo:include=/usr/include/testlib cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -565,12 +578,14 @@ cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/other/include cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -609,12 +624,14 @@ fn override_unset() { assert_flags( flags, r"cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -654,12 +671,14 @@ fn override_no_pkg_config() { flags, r"cargo:rustc-link-lib=custom-lib cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG @@ -1048,6 +1067,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LINK @@ -1056,6 +1076,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LINK @@ -1091,12 +1112,14 @@ fn override_static_no_pkg_config() { flags, r"cargo:rustc-link-lib=static=custom-lib cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LIB cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_NO_PKG_CONFIG @@ -1136,6 +1159,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTSTATICLIB_LINK @@ -1144,6 +1168,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LINK @@ -1177,6 +1202,7 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LINK @@ -1185,9 +1211,59 @@ cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LDFLAGS cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LINK "#, ); } + +#[test] +fn has_link_flags() { + let (libraries, flags) = toml("toml-rpath", vec![]).unwrap(); + let testlib = libraries.get_by_name("testlibwithrpath").unwrap(); + assert_eq!(testlib.version, "1.2.3"); + assert_eq!( + testlib.defines.get("BADGER").unwrap().as_deref(), + Some("yes") + ); + assert!(testlib.defines.get("AWESOME").unwrap().is_none()); + + let testdata = libraries.get_by_name("testdata").unwrap(); + assert_eq!(testdata.version, "4.5.6"); + assert!(libraries.get_by_name("testmore").is_none()); + + assert_eq!(libraries.iter().len(), 2); + + assert_flags( + flags, + r#"cargo:rustc-link-search=native=/usr/lib/ +cargo:rustc-link-search=framework=/usr/lib/ +cargo:rustc-link-lib=test +cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/ +cargo:rustc-link-lib=framework=someframework +cargo:include=/usr/include/testlib +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LDFLAGS +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_LDFLAGS +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LINK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIBWITHRPATH_LINK +cargo:rerun-if-env-changed=SYSTEM_DEPS_LINK +"#, + ); +} diff --git a/src/tests/testlibwithrpath.pc b/src/tests/testlibwithrpath.pc new file mode 100644 index 0000000..6b9957d --- /dev/null +++ b/src/tests/testlibwithrpath.pc @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib/ +includedir=${prefix}/include/testlib + +Name: Test Library with RPATH +Description: A fake library to test pkg-config. +Version: 1.2.3 +Libs: -L${libdir} -ltest -F${libdir} -framework someframework -Wl,-rpath,${libdir} +Cflags: -I${includedir} -DBADGER=yes -DAWESOME diff --git a/src/tests/toml-rpath/Cargo.toml b/src/tests/toml-rpath/Cargo.toml new file mode 100644 index 0000000..c5ae587 --- /dev/null +++ b/src/tests/toml-rpath/Cargo.toml @@ -0,0 +1,4 @@ +[package.metadata.system-deps] +testdata = "4" +testlibwithrpath = { version = "1", feature = "test-feature" } +testmore = { version = "2", feature = "another-test-feature" }