extern crate bindgen;
extern crate xcrun;
use std::env;
use std::path::PathBuf;
use xcrun::SDK;
static MACOS_INCLUDE_PATH: &str = "/usr/include";
fn main() {
let sdk_path = xcrun::find_sdk(SDK::macOS(None))
.and_then(|pb| pb.to_str().map(String::from))
.and_then(|p| p.strip_suffix("\n").map(String::from))
.expect("macOS SDK Required");
let xpc_path = format!("{}{}/xpc/xpc.h", sdk_path, MACOS_INCLUDE_PATH);
let bootstrap_path = format!("{}{}/bootstrap.h", sdk_path, MACOS_INCLUDE_PATH);
let bindings = bindgen::Builder::default()
.header(xpc_path)
.header(bootstrap_path)
.allowlist_function("^xpc_.*")
.allowlist_var("^_xpc_.*")
.allowlist_var("^bootstrap_port")
.allowlist_function("^mach_port.*")
.allowlist_function("^vm_allocate")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.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!");
}