Skip to content

Commit a7c0da2

Browse files
authored
Rollup merge of rust-lang#127974 - onur-ozkan:force-std-builds, r=Mark-Simulacrum
force compiling std from source if 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`. Ref. rust-lang#127322 (comment). Blocker for rust-lang#122709.
2 parents 68ec714 + 6fcc630 commit a7c0da2

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

config.example.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@
472472
# This is mostly useful for tools; if you have changes to `compiler/` or `library/` they will be ignored.
473473
#
474474
# Set this to "if-unchanged" to only download if the compiler and standard library have not been modified.
475-
# Set this to `true` to download unconditionally (useful if e.g. you are only changing doc-comments).
475+
# Set this to `true` to download unconditionally. This is useful if you are working on tools, doc-comments,
476+
# or library (you will be able to build the standard library without needing to build the compiler).
476477
#download-rustc = false
477478

478479
# Number of codegen units to use for each compiler invocation. A value of 0

src/bootstrap/src/core/build_steps/compile.rs

+31-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use crate::core::builder::{
2626
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
2727
use crate::utils::exec::command;
2828
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,
3031
};
3132
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS};
3233

@@ -114,21 +115,43 @@ impl Step for Std {
114115
const DEFAULT: bool = true;
115116

116117
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")
123119
}
124120

125121
fn make_run(run: RunConfig<'_>) {
126122
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+
127150
run.builder.ensure(Std {
128151
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
129152
target: run.target,
130153
crates,
131-
force_recompile: false,
154+
force_recompile,
132155
extra_rust_args: &[],
133156
is_for_mir_opt_tests: false,
134157
});

0 commit comments

Comments
 (0)