Skip to content

Commit

Permalink
Merge pull request #33 from coffinmatician/main
Browse files Browse the repository at this point in the history
Reproducible builds using SOURCE_DATE_EPOCH
  • Loading branch information
kornelski authored Sep 5, 2023
2 parents e9cf4fd + d794e9e commit 494f981
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fs;
use std::env;
use std::process;
use std::io::Write;
use std::str::FromStr;

fn compiler(config_dir: &Path, vendor: &Path) -> cc::Build {
let mut c = cc::Build::new();
Expand Down Expand Up @@ -80,6 +81,12 @@ fn main() {
#define JCOPYRIGHT_SHORT JCOPYRIGHT
", pkg_version = pkg_version)).expect("jversion");

let timestamp: u64 = if let Ok(epoch) = env::var("SOURCE_DATE_EPOCH") {
u64::from_str(epoch.as_str()).expect("Invalid SOURCE_DATE_EPOCH environment variable")
} else {
std::time::UNIX_EPOCH.elapsed().unwrap().as_secs()
};

let mut jconfigint_h = fs::File::create(config_dir.join("jconfigint.h")).expect("jconfint");
write!(jconfigint_h, r#"
#define BUILD "{timestamp}-mozjpeg-sys"
Expand All @@ -97,7 +104,7 @@ fn main() {
#define VERSION "{VERSION}"
#define SIZEOF_SIZE_T {SIZEOF_SIZE_T}
"#,
timestamp = std::time::UNIX_EPOCH.elapsed().unwrap().as_secs(),
timestamp = timestamp,
PACKAGE_NAME = env::var("CARGO_PKG_NAME").expect("pkg"),
VERSION = pkg_version,
SIZEOF_SIZE_T = if target_pointer_width == "32" {4} else {8}
Expand Down

0 comments on commit 494f981

Please sign in to comment.