From 4e64f740df798016a392fcffb7e37095581da703 Mon Sep 17 00:00:00 2001 From: Francis Nixon Date: Mon, 28 Oct 2024 17:59:00 -0400 Subject: [PATCH] build.rs: Use pkg-config to find header search paths for bindgen. --- Cargo.toml | 1 + libblkid-rs-sys/Cargo.toml | 4 ++++ libblkid-rs-sys/build.rs | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d3d8f8c..ab5a40d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ uuid = "1.0.0" [features] default = [] deprecated = [] +static = ["libblkid-rs-sys/static"] [lints.rust] warnings = { level = "deny" } diff --git a/libblkid-rs-sys/Cargo.toml b/libblkid-rs-sys/Cargo.toml index 51e5a10..97c560a 100644 --- a/libblkid-rs-sys/Cargo.toml +++ b/libblkid-rs-sys/Cargo.toml @@ -14,6 +14,7 @@ keywords = ["storage"] [build-dependencies] cc = "1.0.45" +pkg-config = "0.3.31" [build-dependencies.bindgen] default-features = false @@ -30,3 +31,6 @@ nonstandard_style = { level = "deny", priority = 4 } [lints.clippy] all = { level = "deny" } cargo = { level = "deny" , priority = 1} + +[features] +static = [] diff --git a/libblkid-rs-sys/build.rs b/libblkid-rs-sys/build.rs index b1997cc..a0fb40c 100644 --- a/libblkid-rs-sys/build.rs +++ b/libblkid-rs-sys/build.rs @@ -3,9 +3,21 @@ use bindgen::Builder; use std::{env, path::PathBuf}; fn main() { - println!("cargo:rustc-link-lib=blkid"); + let mut pkg_config = pkg_config::Config::new(); + let pkg_config = pkg_config.atleast_version("2.33.2"); + #[cfg(feature = "static")] + { + pkg_config.statik(true); + } + let libblkid = pkg_config.probe("blkid").expect("Failed to find libblkid?"); let bindings = Builder::default() + .clang_args( + libblkid + .include_paths + .iter() + .map(|include| format!("-I{}", include.display())), + ) .header("header.h") .size_t_is_usize(true) .generate()