From 54a7a5069c9f91d2c8911084d2b11d164a7e25e9 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Thu, 24 Oct 2024 09:32:18 +0200 Subject: [PATCH] Allow to override build date with SOURCE_DATE_EPOCH to make builds reproducible. See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable. Also use UTC to be independent of timezone. --- tui/build.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tui/build.rs b/tui/build.rs index 121931c1..bcaf5e2e 100644 --- a/tui/build.rs +++ b/tui/build.rs @@ -1,7 +1,14 @@ +use chrono::{TimeZone, Utc}; +use std::env; + fn main() { // Add current date as a variable to be displayed in the 'Linux Toolbox' text. + let now = match env::var("SOURCE_DATE_EPOCH") { + Ok(val) => { Utc.timestamp_opt(val.parse::().unwrap(), 0).unwrap() } + Err(_) => Utc::now(), + }; println!( "cargo:rustc-env=BUILD_DATE={}", - chrono::Local::now().format("%Y-%m-%d") + now.format("%Y-%m-%d") ); }