build.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. extern crate vergen;
  2. extern crate protobuf_macros;
  3. extern crate rand;
  4. use rand::Rng;
  5. use std::env;
  6. use std::path::PathBuf;
  7. use std::fs::OpenOptions;
  8. use std::io::Write;
  9. fn main() {
  10. let out = PathBuf::from(env::var("OUT_DIR").unwrap());
  11. vergen::vergen(vergen::OutputFns::all()).unwrap();
  12. let build_id: String = rand::thread_rng()
  13. .gen_ascii_chars()
  14. .take(8)
  15. .collect();
  16. let mut version_file =
  17. OpenOptions::new()
  18. .write(true)
  19. .append(true)
  20. .open(&out.join("version.rs"))
  21. .unwrap();
  22. let build_id_fn = format!("
  23. /// Generate a random build id.
  24. pub fn build_id() -> &'static str {{
  25. \"{}\"
  26. }}
  27. ", build_id);
  28. if let Err(e) = version_file.write_all(build_id_fn.as_bytes()) {
  29. println!("{}", e);
  30. }
  31. protobuf_macros::expand("src/lib.in.rs", &out.join("lib.rs")).unwrap();
  32. println!("cargo:rerun-if-changed=src/lib.in.rs");
  33. println!("cargo:rerun-if-changed=src/connection/mod.rs");
  34. println!("cargo:rerun-if-changed=src/connection/codec.rs");
  35. println!("cargo:rerun-if-changed=src/connection/handshake.rs");
  36. }