Skip to content

Commit

Permalink
Allow to override build_id with SOURCE_DATE_EPOCH
Browse files Browse the repository at this point in the history
in order to make builds reproducible.
See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.

This PR was done while working on reproducible builds for openSUSE.
  • Loading branch information
bmwiedemann committed May 20, 2022
1 parent 7efc62b commit 9de1f38
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions core/build.rs
@@ -1,17 +1,24 @@
use rand::distributions::Alphanumeric;
use rand::Rng;
use std::env;
use vergen::{generate_cargo_keys, ConstantsFlags};

fn main() {
let mut flags = ConstantsFlags::all();
flags.toggle(ConstantsFlags::REBUILD_ON_HEAD_CHANGE);
generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate the cargo keys!");

let build_id: String = rand::thread_rng()
.sample_iter(Alphanumeric)
.take(8)
.map(char::from)
.collect();
let build_id: String;
match env::var("SOURCE_DATE_EPOCH") {
Ok(val) => build_id = val,
Err(_) => {
build_id = rand::thread_rng()
.sample_iter(Alphanumeric)
.take(8)
.map(char::from)
.collect()
}
}

println!("cargo:rustc-env=LIBRESPOT_BUILD_ID={}", build_id);
}

0 comments on commit 9de1f38

Please sign in to comment.