Skip to content

Commit 2f4906f

Browse files
committed
set force_recompile: true if library is modified
This allows the standard library to be compiled even with `download-rustc` enabled. Which means it's no longer a requirement to compile `rustc` in order to compile `std`. Signed-off-by: onur-ozkan <[email protected]>
1 parent e69c19e commit 2f4906f

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+38-8
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ use crate::core::builder::{
2525
};
2626
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
2727
use crate::utils::exec::command;
28+
use crate::utils::helpers;
2829
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,
3032
};
3133
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS};
3234

@@ -107,28 +109,56 @@ impl Std {
107109
}
108110
deps
109111
}
112+
113+
#[cfg(feature = "bootstrap-self-test")]
114+
pub fn crates(mut self, crates: Vec<String>) -> Self {
115+
self.crates = crates;
116+
self
117+
}
110118
}
111119

112120
impl Step for Std {
113121
type Output = ();
114122
const DEFAULT: bool = true;
115123

116124
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")
123126
}
124127

125128
fn make_run(run: RunConfig<'_>) {
126129
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+
127157
run.builder.ensure(Std {
128158
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
129159
target: run.target,
130160
crates,
131-
force_recompile: false,
161+
force_recompile,
132162
extra_rust_args: &[],
133163
is_for_mir_opt_tests: false,
134164
});

0 commit comments

Comments
 (0)