1 use std::env; 2 use std::path::Path; 3 use std::process::Command; 4 main()5fn main() { 6 println!("cargo:rerun-if-changed=build.rs"); 7 8 set_commit_info_for_rustc(); 9 10 println!("cargo:rustc-check-cfg=cfg(asan)"); 11 match env::var("CARGO_CFG_SANITIZE") { 12 Ok(s) if s == "address" => { 13 println!("cargo:rustc-cfg=asan"); 14 } 15 _ => {} 16 } 17 } 18 set_commit_info_for_rustc()19fn set_commit_info_for_rustc() { 20 if !Path::new(".git").exists() { 21 return; 22 } 23 let output = match Command::new("git") 24 .arg("log") 25 .arg("-1") 26 .arg("--date=short") 27 .arg("--format=%H %h %cd") 28 .arg("--abbrev=9") 29 .output() 30 { 31 Ok(output) if output.status.success() => output, 32 _ => return, 33 }; 34 let stdout = String::from_utf8(output.stdout).unwrap(); 35 let mut parts = stdout.split_whitespace(); 36 let mut next = || parts.next().unwrap(); 37 println!("cargo:rustc-env=WASMTIME_GIT_HASH={}", next()); 38 println!( 39 "cargo:rustc-env=WASMTIME_VERSION_INFO={} ({} {})", 40 env!("CARGO_PKG_VERSION"), 41 next(), 42 next() 43 ); 44 } 45