From 18ce95773e0a82cd7a768531365c8b6b98e26166 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 16 Aug 2026 22:09:00 +0200 Subject: [PATCH] Embed exact Ghostlight build provenance --- crates/ghostlight-dungeon/build.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 crates/ghostlight-dungeon/build.rs diff --git a/crates/ghostlight-dungeon/build.rs b/crates/ghostlight-dungeon/build.rs new file mode 100644 index 0000000..ca2d5ee --- /dev/null +++ b/crates/ghostlight-dungeon/build.rs @@ -0,0 +1,29 @@ +use std::process::Command; + +fn main() { + println!("cargo:rerun-if-env-changed=GHOSTLIGHT_BUILD_COMMIT"); + println!("cargo:rerun-if-changed=../../.git/HEAD"); + let commit = std::env::var("GHOSTLIGHT_BUILD_COMMIT") + .ok() + .filter(|value| is_commit(value)) + .or_else(git_commit) + .expect("GhostlightDungeon builds require an exact 40-hex source commit"); + println!("cargo:rustc-env=GHOSTLIGHT_BUILD_COMMIT={commit}"); +} + +fn git_commit() -> Option { + let output = Command::new("git") + .args(["rev-parse", "HEAD"]) + .current_dir("../..") + .output() + .ok()?; + if !output.status.success() { + return None; + } + let value = String::from_utf8(output.stdout).ok()?.trim().to_owned(); + is_commit(&value).then_some(value) +} + +fn is_commit(value: &str) -> bool { + value.len() == 40 && value.bytes().all(|byte| byte.is_ascii_hexdigit()) +}