Skip to content

Commit

Permalink
Fix building for missing .git directory or Git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Jul 2, 2024
1 parent df9e9b8 commit 25d0a86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 7 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::path::Path;

fn main() {
let is_git_repo = Path::new(".git").exists();
assert!(is_git_repo, "foo");
vergen::EmitBuilder::builder()
.idempotent()
.git_describe(true, true, None)
.emit()
.unwrap();
if is_git_repo {
vergen::EmitBuilder::builder()
.idempotent()
.git_describe(true, true, None)
.emit()
.unwrap();
}
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
};

#[derive(Parser)]
#[clap(version = option_env!("VERGEN_GIT_DESCRIBE"))]
#[clap(version = version())]
struct Args {
#[clap(
help = "input files to operate on",
Expand Down Expand Up @@ -108,3 +108,7 @@ fn main() -> Result<()> {

Ok(())
}

fn version() -> &'static str {
option_env!("VERGEN_GIT_DESCRIBE").unwrap_or_else(|| env!("CARGO_PKG_VERSION"))
}

0 comments on commit 25d0a86

Please sign in to comment.