use std::env; use std::fs; use std::path::Path; fn main() { let hadron_version = env!("CARGO_PKG_VERSION"); let git_branch = duct::cmd!("git", "rev-parse", "--abbrev-ref", "HEAD") .read() .unwrap_or("".to_string()); let git_sha_abbrev = duct::cmd!("git", "log", "-1", "--format=%h").read().unwrap_or("".to_string()); let git_sha = duct::cmd!("git", "log", "-1", "--format=%H") .read() .unwrap_or("".to_string()); let vars_file = format!( "\ pub const fn hadron_version() -> &'static str {{ \"{}\" }} pub const fn hadron_git_branch() -> &'static str {{ \"{}\" }} pub const fn hadron_git_sha_abbrev() -> &'static str {{ \"{}\" }} pub const fn hadron_git_sha() -> &'static str {{ \"{}\" }} ", hadron_version, git_branch, git_sha_abbrev, git_sha ); let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("hadron_vars.rs"); fs::write(dest_path, vars_file).unwrap(); }