use std::env; use std::process::Command; fn main() { // Set build timestamp println!( "cargo:rustc-env=RUSTYTORCH_BUILD_TIMESTAMP={}", chrono::Utc::now().format("%Y-%m-%d %H:%M:%S UTC") ); // Get git commit hash let git_commit = Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .output() .ok() .and_then(|output| { if output.status.success() { String::from_utf8(output.stdout).ok() } else { None } }) .map_or_else(|| "unknown".to_string(), |s| s.trim().to_string()); println!("cargo:rustc-env=RUSTYTORCH_GIT_COMMIT={git_commit}"); // Get Rust version let rustc_version = env::var("RUSTC_VERSION").unwrap_or_else(|_| { Command::new(env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string())) .arg("--version") .output() .ok() .and_then(|output| { if output.status.success() { String::from_utf8(output.stdout).ok() } else { None } }) .map_or_else(|| "unknown".to_string(), |s| s.trim().to_string()) }); println!("cargo:rustc-env=RUSTYTORCH_RUST_VERSION={rustc_version}"); // Get target architecture let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_else(|_| "unknown".to_string()); println!("cargo:rustc-env=RUSTYTORCH_TARGET_ARCH={target_arch}"); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=.git/HEAD"); }