This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
build.rs
54 lines (49 loc) · 1.58 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::env;
use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set a build-time `GIT_HEAD` env var which includes the commit id;
// such that we can tell which code is running.
let hash = env::var("GIT_HEAD").unwrap_or_else(|_| {
Command::new("git")
.arg("rev-parse")
.arg("--short")
.arg("HEAD")
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.unwrap_or("unknown".into())
});
let version = if let Ok(version) = env::var("RADICLE_VERSION") {
version
} else {
"pre-release".to_owned()
};
// Set a build-time `GIT_COMMIT_TIME` env var which includes the commit time.
let commit_time = env::var("GIT_COMMIT_TIME").unwrap_or_else(|_| {
Command::new("git")
.arg("log")
.arg("-1")
.arg("--pretty=%ct")
.arg("HEAD")
.output()
.ok()
.and_then(|output| {
if output.status.success() {
String::from_utf8(output.stdout).ok()
} else {
None
}
})
.unwrap_or(0.to_string())
});
println!("cargo::rustc-env=RADICLE_VERSION={version}");
println!("cargo::rustc-env=GIT_COMMIT_TIME={commit_time}");
println!("cargo::rustc-env=GIT_HEAD={hash}");
Ok(())
}