mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
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.
This commit is contained in:
parent
9cc7ac618b
commit
436b9eb85d
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user