File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -104,13 +104,30 @@ fn git_short_hash() -> std::io::Result<String> {
104104 } )
105105}
106106
107+ #[ cfg( not( feature = "nightly" ) ) ]
108+ fn git_path ( path : & str ) -> std:: io:: Result < String > {
109+ let output_result = Command :: new ( "git" )
110+ . args ( [ "rev-parse" , "--git-path" , path] )
111+ . output ( ) ;
112+
113+ output_result. map ( |output| {
114+ String :: from_utf8 ( output. stdout )
115+ . expect ( "valid UTF-8" )
116+ . trim_end_matches ( [ '\r' , '\n' ] )
117+ . to_owned ( )
118+ } )
119+ }
120+
107121fn main ( ) {
108122 // Always rerun if the build script itself changes.
109123 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
110124
111125 // re-run if the HEAD has changed. This is only necessary for non-release and nightly builds.
112126 #[ cfg( not( feature = "nightly" ) ) ]
113- println ! ( "cargo:rerun-if-changed=.git/HEAD" ) ;
127+ println ! (
128+ "cargo:rerun-if-changed={}" ,
129+ git_path( "HEAD" ) . expect( "git HEAD path detection failed" )
130+ ) ;
114131
115132 #[ cfg( feature = "protobuf-build" ) ]
116133 {
You can’t perform that action at this time.
0 commit comments