Skip to content

Commit

Permalink
package: honor SOURCE_DATE_EPOCH
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bk2204 committed Nov 15, 2020
1 parent 9cc7ac6 commit 436b9eb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ fn check_repo_state(
}

fn timestamp() -> u64 {
if let Ok(var) = std::env::var("SOURCE_DATE_EPOCH") {
if let Ok(stamp) = var.parse() {
return stamp;
}
}
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
Expand Down

0 comments on commit 436b9eb

Please sign in to comment.