summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard M. Wiedemann <githubbmwprimary@lsmod.de>2023-08-01 13:46:20 +0200
committerGitHub <noreply@github.com>2023-08-01 09:16:20 -0230
commitf8262b54f6eb2a64d3317db107855dd64a4958ed (patch)
tree65e2577fe5a6c22a814e734608e5ffba9f4794b1
parent033c6c86598b8df36004d314dd850aeb0cfeb300 (diff)
Add SOURCE_DATE_EPOCH to build
Add an optional SOURCE_DATE_EPOCH environment variable, to make the builds reproducible. Co-authored-by: Tim Oram <dev@mitmaro.ca> Co-authored-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
-rw-r--r--README.md6
-rw-r--r--src/core/build.rs12
2 files changed, 14 insertions, 4 deletions
diff --git a/README.md b/README.md
index 22918a6..f860bf9 100644
--- a/README.md
+++ b/README.md
@@ -256,12 +256,16 @@ An addition to the report printed to the CLI, an HTML report can be found in the
### Release
-##### Building
+#### Debian Building
cargo make deb
A deb file will be written to `target/debian/interactive-rebase-tool_*.deb`.
+#### Reproducible Builds
+
+Providing a [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/specs/source-date-epoch/#idm55) environment variable with a valid UNIX timestamp, defined in seconds, will ensure a reproducible build.
+
## Related Projects
* [rebase-editor](https://github.com/sjurba/rebase-editor) is a very similar project written in Node.js.
diff --git a/src/core/build.rs b/src/core/build.rs
index b8b88bc..f528155 100644
--- a/src/core/build.rs
+++ b/src/core/build.rs
@@ -1,6 +1,6 @@
-use std::process;
+use std::{env, process};
-use chrono::Utc;
+use chrono::{TimeZone, Utc};
use rustc_version::{version_meta, Channel};
fn main() {
@@ -16,7 +16,13 @@ fn main() {
if let Some(rev) = git_revision_hash() {
println!("cargo:rustc-env=GIRT_BUILD_GIT_HASH={rev}");
}
- println!("cargo:rustc-env=GIRT_BUILD_DATE={}", Utc::now().format("%Y-%m-%d"));
+
+ // Use provided SOURCE_DATE_EPOCH to make builds reproducible
+ let build_date = match env::var("SOURCE_DATE_EPOCH") {
+ Ok(val) => Utc.timestamp_opt(val.parse::<i64>().unwrap(), 0).unwrap(),
+ Err(_) => Utc::now(),
+ };
+ println!("cargo:rustc-env=GIRT_BUILD_DATE={}", build_date.format("%Y-%m-%d"));
}
fn git_revision_hash() -> Option<String> {