Skip to content

Commit

Permalink
allow overriding vergen in docker builds (#34036)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gautamg795 authored and Convex, Inc. committed Feb 4, 2025
1 parent 26d41ab commit 3091f84
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions crates/local_backend/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
use vergen::EmitBuilder;

fn main() -> anyhow::Result<()> {
// recompile when there's a new git hash for beacon.
EmitBuilder::builder()
// Recompile when there's a new git hash for beacon.
// This is a workaround for https://github.com/rustyhorde/vergen/issues/174
// In docker builds, we need a way to pass overrides to Vergen when there's no
// actual git repo. We'll try emitting as usual, then fall back to env vars
// that might have been set in the docker build before falling back to empty
// strings.
if EmitBuilder::builder()
.git_sha(false)
.git_commit_timestamp()
.emit()?;
.fail_on_error()
.emit()
.is_err()
{
println!("cargo:rerun-if-changed=build.rs");
println!(
"cargo:rustc-env=VERGEN_GIT_SHA={}",
option_env!("VERGEN_GIT_SHA").unwrap_or_else(|| "unknown")
);
println!(
"cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP={}",
option_env!("VERGEN_GIT_COMMIT_TIMESTAMP").unwrap_or_else(|| "unknown")
);
}
Ok(())
}

0 comments on commit 3091f84

Please sign in to comment.