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