extern crate bindgen;
use std::env;
use std::path::PathBuf;
use bindgen::callbacks::{EnumVariantValue, ParseCallbacks};
#[derive(Debug)]
struct Callbacks;
impl ParseCallbacks for Callbacks {
fn enum_variant_name(&self, enum_name: Option<&str>, original_variant_name: &str, _variant_value: EnumVariantValue) -> Option<String> {
if enum_name == Some("knot_ctl_idx_t") && original_variant_name == "KNOT_CTL_IDX_FILTER" {
Some("KNOT_CTL_IDX_FILTERS".to_owned())
} else {
None
}
}
}
fn main() {
println!("cargo:rustc-link-lib=knot");
let bindings = bindgen::Builder::default()
.header("/usr/include/libknot/libknot.h")
.allowlist_type("knot_.*")
.allowlist_function("knot_.*")
.allowlist_var("(KNOT|knot)_.*")
.rustified_enum(".*_idx_t")
.raw_line("#[allow(bad_style)]")
.parse_callbacks(Box::new(Callbacks))
.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("Could not write bindings");
}