-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
27 lines (25 loc) · 753 Bytes
/
build.rs
File metadata and controls
27 lines (25 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
let sha = std::env::var("DESLICER_GIT_SHA")
.ok()
.filter(|s| !s.trim().is_empty())
.or_else(git_short_sha)
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=DESLICER_GIT_SHA={sha}");
println!("cargo:rerun-if-env-changed=DESLICER_GIT_SHA");
println!("cargo:rerun-if-changed=.git/HEAD");
}
fn git_short_sha() -> Option<String> {
let output = std::process::Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()?;
if !output.status.success() {
return None;
}
let sha = String::from_utf8_lossy(&output.stdout).trim().to_string();
if sha.is_empty() {
None
} else {
Some(sha)
}
}