Skip to content

Commit 9de1f38

Browse files
committed
Allow to override build_id with SOURCE_DATE_EPOCH
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.
1 parent 7efc62b commit 9de1f38

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

core/build.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
use rand::distributions::Alphanumeric;
22
use rand::Rng;
3+
use std::env;
34
use vergen::{generate_cargo_keys, ConstantsFlags};
45

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

10-
let build_id: String = rand::thread_rng()
11-
.sample_iter(Alphanumeric)
12-
.take(8)
13-
.map(char::from)
14-
.collect();
11+
let build_id: String;
12+
match env::var("SOURCE_DATE_EPOCH") {
13+
Ok(val) => build_id = val,
14+
Err(_) => {
15+
build_id = rand::thread_rng()
16+
.sample_iter(Alphanumeric)
17+
.take(8)
18+
.map(char::from)
19+
.collect()
20+
}
21+
}
1522

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

0 commit comments

Comments
 (0)