Skip to content

Commit 436b9eb

Browse files
committed
package: honor SOURCE_DATE_EPOCH
For projects supporting reproducible builds, it's possible to set the timestamp used in artifacts by setting SOURCE_DATE_EPOCH to a decimal Unix timestamp. This is helpful because it allows users to produce the exact same artifact, regardless of when the project was built, and it also means that services which generate crates from source can generate a consistent crate without having store previously built artifacts. For all these reasons, let's honor the SOURCE_DATE_EPOCH environment variable if it's set and use the current timestamp if it's not.
1 parent 9cc7ac6 commit 436b9eb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ fn check_repo_state(
473473
}
474474

475475
fn timestamp() -> u64 {
476+
if let Ok(var) = std::env::var("SOURCE_DATE_EPOCH") {
477+
if let Ok(stamp) = var.parse() {
478+
return stamp;
479+
}
480+
}
476481
SystemTime::now()
477482
.duration_since(SystemTime::UNIX_EPOCH)
478483
.unwrap()

0 commit comments

Comments
 (0)