@@ -26,7 +26,8 @@ use crate::core::builder::{
26
26
use crate :: core:: config:: { DebuginfoLevel , LlvmLibunwind , RustcLto , TargetSelection } ;
27
27
use crate :: utils:: exec:: command;
28
28
use crate :: utils:: helpers:: {
29
- exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
29
+ self , exe, get_clang_cl_resource_dir, get_closest_merge_base_commit, is_debug_info, is_dylib,
30
+ symlink_dir, t, up_to_date,
30
31
} ;
31
32
use crate :: { CLang , Compiler , DependencyType , GitRepo , Mode , LLVM_TOOLS } ;
32
33
@@ -114,21 +115,43 @@ impl Step for Std {
114
115
const DEFAULT : bool = true ;
115
116
116
117
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 ( ) ) )
118
+ run. crate_or_deps ( "sysroot" ) . path ( "library" )
123
119
}
124
120
125
121
fn make_run ( run : RunConfig < ' _ > ) {
126
122
let crates = std_crates_for_run_make ( & run) ;
123
+ let builder = run. builder ;
124
+
125
+ // Force compilation of the standard library from source if the `library` is modified. This allows
126
+ // library team to compile the standard library without needing to compile the compiler with
127
+ // the `rust.download-rustc=true` option.
128
+ let force_recompile =
129
+ if builder. rust_info ( ) . is_managed_git_subrepository ( ) && builder. download_rustc ( ) {
130
+ let closest_merge_commit = get_closest_merge_base_commit (
131
+ Some ( & builder. src ) ,
132
+ & builder. config . git_config ( ) ,
133
+ & builder. config . stage0_metadata . config . git_merge_commit_email ,
134
+ & [ ] ,
135
+ )
136
+ . unwrap ( ) ;
137
+
138
+ // Check if `library` has changes (returns false otherwise)
139
+ !t ! ( helpers:: git( Some ( & builder. src) )
140
+ . args( [ "diff-index" , "--quiet" , & closest_merge_commit] )
141
+ . arg( "--" )
142
+ . arg( builder. src. join( "library" ) )
143
+ . as_command_mut( )
144
+ . status( ) )
145
+ . success ( )
146
+ } else {
147
+ false
148
+ } ;
149
+
127
150
run. builder . ensure ( Std {
128
151
compiler : run. builder . compiler ( run. builder . top_stage , run. build_triple ( ) ) ,
129
152
target : run. target ,
130
153
crates,
131
- force_recompile : false ,
154
+ force_recompile,
132
155
extra_rust_args : & [ ] ,
133
156
is_for_mir_opt_tests : false ,
134
157
} ) ;
0 commit comments