Skip to content

Commit f8262b5

Browse files
bmwiedemannMitMaro
andauthored
Add SOURCE_DATE_EPOCH to build
Add an optional SOURCE_DATE_EPOCH environment variable, to make the builds reproducible. Co-authored-by: Tim Oram <[email protected]> Co-authored-by: Bernhard M. Wiedemann <[email protected]>
1 parent 033c6c8 commit f8262b5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,16 @@ An addition to the report printed to the CLI, an HTML report can be found in the
256256

257257
### Release
258258

259-
##### Building
259+
#### Debian Building
260260

261261
cargo make deb
262262

263263
A deb file will be written to `target/debian/interactive-rebase-tool_*.deb`.
264264

265+
#### Reproducible Builds
266+
267+
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.
268+
265269
## Related Projects
266270

267271
* [rebase-editor](https://github.com/sjurba/rebase-editor) is a very similar project written in Node.js.

src/core/build.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::process;
1+
use std::{env, process};
22

3-
use chrono::Utc;
3+
use chrono::{TimeZone, Utc};
44
use rustc_version::{version_meta, Channel};
55

66
fn main() {
@@ -16,7 +16,13 @@ fn main() {
1616
if let Some(rev) = git_revision_hash() {
1717
println!("cargo:rustc-env=GIRT_BUILD_GIT_HASH={rev}");
1818
}
19-
println!("cargo:rustc-env=GIRT_BUILD_DATE={}", Utc::now().format("%Y-%m-%d"));
19+
20+
// Use provided SOURCE_DATE_EPOCH to make builds reproducible
21+
let build_date = match env::var("SOURCE_DATE_EPOCH") {
22+
Ok(val) => Utc.timestamp_opt(val.parse::<i64>().unwrap(), 0).unwrap(),
23+
Err(_) => Utc::now(),
24+
};
25+
println!("cargo:rustc-env=GIRT_BUILD_DATE={}", build_date.format("%Y-%m-%d"));
2026
}
2127

2228
fn git_revision_hash() -> Option<String> {

0 commit comments

Comments
 (0)