diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index a2dca66697d6d..068cc2315e1a9 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -726,7 +726,7 @@ impl<'a> Builder<'a> { self.clear_if_dirty(&my_out, &rustdoc); } - cargo.env("CARGO_TARGET_DIR", out_dir).arg(cmd).arg("-Zconfig-profile"); + cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd).arg("-Zconfig-profile"); let profile_var = |name: &str| { let profile = if self.config.rust_optimize { "RELEASE" } else { "DEV" }; @@ -865,6 +865,18 @@ impl<'a> Builder<'a> { let sysroot = if use_snapshot { self.rustc_snapshot_sysroot() } else { &maybe_sysroot }; let libdir = self.rustc_libdir(compiler); + // Clear the output directory if the real rustc we're using has changed; + // Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc. + // + // Avoid doing this during dry run as that usually means the relevant + // compiler is not yet linked/copied properly. + // + // Only clear out the directory if we're compiling std; otherwise, we + // should let Cargo take care of things for us (via depdep info) + if !self.config.dry_run && mode == Mode::ToolStd && cmd == "build" { + self.clear_if_dirty(&out_dir, &self.rustc(compiler)); + } + // Customize the compiler we're running. Specify the compiler to cargo // as our shim and then pass it some various options used to configure // how the actual compiler itself is called. diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2d60024a22ac4..7f0bb5813a4a0 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -776,7 +776,6 @@ impl Step for Assemble { let bindir = sysroot.join("bin"); t!(fs::create_dir_all(&bindir)); let compiler = builder.rustc(target_compiler); - let _ = fs::remove_file(&compiler); builder.copy(&rustc, &compiler); target_compiler