@@ -823,19 +823,29 @@ impl Step for LibcxxVersionTool {
823
823
824
824
fn run ( self , builder : & Builder < ' _ > ) -> LibcxxVersion {
825
825
let out_dir = builder. out . join ( self . target . to_string ( ) ) . join ( "libcxx-version" ) ;
826
- let _ = fs:: remove_dir_all ( & out_dir) ;
827
- t ! ( fs:: create_dir_all( & out_dir) ) ;
826
+ let executable = out_dir. join ( exe ( "libcxx-version" , self . target ) ) ;
828
827
829
- let compiler = builder. cxx ( self . target ) . unwrap ( ) ;
830
- let mut cmd = Command :: new ( compiler) ;
828
+ // This is a sanity-check specific step, which means it is frequently called (when using
829
+ // CI LLVM), and compiling `src/tools/libcxx-version/main.cpp` at the beginning of the bootstrap
830
+ // invocation adds a fair amount of overhead to the process (see https://github.com/rust-lang/rust/issues/126423).
831
+ // Therefore, we want to avoid recompiling this file unnecessarily.
832
+ if !executable. exists ( ) {
833
+ if !out_dir. exists ( ) {
834
+ t ! ( fs:: create_dir_all( & out_dir) ) ;
835
+ }
831
836
832
- let executable = out_dir . join ( exe ( "libcxx-version" , self . target ) ) ;
833
- cmd. arg ( "-o" ) . arg ( & executable ) . arg ( builder . src . join ( "src/tools/libcxx-version/main.cpp" ) ) ;
837
+ let compiler = builder . cxx ( self . target ) . unwrap ( ) ;
838
+ let mut cmd = Command :: new ( compiler ) ;
834
839
835
- builder. run_cmd ( & mut cmd) ;
840
+ cmd. arg ( "-o" )
841
+ . arg ( & executable)
842
+ . arg ( builder. src . join ( "src/tools/libcxx-version/main.cpp" ) ) ;
836
843
837
- if !executable. exists ( ) {
838
- panic ! ( "Something went wrong. {} is not present" , executable. display( ) ) ;
844
+ builder. run_cmd ( & mut cmd) ;
845
+
846
+ if !executable. exists ( ) {
847
+ panic ! ( "Something went wrong. {} is not present" , executable. display( ) ) ;
848
+ }
839
849
}
840
850
841
851
let version_output = output ( & mut Command :: new ( executable) ) ;
0 commit comments