-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
38 lines (35 loc) · 1.09 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
use std::{env, process::Command};
/// Pass git-describe through CARGO_GIT_VERSION env variable
///
/// NOTE: Cargo.toml still needs to be updated on releases
fn set_version_from_git() {
let cmd = Command::new("git")
.arg("describe")
.arg("--always")
.arg("--dirty")
.arg("--tags")
.output();
match cmd {
Ok(output) if output.status.success() => {
let version = String::from_utf8_lossy(&output.stdout);
let version = version.trim();
println!("cargo:rustc-env=CARGO_GIT_VERSION={}", version);
// rerun when git checks out another ref or any ref changes
println!("cargo:rerun-if-changed=.git/refs/");
println!("cargo:rerun-if-changed=.git/HEAD");
}
_ => {
// crates.io builds without git, so ignore here
eprintln!("git describe failed; ignoring");
}
}
}
fn main() {
// Only embed on release builds.
if env::var("PROFILE")
.map(|p| p == "release")
.unwrap_or_default()
{
set_version_from_git();
}
}