extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=include/bridge.h");
let llvm_config_path = Command::new("llvm-config")
.args(["--prefix"])
.output()
.expect("`llvm-config` must be in PATH")
.stdout;
let llvm_config_path =
String::from_utf8(llvm_config_path).expect("`llvm-config --prefix` output must be UTF-8");
std::env::set_var(
"LLVM_CONFIG_PATH",
format!("{}/bin/llvm-config", llvm_config_path.trim()),
);
let bindings = bindgen::Builder::default()
.header("include/bridge.h")
.allowlist_function("logz_rs_error_handler")
.allowlist_function("log_.*")
.allowlist_var("CONFIG_.*")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.use_core()
.ctypes_prefix("cty")
.layout_tests(false)
.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!");
}