//! Build stamp: lets `llm-gateway --version` tell you when the binary was built. //! //! Without it, a stale release binary looks exactly like a fresh one, which has //! already caused a confusing "unknown argument" report. use std::time::{SystemTime, UNIX_EPOCH}; fn main() { let seconds = SystemTime::now() .duration_since(UNIX_EPOCH) .map(|elapsed| elapsed.as_secs()) .unwrap_or(0); println!( "cargo:rustc-env=LLM_GATEWAY_BUILD_TIME={}", format_utc(seconds) ); } /// `YYYY-MM-DDTHH:MM:SSZ`, without pulling a date crate into the build script. fn format_utc(seconds: u64) -> String { let days = (seconds / 86_400) as i64; let rem = seconds % 86_400; // Howard Hinnant's civil-from-days algorithm. let z = days + 719_468; let era = if z >= 0 { z } else { z - 146_096 } / 146_097; let doe = z - era * 146_097; let yoe = (doe - doe / 1460 + doe / 36_524 - doe / 146_096) / 365; let mut year = yoe + era * 400; let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); let mp = (5 * doy + 2) / 153; let day = doy - (153 * mp + 2) / 5 + 1; let month = if mp < 10 { mp + 3 } else { mp - 9 }; if month <= 2 { year += 1; } format!( "{year:04}-{month:02}-{day:02}T{:02}:{:02}:{:02}Z", rem / 3600, (rem % 3600) / 60, rem % 60 ) }