build.rs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. extern crate bindgen;
  2. use std::env;
  3. use std::path::{Path,PathBuf};
  4. use std::process::Command;
  5. #[allow(dead_code)]
  6. fn make_debug(dir: &Path) {
  7. let status = Command::new("make").current_dir(dir).arg("debug").status();
  8. assert!(status.unwrap().success());
  9. println!("cargo:rustc-link-lib=static=wrend");
  10. }
  11. #[allow(dead_code)]
  12. fn make_release(dir: &Path) {
  13. let status = Command::new("make").current_dir(dir).arg("static").status();
  14. assert!(status.unwrap().success());
  15. println!("cargo:rustc-link-lib=static=wren");
  16. }
  17. fn main() {
  18. // The bindgen::Builder is the main entry point
  19. // to bindgen, and lets you build up options for
  20. // the resulting bindings.
  21. let bindings = bindgen::Builder::default()
  22. // The input header we would like to generate
  23. // bindings for.
  24. .header("wren/src/include/wren.h")
  25. // Finish the builder and generate the bindings.
  26. .whitelist_type("WrenConfiguration")
  27. .whitelist_type("WrenVM")
  28. .whitelist_type("WrenHandle")
  29. .whitelist_function("wrenInitConfiguration")
  30. .whitelist_function("wrenNewVM")
  31. .whitelist_function("wrenInterpret")
  32. .whitelist_function("wrenFreeVM")
  33. .whitelist_function("wrenMakeCallHandle")
  34. .whitelist_function("wrenEnsureSlots")
  35. .whitelist_function("wrenGetVariable")
  36. .whitelist_function("wrenSetSlotHandle")
  37. .whitelist_function("wrenReleaseHandle")
  38. .whitelist_function("wrenCall")
  39. .whitelist_function("wrenSetSlotString")
  40. .generate()
  41. // Unwrap the Result and panic on failure.
  42. .expect("Unable to generate bindings");
  43. // Write the bindings to the $OUT_DIR/bindings.rs file.
  44. let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
  45. bindings
  46. .write_to_file(out_path.join("bindings.rs"))
  47. .expect("Couldn't write bindings!");
  48. let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
  49. let manifest_path = Path::new(&manifest_dir);
  50. let wren_make_dir = manifest_path.join("wren");
  51. let wren_lib_dir = manifest_path.join("wren/lib");
  52. #[cfg(debug_assertions)]
  53. make_debug(&wren_make_dir);
  54. #[cfg(not(debug_assertions))]
  55. make_release(&wren_make_dir);
  56. println!("cargo:rustc-link-search=native={}", wren_lib_dir.display());
  57. }