extern crate bindgen; use std::env; use std::path::{Path,PathBuf}; use std::process::Command; #[allow(dead_code)] fn make_debug(dir: &Path) { let status = Command::new("make").current_dir(dir).arg("debug").status(); assert!(status.unwrap().success()); println!("cargo:rustc-link-lib=static=wrend"); } #[allow(dead_code)] fn make_release(dir: &Path) { let status = Command::new("make").current_dir(dir).arg("static").status(); assert!(status.unwrap().success()); println!("cargo:rustc-link-lib=static=wren"); } fn main() { // The bindgen::Builder is the main entry point // to bindgen, and lets you build up options for // the resulting bindings. let bindings = bindgen::Builder::default() // The input header we would like to generate // bindings for. .header("wren/src/include/wren.h") // Finish the builder and generate the bindings. .whitelist_type("WrenConfiguration") .whitelist_type("WrenVM") .whitelist_type("WrenHandle") .whitelist_function("wrenInitConfiguration") .whitelist_function("wrenNewVM") .whitelist_function("wrenInterpret") .whitelist_function("wrenFreeVM") .whitelist_function("wrenMakeCallHandle") .whitelist_function("wrenEnsureSlots") .whitelist_function("wrenGetVariable") .whitelist_function("wrenSetSlotHandle") .whitelist_function("wrenReleaseHandle") .whitelist_function("wrenCall") .whitelist_function("wrenSetSlotString") .generate() // Unwrap the Result and panic on failure. .expect("Unable to generate bindings"); // Write the bindings to the $OUT_DIR/bindings.rs file. let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let manifest_path = Path::new(&manifest_dir); let wren_make_dir = manifest_path.join("wren"); let wren_lib_dir = manifest_path.join("wren/lib"); #[cfg(debug_assertions)] make_debug(&wren_make_dir); #[cfg(not(debug_assertions))] make_release(&wren_make_dir); println!("cargo:rustc-link-search=native={}", wren_lib_dir.display()); }