Skip to content

Commit

Permalink
build.rs: Use pkg-config to find header search paths for bindgen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Nixon committed Dec 11, 2024
1 parent 5fd360a commit 5712010
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uuid = "1.0.0"
[features]
default = []
deprecated = []
static = ["libblkid-rs-sys/static"]

[lints.rust]
warnings = { level = "deny" }
Expand Down
4 changes: 4 additions & 0 deletions libblkid-rs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ keywords = ["storage"]

[build-dependencies]
cc = "1.0.45"
pkg-config = "0.3.31"

[build-dependencies.bindgen]
default-features = false
Expand All @@ -30,3 +31,6 @@ nonstandard_style = { level = "deny", priority = 4 }
[lints.clippy]
all = { level = "deny" }
cargo = { level = "deny" , priority = 1}

[features]
static = []
14 changes: 13 additions & 1 deletion libblkid-rs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5712010

Please sign in to comment.