From 95aaa180a8ddf2d68a6105525b7d1ed0029cf940 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Thu, 20 Feb 2025 17:20:21 +0100 Subject: [PATCH] krun-sys: find libkrun using pkg-config This enables the use of non-system-wide installations of libkrun by exporting the right PKG_CONFIG_PATH. Signed-off-by: Sergio Lopez --- Cargo.lock | 3 ++- crates/krun-sys/Cargo.toml | 3 ++- crates/krun-sys/build.rs | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 321b2e6..cb44bcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,9 +340,10 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "krun-sys" -version = "1.9.1" +version = "1.10.1" dependencies = [ "bindgen", + "pkg-config", ] [[package]] diff --git a/crates/krun-sys/Cargo.toml b/crates/krun-sys/Cargo.toml index cfb24ca..efce3ba 100644 --- a/crates/krun-sys/Cargo.toml +++ b/crates/krun-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "krun-sys" -version = "1.9.1" +version = "1.10.1" edition = "2021" rust-version = "1.77.0" description = "Rust bindings for libkrun" @@ -10,6 +10,7 @@ links = "krun" [build-dependencies] bindgen = { version = "0.69.4", default-features = false } +pkg-config = { version = "0.3" } [features] default = [] diff --git a/crates/krun-sys/build.rs b/crates/krun-sys/build.rs index ab2d2ce..1dc6a3f 100644 --- a/crates/krun-sys/build.rs +++ b/crates/krun-sys/build.rs @@ -1,13 +1,20 @@ use std::env; use std::path::PathBuf; -fn main() { +fn main() -> Result<(), pkg_config::Error> { println!("cargo::rerun-if-changed=wrapper.h"); - println!("cargo::rustc-link-lib=krun"); + + let library = pkg_config::probe_library("libkrun")?; let bindings = bindgen::Builder::default() - .header("wrapper.h") + .clang_args( + library + .include_paths + .iter() + .map(|path| format!("-I{}", path.to_string_lossy())), + ) .clang_arg("-fretain-comments-from-system-headers") + .header("wrapper.h") .generate() .expect("Unable to generate bindings"); @@ -15,4 +22,6 @@ fn main() { bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); + + Ok(()) }