Skip to content

Commit 7b9b345

Browse files
committed
fix: add fallback for vergen-gitcl values
1 parent 34f9cd2 commit 7b9b345

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

core/build.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,34 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
88
.commit_date(true) // outputs 'VERGEN_GIT_COMMIT_DATE'
99
.build()?;
1010

11+
if let Err(why) = Emitter::default()
12+
.fail_on_error()
13+
.add_instructions(&gitcl)
14+
.and_then(|emitter| emitter.emit())
15+
{
16+
// if we are running into an error here, the git repo is most likely missing
17+
// in that case we are probably a dependency and want to emit default values
18+
println!("cargo:warning=emitting vergen-gitcl default values: {why}");
19+
println!("cargo:rustc-env=VERGEN_GIT_SHA=stable");
20+
println!("cargo:rustc-env=VERGEN_GIT_COMMIT_DATE=unknown");
21+
}
22+
1123
let build = BuildBuilder::default()
1224
.build_date(true) // outputs 'VERGEN_BUILD_DATE'
1325
.build()?;
1426

1527
Emitter::default()
1628
.add_instructions(&build)?
17-
.add_instructions(&gitcl)?
1829
.emit()
1930
.expect("Unable to generate the cargo keys!");
20-
let build_id = match std::env::var("SOURCE_DATE_EPOCH") {
21-
Ok(val) => val,
22-
Err(_) => rand::rng()
31+
32+
let build_id = std::env::var("SOURCE_DATE_EPOCH").unwrap_or_else(|_| {
33+
rand::rng()
2334
.sample_iter(Alphanumeric)
2435
.take(8)
2536
.map(char::from)
26-
.collect(),
27-
};
37+
.collect()
38+
});
2839

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

0 commit comments

Comments
 (0)