use std::env;
use std::path::PathBuf;
fn main() {
let mut include_paths: Vec<PathBuf> = Vec::new();
try_pkg_config(&mut include_paths);
generate_bindings(include_paths);
}
fn try_pkg_config(include_paths: &mut Vec<PathBuf>) {
let library = pkg_config::Config::new()
.atleast_version("0.31")
.probe("liblo")
.expect("Could not find system liblo via pkg-config. Please install liblo.");
include_paths.extend(library.include_paths);
}
fn generate_bindings(include_paths: Vec<PathBuf>) {
let mut builder = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg("-DHAVE_CONFIG_H=1")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.blocklist_item("IPPORT_RESERVED");
for path in include_paths {
builder = builder.clang_arg(format!("-I{}", path.display()));
}
let bindings = builder.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!");
}