-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.rs
More file actions
54 lines (48 loc) · 1.99 KB
/
build.rs
File metadata and controls
54 lines (48 loc) · 1.99 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Build script — compiles the C++ RNG shim for preseq compatibility and
//! embeds git/build metadata as compile-time environment variables.
//!
//! The shim wraps `std::mt19937` and `std::binomial_distribution` so that
//! RustQC's preseq bootstrap uses the exact same random number generation
//! as upstream preseq compiled on the same platform.
//!
//! Embedded variables:
//! - `GIT_SHORT_HASH` — short commit hash (e.g. `84ec57f`), or `unknown`
//! - `BUILD_TIMESTAMP` — UTC timestamp of the build (e.g. `2026-03-07T12:34:56Z`)
use std::process::Command;
fn main() {
// --- C++ RNG shim ---
cc::Build::new()
.cpp(true)
.file("cpp/rng_shim.cpp")
.std("c++17")
.warnings(true)
.compile("rng_shim");
println!("cargo:rerun-if-changed=cpp/rng_shim.cpp");
// --- Git short hash ---
// First check the GIT_SHORT_HASH env var (set via Docker build arg),
// then fall back to running `git rev-parse` (works in local/CI builds).
let git_hash = std::env::var("GIT_SHORT_HASH")
.ok()
.filter(|s| !s.is_empty() && s != "unknown")
.unwrap_or_else(|| {
Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_else(|| "unknown".to_string())
});
println!("cargo:rustc-env=GIT_SHORT_HASH={}", git_hash);
// --- Build timestamp (UTC, ISO-8601) ---
let build_ts = Command::new("date")
.args(["-u", "+%Y-%m-%dT%H:%M:%SZ"])
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", build_ts);
// Rebuild when HEAD changes (new commits)
println!("cargo:rerun-if-changed=.git/HEAD");
}