Skip to content

Commit

Permalink
Rollup merge of rust-lang#127974 - onur-ozkan:force-std-builds, r=Mar…
Browse files Browse the repository at this point in the history
…k-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.
  • Loading branch information
matthiaskrgr authored Aug 4, 2024
2 parents e83a974 + 6fcc630 commit 69b7ac8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
3 changes: 2 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@
# 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 `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

# Number of codegen units to use for each compiler invocation. A value of 0
Expand Down
39 changes: 31 additions & 8 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use crate::core::builder::{
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
use crate::utils::exec::command;
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};

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

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
// When downloading stage1, the standard library has already been copied to the sysroot, so
// 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()))
run.crate_or_deps("sysroot").path("library")
}

fn make_run(run: RunConfig<'_>) {
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 {
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
target: run.target,
crates,
force_recompile: false,
force_recompile,
extra_rust_args: &[],
is_for_mir_opt_tests: false,
});
Expand Down

0 comments on commit 69b7ac8

Please sign in to comment.