66//! When compiling the `lightwalletd` gRPC tests, also builds a gRPC client
77//! Rust API for `lightwalletd`.
88
9+ use std:: process:: Command ;
910use vergen:: EmitBuilder ;
1011
1112/// Returns a new `vergen` builder, configured for everything except for `git` env vars.
@@ -18,6 +19,18 @@ fn base_vergen_builder() -> EmitBuilder {
1819 vergen
1920}
2021
22+ /// Run a git command and return the output, or a fallback value if it fails
23+ fn run_git_command ( args : & [ & str ] , fallback : & str ) -> String {
24+ Command :: new ( "git" )
25+ . args ( args)
26+ . output ( )
27+ . ok ( )
28+ . and_then ( |o| String :: from_utf8 ( o. stdout ) . ok ( ) )
29+ . map ( |s| s. trim ( ) . to_string ( ) )
30+ . filter ( |s| !s. is_empty ( ) )
31+ . unwrap_or_else ( || fallback. to_owned ( ) )
32+ }
33+
2134/// Process entry point for `zebrad`'s build script
2235#[ allow( clippy:: print_stderr) ]
2336fn main ( ) {
@@ -52,4 +65,11 @@ fn main() {
5265 & [ "tests/common/lightwalletd/proto" ] ,
5366 )
5467 . expect ( "Failed to generate lightwalletd gRPC files" ) ;
68+
69+ // Add custom git tag and commit information
70+ let git_tag = run_git_command ( & [ "describe" , "--exact-match" , "--tags" ] , "none" ) ; // Will be set to 'none' if .git is missing or git fails.
71+ let git_commit = run_git_command ( & [ "rev-parse" , "HEAD" ] , "none" ) ; // Will be set to 'none' if .git is missing or git fails.
72+
73+ println ! ( "cargo:rustc-env=GIT_TAG={}" , git_tag) ;
74+ println ! ( "cargo:rustc-env=GIT_COMMIT_FULL={}" , git_commit) ;
5575}
0 commit comments