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
This commit is contained in:
John Ericson 2025-12-06 15:44:20 -05:00
parent 485070ffa9
commit dbb00333b1
51 changed files with 571 additions and 104 deletions

View file

@ -0,0 +1,42 @@
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-expr.h");
println!("cargo:rustc-link-lib=nixexprc");
let mut args = Vec::new();
for path in pkg_config::probe_library("nix-expr-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-expr.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")
// Blocklist symbols from nix-bindings-store-sys
.blocklist_file(".*nix_api_store\\.h")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}