-
Notifications
You must be signed in to change notification settings - Fork 475
/
build.rs
25 lines (24 loc) · 838 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
use std::process::Command;
fn main() {
let hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.env("GIT_CONFIG_GLOBAL", "/dev/null")
.output()
.map(|o| String::from_utf8(o.stdout).unwrap());
let date = Command::new("git")
.args(["log", "--pretty=format:'%ad'", "-n1", "--date=short"])
.env("GIT_CONFIG_GLOBAL", "/dev/null")
.output()
.map(|o| String::from_utf8(o.stdout).unwrap());
if let (Ok(hash), Ok(date)) = (hash, date) {
let ver = format!(
"{} (commit {} {})",
env!("CARGO_PKG_VERSION"),
hash.trim(),
date.trim_matches('\'')
);
println!("cargo:rustc-env=VERSION={ver}");
} else {
println!("cargo:rustc-env=VERSION={}", env!("CARGO_PKG_VERSION"));
}
}