//! Build script: records the git commit cumulus is built from, so //! `cumulus --version` can tell exactly which build you're running. //! //! Outside a git checkout, or without git installed, the commit is "unknown". //! (No Windows icon or manifest: a terminal program's icon only shows in //! Explorer, and a manifest changes nothing for it.) use std::path::Path; use std::process::Command; fn main() { let commit = git_commit().unwrap_or_else(|| "unknown".to_string()); println!("cargo::rustc-env=CUMULUS_COMMIT={commit}"); // Run again when the commit changes: HEAD moves on checkout, and the // branch files change on commit. Only watch files that exist, or cargo // would run this script on every build. println!("cargo::rerun-if-changed=build.rs"); for path in [".git/HEAD", ".git/refs/heads", ".git/packed-refs"] { if Path::new(path).exists() { println!("cargo::rerun-if-changed={path}"); } } } /// The short hash of the current commit, if git can tell. fn git_commit() -> Option { let output = Command::new("git").args(["rev-parse", "--short=9", "HEAD"]).output().ok()?; let hash = String::from_utf8(output.stdout).ok()?; let hash = hash.trim(); (output.status.success() && !hash.is_empty()).then(|| hash.to_string()) }