Skip to content

Commit ca010ae

Browse files
committed
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 <[email protected]>
1 parent 273f070 commit ca010ae

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/krun-sys/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "krun-sys"
3-
version = "1.9.1"
3+
version = "1.10.1"
44
edition = "2021"
55
rust-version = "1.77.0"
66
description = "Rust bindings for libkrun"
@@ -10,6 +10,7 @@ links = "krun"
1010

1111
[build-dependencies]
1212
bindgen = { version = "0.69.4", default-features = false }
13+
pkg-config = { version = "0.3", default-features = false }
1314

1415
[features]
1516
default = []

crates/krun-sys/build.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
use std::env;
22
use std::path::PathBuf;
33

4-
fn main() {
4+
fn main() -> Result<(), pkg_config::Error> {
55
println!("cargo::rerun-if-changed=wrapper.h");
6-
println!("cargo::rustc-link-lib=krun");
6+
7+
let library = pkg_config::probe_library("libkrun")?;
78

89
let bindings = bindgen::Builder::default()
9-
.header("wrapper.h")
10+
.clang_args(
11+
library
12+
.include_paths
13+
.iter()
14+
.map(|path| format!("-I{}", path.to_string_lossy())),
15+
)
1016
.clang_arg("-fretain-comments-from-system-headers")
17+
.header("wrapper.h")
1118
.generate()
1219
.expect("Unable to generate bindings");
1320

1421
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
1522
bindings
1623
.write_to_file(out_path.join("bindings.rs"))
1724
.expect("Couldn't write bindings!");
25+
26+
Ok(())
1827
}

0 commit comments

Comments
 (0)