use std::env; use std::path::PathBuf; fn main() { let libdir_path = PathBuf::from("ext") .canonicalize() .expect("cannot canonicalize ext/ path"); let obj_path = libdir_path.join("hap.o"); let lib_path = libdir_path.join("libhap.a"); println!("cargo:rustc-link-search={}", libdir_path.display()); println!("cargo:rustc-link-lib=static=hap"); println!("cargo:rustc-link-lib=snappy"); println!("cargo:rerun-if-changed=ext/hap.c"); println!("cargo:rerun-if-changed=ext/hap.h"); if !std::process::Command::new("clang") .arg("-c") .arg("-o") .arg(&obj_path) .arg(libdir_path.join("hap.c")) .output() .expect("could not spawn `clang`") .status .success() { panic!("could not compile hap.c"); } if !std::process::Command::new("ar") .arg("rcs") .arg(&lib_path) .arg(&obj_path) .output() .expect("could not spawn `ar`") .status .success() { panic!("could not create libhap.a"); } let bindings = bindgen::Builder::default() .header(libdir_path.join("hap.h").to_str().unwrap()) .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .generate() .expect("unable to generate HAP bindings"); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("hap_bindings.rs"); bindings .write_to_file(out_path) .expect("couldn't write HAP bindings"); }