diff --git a/libyang2-sys/Cargo.toml b/libyang2-sys/Cargo.toml index 7353f56..45598a6 100644 --- a/libyang2-sys/Cargo.toml +++ b/libyang2-sys/Cargo.toml @@ -15,6 +15,7 @@ categories = ["external-ffi-bindings"] bindgen = { version = "0.68.0", optional = true } cc = { version = "1.0", features = ["parallel"], optional = true } cmake = { version = "0.1", optional = true } +pkg-config = "0.3.27" [features] # Use pre-generated FFI bindings diff --git a/libyang2-sys/build.rs b/libyang2-sys/build.rs index 4468b05..0775105 100644 --- a/libyang2-sys/build.rs +++ b/libyang2-sys/build.rs @@ -130,8 +130,18 @@ fn main() { build.compile("yang2"); println!("cargo:root={}", env::var("OUT_DIR").unwrap()); - println!("cargo:rustc-link-lib=pcre2-8"); + if let Err(e) = pkg_config::Config::new().probe("libpcre2-8") { + println!("cargo:warning=failed to find pcre2 library with pkg-config: {}", e); + println!("cargo:warning=attempting to link without pkg-config"); + println!("cargo:rustc-link-lib=pcre2-8"); + } } #[cfg(not(feature = "bundled"))] - println!("cargo:rustc-link-lib=yang"); + { + if let Err(e) = pkg_config::Config::new().probe("libyang") { + println!("cargo:warning=failed to find yang library with pkg-config: {}", e); + println!("cargo:warning=attempting to link without pkg-config"); + println!("cargo:rustc-link-lib=yang"); + } + } }