forked from jyn514/saltwater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
27 lines (26 loc) · 932 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
fn main() {
write_git_version();
}
fn write_git_version() {
let tag = git(&["describe", "--exact-match", "--tags", "HEAD"]);
let version = tag.unwrap_or_else(|| {
let commit = git(&["rev-parse", "--short=7", "HEAD"])
.expect("`git` was not successful, are you in the right directory?");
let most_recent_tag = git(&["describe", "--tags", "--abbrev=0", "HEAD"]).unwrap();
format!("{}-dev ({})", most_recent_tag, commit)
});
println!("cargo:rustc-env=RCC_GIT_REV={}", version);
println!("cargo:rerun-if-changed=.git/HEAD");
}
fn git(args: &[&str]) -> Option<String> {
use std::process::Command;
let output = Command::new("git")
.args(args)
.output()
.expect("failed to run `git`, is it installed?");
if output.status.success() {
Some(String::from_utf8(output.stdout).unwrap().trim().to_string())
} else {
None
}
}