-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
37 lines (33 loc) · 1.2 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
use std::process::Command;
fn main() {
// LATER Multiple issues with using build.rs:
// - It can report incorrect commit - it doesn't rerun after commit
// EDIT 2023-07-23 it reruns on any change, including .git
// - Measure how much it slows down incremental rebuilds
// - Any way to only use build.rs in release builds?
// LATER consider https://docs.rs/vergen/latest/vergen/
// Ideally we'd also save --dirty status but that often means
// recompiling when non-code files in the repo changed.
let describe = Command::new("git")
.args(["describe", "--long", "--always"])
.output()
.unwrap()
.stdout;
let describe = String::from_utf8(describe).unwrap();
let describe = describe.trim_end_matches('\n');
// e.g. v0.1.0-109-g6a10529
let log = Command::new("git")
.args([
"log",
"-n",
"1",
"--pretty=format:%cd %s",
"--date=format:%Y-%m-%d %H:%M",
])
.output()
.unwrap()
.stdout;
let log = String::from_utf8(log).unwrap();
// e.g. 2021-09-09 14:17 Bigger missiles
println!("cargo:rustc-env=GIT_VERSION={describe} {log}");
}