Rollup merge of #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. https://github.com/rust-lang/rust/pull/127322#discussion_r1666418280.
Blocker for https://github.com/rust-lang/rust/pull/122709.
This commit is contained in:
Matthias Krüger 2024-08-05 05:40:20 +02:00 committed by GitHub
commit f6c8b7a60a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 9 deletions

View File

@ -472,7 +472,8 @@
# This is mostly useful for tools; if you have changes to `compiler/` or `library/` they will be ignored. # This is mostly useful for tools; if you have changes to `compiler/` or `library/` they will be ignored.
# #
# Set this to "if-unchanged" to only download if the compiler and standard library have not been modified. # Set this to "if-unchanged" to only download if the compiler and standard library have not been modified.
# Set this to `true` to download unconditionally (useful if e.g. you are only changing doc-comments). # Set this to `true` to download unconditionally. This is useful if you are working on tools, doc-comments,
# or library (you will be able to build the standard library without needing to build the compiler).
#download-rustc = false #download-rustc = false
# Number of codegen units to use for each compiler invocation. A value of 0 # Number of codegen units to use for each compiler invocation. A value of 0

View File

@ -26,7 +26,8 @@
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection}; use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
use crate::utils::exec::command; use crate::utils::exec::command;
use crate::utils::helpers::{ use crate::utils::helpers::{
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date, self, exe, get_clang_cl_resource_dir, get_closest_merge_base_commit, is_debug_info, is_dylib,
symlink_dir, t, up_to_date,
}; };
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS}; use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS};
@ -114,21 +115,43 @@ impl Step for Std {
const DEFAULT: bool = true; const DEFAULT: bool = true;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
// When downloading stage1, the standard library has already been copied to the sysroot, so run.crate_or_deps("sysroot").path("library")
// there's no need to rebuild it.
let builder = run.builder;
run.crate_or_deps("sysroot")
.path("library")
.lazy_default_condition(Box::new(|| !builder.download_rustc()))
} }
fn make_run(run: RunConfig<'_>) { fn make_run(run: RunConfig<'_>) {
let crates = std_crates_for_run_make(&run); let crates = std_crates_for_run_make(&run);
let builder = run.builder;
// Force compilation of the standard library from source if the `library` is modified. This allows
// library team to compile the standard library without needing to compile the compiler with
// the `rust.download-rustc=true` option.
let force_recompile =
if builder.rust_info().is_managed_git_subrepository() && builder.download_rustc() {
let closest_merge_commit = get_closest_merge_base_commit(
Some(&builder.src),
&builder.config.git_config(),
&builder.config.stage0_metadata.config.git_merge_commit_email,
&[],
)
.unwrap();
// Check if `library` has changes (returns false otherwise)
!t!(helpers::git(Some(&builder.src))
.args(["diff-index", "--quiet", &closest_merge_commit])
.arg("--")
.arg(builder.src.join("library"))
.as_command_mut()
.status())
.success()
} else {
false
};
run.builder.ensure(Std { run.builder.ensure(Std {
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()), compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
target: run.target, target: run.target,
crates, crates,
force_recompile: false, force_recompile,
extra_rust_args: &[], extra_rust_args: &[],
is_for_mir_opt_tests: false, is_for_mir_opt_tests: false,
}); });