Skip to content

Commit 87540bd

Browse files
committed
Auto merge of #67760 - Mark-Simulacrum:rustc-dirty, r=alexcrichton
Clear out target directory if compiler has changed Previously, we relied fully on Cargo to detect that the compiler had changed and it needed to rebuild the standard library (or later "components"). This used to not quite be the case prior to moving to LLVM be a separate cargo invocation; subsequent compiles would recompile std and friends if LLVM had changed (#67077 is the PR that changes things here). This PR moves us to clearing out libstd when it is being compiled if the rustc we're using has changed. We fairly harshly limit the cases in which we do this (e.g., ignoring dry run mode, and so forth, as well as rustdoc invocations). This is primarily because when we're not using the compiler directly, so clearing out in other cases is likely to lead to bugs, particularly as our deletion scheme is pretty blunt today (basically removing more than is needed, i.e., not just the rustc artifacts). In practice, this targeted fix does fix the known bug, though it may not fully resolve the problem here. It's also not clear that there is a full fix hiding here that doesn't involve a more major change (like -Zbinary-dep-depinfo was). As a drive-by fix, don't delete the compiler before calling Build::copy, as that also deletes the compiler.
2 parents f48e576 + ccd8c8c commit 87540bd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/bootstrap/builder.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ impl<'a> Builder<'a> {
726726
self.clear_if_dirty(&my_out, &rustdoc);
727727
}
728728

729-
cargo.env("CARGO_TARGET_DIR", out_dir).arg(cmd).arg("-Zconfig-profile");
729+
cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd).arg("-Zconfig-profile");
730730

731731
let profile_var = |name: &str| {
732732
let profile = if self.config.rust_optimize { "RELEASE" } else { "DEV" };
@@ -865,6 +865,18 @@ impl<'a> Builder<'a> {
865865
let sysroot = if use_snapshot { self.rustc_snapshot_sysroot() } else { &maybe_sysroot };
866866
let libdir = self.rustc_libdir(compiler);
867867

868+
// Clear the output directory if the real rustc we're using has changed;
869+
// Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc.
870+
//
871+
// Avoid doing this during dry run as that usually means the relevant
872+
// compiler is not yet linked/copied properly.
873+
//
874+
// Only clear out the directory if we're compiling std; otherwise, we
875+
// should let Cargo take care of things for us (via depdep info)
876+
if !self.config.dry_run && mode == Mode::ToolStd && cmd == "build" {
877+
self.clear_if_dirty(&out_dir, &self.rustc(compiler));
878+
}
879+
868880
// Customize the compiler we're running. Specify the compiler to cargo
869881
// as our shim and then pass it some various options used to configure
870882
// how the actual compiler itself is called.

src/bootstrap/compile.rs

-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ impl Step for Assemble {
776776
let bindir = sysroot.join("bin");
777777
t!(fs::create_dir_all(&bindir));
778778
let compiler = builder.rustc(target_compiler);
779-
let _ = fs::remove_file(&compiler);
780779
builder.copy(&rustc, &compiler);
781780

782781
target_compiler

0 commit comments

Comments
 (0)