Skip to content

Commit 3091f84

Browse files
gautamg795Convex, Inc.
authored andcommitted
allow overriding vergen in docker builds (#34036)
Vergen has somewhat annoying behavior in that when _not_ running in a git repo, it sets all git-generated env vars to VERGEN_IDEMPOTENT_VALUE to prevent compile-time panics in apps that use `env!` So the only way to get around that is to insist that it fails when a git repo can't be found, catch the error, and then manually set the values such that they'll be correct if present in the docker build environment, otherwise they'll fall back to "unknown". GitOrigin-RevId: d2b5967e0be039d808f9440c744f25e05fd00509
1 parent 26d41ab commit 3091f84

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

crates/local_backend/build.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
use vergen::EmitBuilder;
22

33
fn main() -> anyhow::Result<()> {
4-
// recompile when there's a new git hash for beacon.
5-
EmitBuilder::builder()
4+
// Recompile when there's a new git hash for beacon.
5+
// This is a workaround for https://github.com/rustyhorde/vergen/issues/174
6+
// In docker builds, we need a way to pass overrides to Vergen when there's no
7+
// actual git repo. We'll try emitting as usual, then fall back to env vars
8+
// that might have been set in the docker build before falling back to empty
9+
// strings.
10+
if EmitBuilder::builder()
611
.git_sha(false)
712
.git_commit_timestamp()
8-
.emit()?;
13+
.fail_on_error()
14+
.emit()
15+
.is_err()
16+
{
17+
println!("cargo:rerun-if-changed=build.rs");
18+
println!(
19+
"cargo:rustc-env=VERGEN_GIT_SHA={}",
20+
option_env!("VERGEN_GIT_SHA").unwrap_or_else(|| "unknown")
21+
);
22+
println!(
23+
"cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP={}",
24+
option_env!("VERGEN_GIT_COMMIT_TIMESTAMP").unwrap_or_else(|| "unknown")
25+
);
26+
}
927
Ok(())
1028
}

0 commit comments

Comments
 (0)