diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-05-09 18:00:35 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-05-09 18:00:35 +0200 |
| commit | 8d020342f0c555c7d6f98179b8165fae246c6da6 (patch) | |
| tree | 10506f3edc06c5f91de241ea5f914f5a4796e19b /build.rs | |
| parent | cc1bf55b9996d556080c4104e211f24508b29cd8 (diff) | |
| download | pish-8d020342f0c555c7d6f98179b8165fae246c6da6.tar.gz | |
more builtin variables
Diffstat (limited to 'build.rs')
| -rw-r--r-- | build.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..95a5eae --- /dev/null +++ b/build.rs @@ -0,0 +1,41 @@ +use std::process::Command; + +fn git(args: &[&str]) -> String { + let output = Command::new("git") + .args(args) + .output() + .expect("failed to execute git"); + + if !output.status.success() { + panic!("git command failed: git {}", args.join(" ")); + } + + String::from_utf8(output.stdout) + .expect("git output not utf8") + .trim() + .to_string() +} + +fn main() { + // Re-run if HEAD changes + println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-changed=.git/refs"); + + let git_hash = git(&["rev-parse", "HEAD"]); + let git_hash_short = git(&["rev-parse", "--short", "HEAD"]); + + let git_dirty = { + let status = Command::new("git") + .args(["diff", "--quiet"]) + .status() + .expect("failed to check git dirty state"); + + if status.success() { false } else { true } + }; + + println!("cargo:rustc-env=GIT_HASH={git_hash}"); + println!("cargo:rustc-env=GIT_HASH_SHORT={git_hash_short}"); + if git_dirty { + println!("cargo:rustc-env=GIT_DIRTY=1"); + } +} |
