build.rs 757 B

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