fix: update build script for using vergen without a git repo

A fallback mechanism has been added to build script for letting
vergen generate cargo instructions even if not run in a git
repository. In such cases, a default vergen configuration is
used along with disabled "git" feature thus not generating any
git-related environment variables.

Signed-off-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
Orhun Parmaksız 2022-01-04 19:22:01 +03:00 committed by Yujia Qiao
parent a8d3be103c
commit bb26e2cd36
1 changed files with 8 additions and 2 deletions

View File

@ -7,7 +7,13 @@ fn main() -> Result<()> {
*config.git_mut().semver_kind_mut() = SemverKind::Lightweight;
// Add a `-dirty` flag to the SEMVER output
*config.git_mut().semver_dirty_mut() = Some("-dirty");
// Generate the instructions
vergen(config)
if let Err(e) = vergen(config) {
eprintln!("error occurred while generating instructions: {:?}", e);
let mut config = Config::default();
*config.git_mut().enabled_mut() = false;
vergen(config)
} else {
Ok(())
}
}