@@ -41,28 +41,32 @@ pub fn llvm(build: &Build, target: &str) {
4141 }
4242 }
4343
44- // If the cleaning trigger is newer than our built artifacts (or if the
45- // artifacts are missing) then we keep going, otherwise we bail out.
46- let dst = build. llvm_out ( target) ;
47- let stamp = build. src . join ( "src/rustllvm/llvm-auto-clean-trigger" ) ;
48- let mut stamp_contents = String :: new ( ) ;
49- t ! ( t!( File :: open( & stamp) ) . read_to_string( & mut stamp_contents) ) ;
50- let done_stamp = dst. join ( "llvm-finished-building" ) ;
44+ let clean_trigger = build. src . join ( "src/rustllvm/llvm-auto-clean-trigger" ) ;
45+ let mut clean_trigger_contents = String :: new ( ) ;
46+ t ! ( t!( File :: open( & clean_trigger) ) . read_to_string( & mut clean_trigger_contents) ) ;
47+
48+ let out_dir = build. llvm_out ( target) ;
49+ let done_stamp = out_dir. join ( "llvm-finished-building" ) ;
5150 if done_stamp. exists ( ) {
5251 let mut done_contents = String :: new ( ) ;
5352 t ! ( t!( File :: open( & done_stamp) ) . read_to_string( & mut done_contents) ) ;
54- if done_contents == stamp_contents {
53+
54+ // LLVM was already built previously.
55+ // We don't track changes in LLVM sources, so we need to choose between reusing
56+ // what was built previously, or cleaning the directory and doing a fresh build.
57+ // The choice depends on contents of the clean-trigger file.
58+ // If the contents are the same as during the previous build, then no action is required.
59+ // If the contents differ from the previous build, then cleaning is triggered.
60+ if done_contents == clean_trigger_contents {
5561 return
62+ } else {
63+ t ! ( fs:: remove_dir_all( & out_dir) ) ;
5664 }
5765 }
58- drop ( fs:: remove_dir_all ( & dst) ) ;
5966
6067 println ! ( "Building LLVM for {}" , target) ;
61-
6268 let _time = util:: timeit ( ) ;
63- let _ = fs:: remove_dir_all ( & dst. join ( "build" ) ) ;
64- t ! ( fs:: create_dir_all( & dst. join( "build" ) ) ) ;
65- let assertions = if build. config . llvm_assertions { "ON" } else { "OFF" } ;
69+ t ! ( fs:: create_dir_all( & out_dir) ) ;
6670
6771 // http://llvm.org/docs/CMake.html
6872 let mut cfg = cmake:: Config :: new ( build. src . join ( "src/llvm" ) ) ;
@@ -82,9 +86,11 @@ pub fn llvm(build: &Build, target: &str) {
8286 None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX" ,
8387 } ;
8488
89+ let assertions = if build. config . llvm_assertions { "ON" } else { "OFF" } ;
90+
8591 cfg. target ( target)
8692 . host ( & build. config . build )
87- . out_dir ( & dst )
93+ . out_dir ( & out_dir )
8894 . profile ( profile)
8995 . define ( "LLVM_ENABLE_ASSERTIONS" , assertions)
9096 . define ( "LLVM_TARGETS_TO_BUILD" , llvm_targets)
@@ -142,7 +148,7 @@ pub fn llvm(build: &Build, target: &str) {
142148 // tools and libs on all platforms.
143149 cfg. build ( ) ;
144150
145- t ! ( t!( File :: create( & done_stamp) ) . write_all( stamp_contents . as_bytes( ) ) ) ;
151+ t ! ( t!( File :: create( & done_stamp) ) . write_all( clean_trigger_contents . as_bytes( ) ) ) ;
146152}
147153
148154fn check_llvm_version ( build : & Build , llvm_config : & Path ) {
0 commit comments