// Copyright 2018-2025 the Deno authors. MIT license. fn main() { let commit_hash = git_commit_hash(); println!("cargo:rustc-env=GIT_COMMIT_HASH={}", commit_hash); println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH"); println!( "cargo:rustc-env=GIT_COMMIT_HASH_SHORT={}", &commit_hash[..7] ); } fn git_commit_hash() -> String { if let Ok(output) = std::process::Command::new("git") .arg("rev-list") .arg("-1") .arg("HEAD") .output() { if output.status.success() { std::str::from_utf8(&output.stdout[..40]) .unwrap() .to_string() } else { // When not in git repository // (e.g. when the user install by `cargo install deno`) "UNKNOWN".to_string() } } else { // When there is no git command for some reason "UNKNOWN".to_string() } }