Files
smart-rgb/crates/borders-core/build.rs
2025-10-12 22:12:23 -05:00

29 lines
1.3 KiB
Rust

use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
// Get the workspace root (two levels up from borders-core)
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let workspace_root = manifest_dir.parent().unwrap().parent().unwrap();
// Read git commit from .source-commit file
let source_commit_path = workspace_root.join(".source-commit");
let git_commit = if source_commit_path.exists() {
fs::read_to_string(&source_commit_path).unwrap_or_else(|_| "unknown".to_string()).trim().to_string()
} else {
// Fallback to git command if file doesn't exist (local development)
std::process::Command::new("git").args(["rev-parse", "HEAD"]).current_dir(workspace_root).output().ok().and_then(|output| if output.status.success() { String::from_utf8(output.stdout).ok() } else { None }).map(|s| s.trim().to_string()).unwrap_or_else(|| "unknown".to_string())
};
// Get current build time in UTC
let build_time = chrono::Utc::now().to_rfc3339();
// Set environment variables for compile-time access
println!("cargo:rustc-env=BUILD_GIT_COMMIT={}", git_commit);
println!("cargo:rustc-env=BUILD_TIME={}", build_time);
// Re-run if .source-commit changes
println!("cargo:rerun-if-changed={}", source_commit_path.display());
}