nixide/nix-bindings-store-sys/build.rs
John Ericson dbb00333b1 Split monolithic raw crates into sys crates
Creating a crate for bwd-gc highlights the fact that it would be nice to
fix 2!

The file blocklist is a lost less unmaintainable then the more
fine-grained one we had before.

Fix #9
2026-01-12 19:48:45 -05:00

40 lines
1.1 KiB
Rust

use std::path::PathBuf;
#[derive(Debug)]
struct StripNixPrefix;
impl bindgen::callbacks::ParseCallbacks for StripNixPrefix {
fn item_name(&self, name: &str) -> Option<String> {
name.strip_prefix("nix_").map(String::from)
}
}
fn main() {
println!("cargo:rerun-if-changed=include/nix-c-store.h");
println!("cargo:rustc-link-lib=nixstorec");
let mut args = Vec::new();
for path in pkg_config::probe_library("nix-store-c")
.unwrap()
.include_paths
.iter()
{
args.push(format!("-I{}", path.to_str().unwrap()));
}
let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let bindings = bindgen::Builder::default()
.header("include/nix-c-store.h")
.clang_args(args)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.parse_callbacks(Box::new(StripNixPrefix))
// Blocklist symbols from nix-bindings-util-sys
.blocklist_file(".*nix_api_util\\.h")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}