-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
26 lines (22 loc) · 734 Bytes
/
build.rs
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
use std::process::Command;
fn get_git_commit_hash() -> String {
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
String::from_utf8(output.stdout).unwrap()
}
fn get_git_commit_date() -> String {
let output = Command::new("git")
.args(["show", "-s", "--format=%cd", "--date=short", "HEAD"])
.output()
.unwrap();
String::from_utf8(output.stdout).unwrap()
}
fn main() {
let commit_hash = get_git_commit_hash();
let (commit_hash, _) = commit_hash.split_at(9);
println!("cargo:rustc-env=COMMIT_HASH={}", commit_hash);
let commit_date = get_git_commit_date();
println!("cargo:rustc-env=COMMIT_DATE={}", commit_date);
}