#![allow(clippy::expect_used, clippy::panic)]
use std::env;
use std::path::Path;
use std::time::{SystemTime, UNIX_EPOCH};
const HARDCODED_FLOOR_SECS: u64 = 1_782_864_000;
const SECS_PER_DAY: u64 = 86_400;
fn main() {
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_BUILD_TIME_FLOOR");
let build_floor_secs = if env::var_os("CARGO_FEATURE_BUILD_TIME_FLOOR").is_some() {
let now_secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("build.rs: system clock is before the Unix epoch")
.as_secs();
let day_truncated = (now_secs / SECS_PER_DAY) * SECS_PER_DAY;
assert!(
day_truncated >= HARDCODED_FLOOR_SECS,
"roughtime build.rs: build machine clock ({day_truncated}s, day-truncated UTC) is \
before the hardcoded anti-rollback floor ({HARDCODED_FLOOR_SECS}s / 2026-07-01). \
This indicates a broken or tampered build-host clock. Refusing to compile — fix \
the build machine's clock and retry."
);
day_truncated
} else {
0
};
let out_dir = env::var_os("OUT_DIR").expect("build.rs: OUT_DIR not set by Cargo");
let dest = Path::new(&out_dir).join("build_floor.rs");
std::fs::write(
&dest,
format!("pub(crate) const BUILD_FLOOR_SECS: u64 = {build_floor_secs};\n"),
)
.expect("build.rs: failed to write build_floor.rs to OUT_DIR");
}