-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.rs
27 lines (24 loc) · 834 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
27
use std::{env, process::Command};
fn main() {
let version = env!("CARGO_PKG_VERSION");
if Ok("release".to_owned()) == env::var("PROFILE") {
println!("cargo:rustc-env=COTP_VERSION={version}");
} else {
// Suffix with -DEBUG
// If we can get the last commit hash, let's append that also
if let Some(last_commit) = get_last_commit() {
println!("cargo:rustc-env=COTP_VERSION={version}-DEBUG-{last_commit}");
} else {
println!("cargo:rustc-env=COTP_VERSION={version}-DEBUG");
}
}
}
fn get_last_commit() -> Option<String> {
Command::new("git")
.args(["rev-parse", "--short=12", "HEAD"])
.output()
.ok()
.filter(|e| e.status.success())
.map(|e| String::from_utf8(e.stdout))
.and_then(Result::ok)
}