You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.0 KiB
Rust
32 lines
1.0 KiB
Rust
//! Build script for `nbd`.
|
|
//!
|
|
//! Captures the short git SHA at compile time and emits it as the
|
|
//! `GIT_SHORT_SHA` environment variable, making it available via
|
|
//! `env!("GIT_SHORT_SHA")` in the crate source.
|
|
//!
|
|
//! Falls back to `"unknown"` when git is unavailable (e.g. a clean Nix
|
|
//! sandbox build where `.git/` is not present).
|
|
|
|
fn main() {
|
|
// Capture the short git SHA at build time.
|
|
let sha = std::process::Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.ok()
|
|
.and_then(|o| {
|
|
if o.status.success() {
|
|
Some(o.stdout)
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.and_then(|b| String::from_utf8(b).ok())
|
|
.map(|s| s.trim().to_string())
|
|
.unwrap_or_else(|| "unknown".to_string());
|
|
|
|
println!("cargo:rustc-env=GIT_SHORT_SHA={sha}");
|
|
// Re-run whenever HEAD or any ref changes (new commits, branch switches).
|
|
println!("cargo:rerun-if-changed=.git/HEAD");
|
|
println!("cargo:rerun-if-changed=.git/refs");
|
|
}
|