@@ -21,7 +21,7 @@ use std::fs::{self, File};
21
21
use std:: path:: { Path , PathBuf } ;
22
22
use std:: process:: Command ;
23
23
24
- use build_helper:: { output, mtime} ;
24
+ use build_helper:: { output, mtime, up_to_date } ;
25
25
use filetime:: FileTime ;
26
26
27
27
use util:: { exe, libdir, is_dylib, copy} ;
@@ -132,21 +132,29 @@ pub fn build_startup_objects(build: &Build, for_compiler: &Compiler, target: &st
132
132
133
133
let compiler = Compiler :: new ( 0 , & build. config . build ) ;
134
134
let compiler_path = build. compiler_path ( & compiler) ;
135
- let into = build. sysroot_libdir ( for_compiler, target) ;
136
- t ! ( fs:: create_dir_all( & into) ) ;
137
-
138
- for file in t ! ( fs:: read_dir( build. src. join( "src/rtstartup" ) ) ) {
139
- let file = t ! ( file) ;
140
- let mut cmd = Command :: new ( & compiler_path) ;
141
- build. run ( cmd. env ( "RUSTC_BOOTSTRAP" , "1" )
142
- . arg ( "--target" ) . arg ( target)
143
- . arg ( "--emit=obj" )
144
- . arg ( "--out-dir" ) . arg ( & into)
145
- . arg ( file. path ( ) ) ) ;
135
+ let src_dir = & build. src . join ( "src/rtstartup" ) ;
136
+ let dst_dir = & build. native_dir ( target) . join ( "rtstartup" ) ;
137
+ let sysroot_dir = & build. sysroot_libdir ( for_compiler, target) ;
138
+ t ! ( fs:: create_dir_all( dst_dir) ) ;
139
+ t ! ( fs:: create_dir_all( sysroot_dir) ) ;
140
+
141
+ for file in & [ "rsbegin" , "rsend" ] {
142
+ let src_file = & src_dir. join ( file. to_string ( ) + ".rs" ) ;
143
+ let dst_file = & dst_dir. join ( file. to_string ( ) + ".o" ) ;
144
+ if !up_to_date ( src_file, dst_file) {
145
+ let mut cmd = Command :: new ( & compiler_path) ;
146
+ build. run ( cmd. env ( "RUSTC_BOOTSTRAP" , "1" )
147
+ . arg ( "--target" ) . arg ( target)
148
+ . arg ( "--emit=obj" )
149
+ . arg ( "--out-dir" ) . arg ( dst_dir)
150
+ . arg ( src_file) ) ;
151
+ }
152
+
153
+ copy ( dst_file, & sysroot_dir. join ( file. to_string ( ) + ".o" ) ) ;
146
154
}
147
155
148
156
for obj in [ "crt2.o" , "dllcrt2.o" ] . iter ( ) {
149
- copy ( & compiler_file ( build. cc ( target) , obj) , & into . join ( obj) ) ;
157
+ copy ( & compiler_file ( build. cc ( target) , obj) , & sysroot_dir . join ( obj) ) ;
150
158
}
151
159
}
152
160
0 commit comments