fn main() {
    println!("cargo:rerun-if-env-changed=METACRATE_RUST_COMMIT");
    let commit = std::env::var("METACRATE_RUST_COMMIT")
        .ok()
        .filter(|value| valid_commit(value))
        .unwrap_or_else(|| "unavailable".to_owned());
    println!("cargo:rustc-env=METACRATE_RUST_COMMIT={commit}");
}

fn valid_commit(value: &str) -> bool {
    matches!(value.len(), 40 | 64) && value.bytes().all(|byte| byte.is_ascii_hexdigit())
}
