-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
39 lines (33 loc) · 1.46 KB
/
Copy pathbuild.rs
File metadata and controls
39 lines (33 loc) · 1.46 KB
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
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
//
// Emit git-sha + build-date as compile-time env vars so the binary can show
// them in `verisimiser --version` and `verisimiser version --json`.
// Closes #56 (V-L3-J1). No build-dep — uses the `git` CLI and `chrono` is
// available at runtime via the main dependency tree.
use std::process::Command;
fn main() {
let sha = Command::new("git")
.args(["rev-parse", "--short=12", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
let describe = Command::new("git")
.args(["describe", "--tags", "--always", "--dirty"])
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
let build_date = chrono::Utc::now().format("%Y-%m-%d").to_string();
println!("cargo:rustc-env=VERISIMISER_GIT_SHA={}", sha);
println!("cargo:rustc-env=VERISIMISER_GIT_DESCRIBE={}", describe);
println!("cargo:rustc-env=VERISIMISER_BUILD_DATE={}", build_date);
// Re-run when HEAD moves or git ref changes.
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/refs");
}