Skip to content

Commit

Permalink
krun-sys: find libkrun using pkg-config
Browse files Browse the repository at this point in the history
This enables the use of non-system-wide installations of libkrun by
exporting the right PKG_CONFIG_PATH.

Signed-off-by: Sergio Lopez <[email protected]>
  • Loading branch information
slp committed Feb 20, 2025
1 parent 69af6da commit fc82dcd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/krun-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -10,6 +10,7 @@ links = "krun"

[build-dependencies]
bindgen = { version = "0.69.4", default-features = false }
pkg-config = { version = "0.3", default-features = false }

[features]
default = []
15 changes: 12 additions & 3 deletions crates/krun-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
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");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");

Ok(())
}

0 comments on commit fc82dcd

Please sign in to comment.