build.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. extern crate bindgen;
  2. use std::env;
  3. use std::path::PathBuf;
  4. use std::process::Command;
  5. fn main() {
  6. let out_dir = env::var("OUT_DIR").expect("No out dir");
  7. println!("cargo:rustc-link-lib=murmur3");
  8. println!("cargo:rustc-link-search=native={}", &out_dir);
  9. let bindings = bindgen::Builder::default()
  10. .header("murmur3.h")
  11. .generate()
  12. .expect("Unable to generate bindings");
  13. let target_os = std::env::var_os("CARGO_CFG_TARGET_OS").expect("No target OS");
  14. if target_os == "linux" {
  15. assert!(Command::new("make")
  16. .arg("shared")
  17. .status()
  18. .expect("Building C lib failed")
  19. .success());
  20. } else if target_os == "macos" {
  21. assert!(Command::new("make")
  22. .arg("shared-mac")
  23. .status()
  24. .expect("Building C lib failed")
  25. .success());
  26. } else {
  27. panic!("Unsupported OS: {:?}", target_os);
  28. }
  29. // Write the bindings to the $OUT_DIR/bindings.rs file.
  30. let out_path = PathBuf::from(out_dir);
  31. bindings
  32. .write_to_file(out_path.join("bindings.rs"))
  33. .expect("Couldn't write bindings!");
  34. }