-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
34 lines (28 loc) · 975 Bytes
/
Copy pathbuild.rs
File metadata and controls
34 lines (28 loc) · 975 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
28
29
30
31
32
33
34
use std::process::Command;
fn main() {
// Get git revision
let output = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.expect("Failed to execute git command");
let git_hash = String::from_utf8(output.stdout)
.expect("Invalid UTF-8")
.trim()
.to_string();
// Check if working directory is clean
let status_output = Command::new("git")
.args(["status", "--porcelain"])
.output()
.expect("Failed to execute git status");
let is_dirty = !status_output.stdout.is_empty();
let git_revision = if is_dirty {
format!("{git_hash}-dirty")
} else {
git_hash
};
// Set the GIT_REVISION environment variable for use in the code
println!("cargo:rustc-env=GIT_REVISION={git_revision}");
// Rerun if .git directory changes
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/index");
}