Skip to content

Commit

Permalink
build.rs: Add support for finding header paths with pkg-config
Browse files Browse the repository at this point in the history
This can help in cross-compilation scenarios as well as large
complex builds.
  • Loading branch information
Francis Nixon committed Dec 12, 2024
1 parent 6f05e2c commit b217b08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions devicemapper-rs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ default-features = false
features = ["runtime"]
version = "0.69.0"

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

[lints.rust]
warnings = { level = "deny" }
future_incompatible = { level = "deny", priority = 1 }
Expand Down
16 changes: 16 additions & 0 deletions devicemapper-rs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@
use std::{env::var, path::PathBuf};

use bindgen::Builder;
use pkg_config::{Config, Library};

fn libdevmapper_probe() -> Library {
match Config::new().atleast_version("1.02.151").probe("devmapper") {
Ok(library) => library,
Err(e) => panic!("Suitable version of libdevmapper not found: {}", e),
}
}

fn main() {
let libdevmapper = libdevmapper_probe();
// Generate bindings for dm-ioctl.h and libdevmapper.h
// dm-ioctl.h is part of linux-headers/libc and has no pkg-config
let bindings = Builder::default()
.header("dm.h")
.clang_args(
libdevmapper
.include_paths
.iter()
.map(|include| format!("-I{}", include.display())),
)
.allowlist_var("DM.*")
.allowlist_type("__u16")
.allowlist_type("dm_ioctl")
Expand Down

0 comments on commit b217b08

Please sign in to comment.