@@ -25,8 +25,10 @@ use crate::core::builder::{
25
25
} ;
26
26
use crate :: core:: config:: { DebuginfoLevel , LlvmLibunwind , RustcLto , TargetSelection } ;
27
27
use crate :: utils:: exec:: command;
28
+ use crate :: utils:: helpers;
28
29
use crate :: utils:: helpers:: {
29
- exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
30
+ exe, get_clang_cl_resource_dir, get_closest_merge_base_commit, is_debug_info, is_dylib,
31
+ symlink_dir, t, up_to_date,
30
32
} ;
31
33
use crate :: { CLang , Compiler , DependencyType , GitRepo , Mode , LLVM_TOOLS } ;
32
34
@@ -107,28 +109,56 @@ impl Std {
107
109
}
108
110
deps
109
111
}
112
+
113
+ #[ cfg( feature = "bootstrap-self-test" ) ]
114
+ pub fn crates ( mut self , crates : Vec < String > ) -> Self {
115
+ self . crates = crates;
116
+ self
117
+ }
110
118
}
111
119
112
120
impl Step for Std {
113
121
type Output = ( ) ;
114
122
const DEFAULT : bool = true ;
115
123
116
124
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
117
- // When downloading stage1, the standard library has already been copied to the sysroot, so
118
- // there's no need to rebuild it.
119
- let builder = run. builder ;
120
- run. crate_or_deps ( "sysroot" )
121
- . path ( "library" )
122
- . lazy_default_condition ( Box :: new ( || !builder. download_rustc ( ) ) )
125
+ run. crate_or_deps ( "sysroot" ) . path ( "library" )
123
126
}
124
127
125
128
fn make_run ( run : RunConfig < ' _ > ) {
126
129
let crates = std_crates_for_run_make ( & run) ;
130
+ let builder = run. builder ;
131
+
132
+ // Force compilation of the standard library from source if the `library` is modified. This allows
133
+ // library team to compile the standard library without needing to compile the compiler with
134
+ // the `rust.download-rustc=true` option.
135
+ let force_recompile =
136
+ if builder. rust_info ( ) . is_managed_git_subrepository ( ) && builder. download_rustc ( ) {
137
+ let closest_merge_commit = get_closest_merge_base_commit (
138
+ Some ( & builder. src ) ,
139
+ & builder. config . git_config ( ) ,
140
+ & builder. config . stage0_metadata . config . git_merge_commit_email ,
141
+ & [ ] ,
142
+ )
143
+ . unwrap ( ) ;
144
+
145
+ // Check if `library` has changes (returns false otherwise)
146
+ !t ! ( helpers:: git( Some ( & builder. src) )
147
+ . args( [ "diff-index" , "--quiet" , & closest_merge_commit] )
148
+ . arg( "--" )
149
+ . arg( builder. src. join( "library" ) )
150
+ . as_command_mut( )
151
+ . status( ) )
152
+ . success ( )
153
+ } else {
154
+ false
155
+ } ;
156
+
127
157
run. builder . ensure ( Std {
128
158
compiler : run. builder . compiler ( run. builder . top_stage , run. build_triple ( ) ) ,
129
159
target : run. target ,
130
160
crates,
131
- force_recompile : false ,
161
+ force_recompile,
132
162
extra_rust_args : & [ ] ,
133
163
is_for_mir_opt_tests : false ,
134
164
} ) ;
0 commit comments