File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1+ use std:: { path:: Path , process:: Command } ;
2+
3+ fn main ( ) {
4+ println ! ( "cargo:rerun-if-changed=build.rs" ) ;
5+
6+ commit_info ( ) ;
7+ }
8+
9+ fn commit_info ( ) {
10+ if !Path :: new ( ".git" ) . exists ( ) {
11+ return ;
12+ }
13+ let output = match Command :: new ( "git" )
14+ . arg ( "log" )
15+ . arg ( "-1" )
16+ . arg ( "--date=short" )
17+ . arg ( "--format=%H %h %cd" )
18+ . arg ( "--abbrev=9" )
19+ . output ( )
20+ {
21+ Ok ( output) if output. status . success ( ) => output,
22+ _ => return ,
23+ } ;
24+ let stdout = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
25+ let mut parts = stdout. split_whitespace ( ) ;
26+ let mut next = || parts. next ( ) . unwrap ( ) ;
27+ println ! ( "cargo:rustc-env=CARGO_GIT_HASH={}" , next( ) ) ;
28+ println ! (
29+ "cargo:rustc-env=CARGO_VERSION_INFO={} ({} {})" ,
30+ env!( "CARGO_PKG_VERSION" ) ,
31+ next( ) ,
32+ next( )
33+ ) ;
34+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ macro_rules! subcommands {
1414 ) *
1515
1616 #[ derive( Parser ) ]
17- #[ clap( version) ]
17+ #[ clap( version = version ( ) ) ]
1818 #[ allow( non_camel_case_types) ]
1919 enum WasmTools {
2020 $(
@@ -72,6 +72,11 @@ fn main() -> ExitCode {
7272 ExitCode :: FAILURE
7373}
7474
75+ /// If CARGO_VERSION_INFO is set, use it, otherwise use CARGO_PKG_VERSION.
76+ fn version ( ) -> & ' static str {
77+ option_env ! ( "CARGO_VERSION_INFO" ) . unwrap_or ( env ! ( "CARGO_PKG_VERSION" ) )
78+ }
79+
7580#[ test]
7681fn verify_cli ( ) {
7782 use clap:: CommandFactory ;
You can’t perform that action at this time.
0 commit comments