-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbuild.rs
More file actions
30 lines (28 loc) · 813 Bytes
/
build.rs
File metadata and controls
30 lines (28 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::error::Error;
use vergen_gitcl::{Emitter, GitclBuilder};
fn main() -> Result<(), Box<dyn Error>> {
// Try to get the git sha from the local git repository
match GitclBuilder::all_git() {
Ok(gitcl) => match Emitter::default().fail_on_error().add_instructions(&gitcl) {
Ok(emitter) => {
if emitter.emit().is_err() {
fallback_git_sha();
}
}
Err(_) => {
fallback_git_sha();
}
},
Err(_) => {
fallback_git_sha();
}
};
Ok(())
}
fn fallback_git_sha() {
// Unable to get the git sha
if let Ok(sha) = std::env::var("GIT_SHA") {
// Set it from an env var
println!("cargo:rustc-env=VERGEN_GIT_SHA={sha}");
}
}