Skip to content

Commit 1a648b3

Browse files
committed
Auto merge of #120803 - onur-ozkan:fix-compilation-cache, r=Mark-Simulacrum
always run `configure_linker` except for mir-opt tests `configure_linker` now runs consistently unless it's for mir-opt tests. Previously `!= "check"` condition was causing dirt in the cargo cache between runs of `x anything-but-not-check` and `x check`. Fixes #120768 cc `@saethlin`
2 parents a166af7 + ff6d296 commit 1a648b3

File tree

7 files changed

+250
-171
lines changed

7 files changed

+250
-171
lines changed

src/bootstrap/src/core/build_steps/check.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::core::build_steps::compile::{
44
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
55
};
66
use crate::core::build_steps::tool::{prepare_tool_cargo, SourceType};
7-
use crate::core::builder::{crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step};
7+
use crate::core::builder::{
8+
self, crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step,
9+
};
810
use crate::core::config::TargetSelection;
911
use crate::utils::cache::Interned;
1012
use crate::INTERNER;
@@ -110,13 +112,15 @@ impl Step for Std {
110112
let target = self.target;
111113
let compiler = builder.compiler(builder.top_stage, builder.config.build);
112114

113-
let mut cargo = builder.cargo(
115+
let mut cargo = builder::Cargo::new(
116+
builder,
114117
compiler,
115118
Mode::Std,
116119
SourceType::InTree,
117120
target,
118121
cargo_subcommand(builder.kind),
119122
);
123+
120124
std_cargo(builder, target, compiler.stage, &mut cargo);
121125
if matches!(builder.config.cmd, Subcommand::Fix { .. }) {
122126
// By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot.
@@ -162,7 +166,8 @@ impl Step for Std {
162166
// since we initialize with an empty sysroot.
163167
//
164168
// Currently only the "libtest" tree of crates does this.
165-
let mut cargo = builder.cargo(
169+
let mut cargo = builder::Cargo::new(
170+
builder,
166171
compiler,
167172
Mode::Std,
168173
SourceType::InTree,
@@ -256,13 +261,15 @@ impl Step for Rustc {
256261
builder.ensure(Std::new(target));
257262
}
258263

259-
let mut cargo = builder.cargo(
264+
let mut cargo = builder::Cargo::new(
265+
builder,
260266
compiler,
261267
Mode::Rustc,
262268
SourceType::InTree,
263269
target,
264270
cargo_subcommand(builder.kind),
265271
);
272+
266273
rustc_cargo(builder, &mut cargo, target, compiler.stage);
267274

268275
// For ./x.py clippy, don't run with --all-targets because
@@ -332,13 +339,15 @@ impl Step for CodegenBackend {
332339

333340
builder.ensure(Rustc::new(target, builder));
334341

335-
let mut cargo = builder.cargo(
342+
let mut cargo = builder::Cargo::new(
343+
builder,
336344
compiler,
337345
Mode::Codegen,
338346
SourceType::InTree,
339347
target,
340348
cargo_subcommand(builder.kind),
341349
);
350+
342351
cargo
343352
.arg("--manifest-path")
344353
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));

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

+34-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use serde_derive::Deserialize;
2222
use crate::core::build_steps::dist;
2323
use crate::core::build_steps::llvm;
2424
use crate::core::build_steps::tool::SourceType;
25+
use crate::core::builder;
2526
use crate::core::builder::crate_description;
2627
use crate::core::builder::Cargo;
2728
use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
@@ -239,12 +240,26 @@ impl Step for Std {
239240
// with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
240241
// fact that this is a check build integrates nicely with run_cargo.
241242
let mut cargo = if self.is_for_mir_opt_tests {
242-
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "check");
243+
let mut cargo = builder::Cargo::new_for_mir_opt_tests(
244+
builder,
245+
compiler,
246+
Mode::Std,
247+
SourceType::InTree,
248+
target,
249+
"check",
250+
);
243251
cargo.rustflag("-Zalways-encode-mir");
244252
cargo.arg("--manifest-path").arg(builder.src.join("library/sysroot/Cargo.toml"));
245253
cargo
246254
} else {
247-
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build");
255+
let mut cargo = builder::Cargo::new(
256+
builder,
257+
compiler,
258+
Mode::Std,
259+
SourceType::InTree,
260+
target,
261+
"build",
262+
);
248263
std_cargo(builder, target, compiler.stage, &mut cargo);
249264
for krate in &*self.crates {
250265
cargo.arg("-p").arg(krate);
@@ -913,7 +928,15 @@ impl Step for Rustc {
913928
builder.config.build,
914929
));
915930

916-
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build");
931+
let mut cargo = builder::Cargo::new(
932+
builder,
933+
compiler,
934+
Mode::Rustc,
935+
SourceType::InTree,
936+
target,
937+
"build",
938+
);
939+
917940
rustc_cargo(builder, &mut cargo, target, compiler.stage);
918941

919942
if builder.config.rust_profile_use.is_some()
@@ -1333,7 +1356,14 @@ impl Step for CodegenBackend {
13331356

13341357
let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
13351358

1336-
let mut cargo = builder.cargo(compiler, Mode::Codegen, SourceType::InTree, target, "build");
1359+
let mut cargo = builder::Cargo::new(
1360+
builder,
1361+
compiler,
1362+
Mode::Codegen,
1363+
SourceType::InTree,
1364+
target,
1365+
"build",
1366+
);
13371367
cargo
13381368
.arg("--manifest-path")
13391369
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));

src/bootstrap/src/core/build_steps/doc.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{fs, mem};
1313

1414
use crate::core::build_steps::compile;
1515
use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool};
16-
use crate::core::builder::crate_description;
16+
use crate::core::builder::{self, crate_description};
1717
use crate::core::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1818
use crate::core::config::{Config, TargetSelection};
1919
use crate::utils::cache::{Interned, INTERNER};
@@ -684,7 +684,9 @@ fn doc_std(
684684
// as a function parameter.
685685
let out_dir = target_dir.join(target.triple).join("doc");
686686

687-
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "doc");
687+
let mut cargo =
688+
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "doc");
689+
688690
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
689691
cargo
690692
.arg("--no-deps")
@@ -785,7 +787,9 @@ impl Step for Rustc {
785787
);
786788

787789
// Build cargo command.
788-
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc");
790+
let mut cargo =
791+
builder::Cargo::new(builder, compiler, Mode::Rustc, SourceType::InTree, target, "doc");
792+
789793
cargo.rustdocflag("--document-private-items");
790794
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
791795
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");

src/bootstrap/src/core/build_steps/run.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Step for Miri {
165165
SourceType::InTree,
166166
&[],
167167
);
168-
miri.add_rustc_lib_path(builder, compiler);
168+
miri.add_rustc_lib_path(builder);
169169
// Forward arguments.
170170
miri.arg("--").arg("--target").arg(target.rustc_target_arg());
171171
miri.args(builder.config.args());

src/bootstrap/src/core/build_steps/test.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::core::build_steps::llvm;
2020
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
2121
use crate::core::build_steps::tool::{self, SourceType, Tool};
2222
use crate::core::build_steps::toolstate::ToolState;
23+
use crate::core::builder;
2324
use crate::core::builder::crate_description;
2425
use crate::core::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
2526
use crate::core::config::flags::get_completion;
@@ -380,7 +381,7 @@ impl Step for RustAnalyzer {
380381
// work in Rust CI
381382
cargo.env("SKIP_SLOW_TESTS", "1");
382383

383-
cargo.add_rustc_lib_path(builder, compiler);
384+
cargo.add_rustc_lib_path(builder);
384385
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", compiler, host, builder);
385386
}
386387
}
@@ -426,7 +427,7 @@ impl Step for Rustfmt {
426427
t!(fs::create_dir_all(&dir));
427428
cargo.env("RUSTFMT_TEST_DIR", dir);
428429

429-
cargo.add_rustc_lib_path(builder, compiler);
430+
cargo.add_rustc_lib_path(builder);
430431

431432
run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", compiler, host, builder);
432433
}
@@ -476,7 +477,7 @@ impl Step for RustDemangler {
476477
t!(fs::create_dir_all(&dir));
477478

478479
cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
479-
cargo.add_rustc_lib_path(builder, compiler);
480+
cargo.add_rustc_lib_path(builder);
480481

481482
run_cargo_test(
482483
cargo,
@@ -517,7 +518,7 @@ impl Miri {
517518
SourceType::InTree,
518519
&[],
519520
);
520-
cargo.add_rustc_lib_path(builder, compiler);
521+
cargo.add_rustc_lib_path(builder);
521522
cargo.arg("--").arg("miri").arg("setup");
522523
cargo.arg("--target").arg(target.rustc_target_arg());
523524

@@ -618,7 +619,7 @@ impl Step for Miri {
618619
);
619620
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "miri", host, target);
620621

621-
cargo.add_rustc_lib_path(builder, compiler);
622+
cargo.add_rustc_lib_path(builder);
622623

623624
// miri tests need to know about the stage sysroot
624625
cargo.env("MIRI_SYSROOT", &miri_sysroot);
@@ -671,7 +672,7 @@ impl Step for Miri {
671672
SourceType::Submodule,
672673
&[],
673674
);
674-
cargo.add_rustc_lib_path(builder, compiler);
675+
cargo.add_rustc_lib_path(builder);
675676
cargo.arg("--").arg("miri").arg("test");
676677
if builder.config.locked_deps {
677678
cargo.arg("--locked");
@@ -788,7 +789,7 @@ impl Step for Clippy {
788789
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
789790
cargo.env("HOST_LIBS", host_libs);
790791

791-
cargo.add_rustc_lib_path(builder, compiler);
792+
cargo.add_rustc_lib_path(builder);
792793
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);
793794

794795
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
@@ -2499,8 +2500,15 @@ impl Step for Crate {
24992500
// we're working with automatically.
25002501
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
25012502

2502-
let mut cargo =
2503-
builder.cargo(compiler, mode, SourceType::InTree, target, builder.kind.as_str());
2503+
let mut cargo = builder::Cargo::new(
2504+
builder,
2505+
compiler,
2506+
mode,
2507+
SourceType::InTree,
2508+
target,
2509+
builder.kind.as_str(),
2510+
);
2511+
25042512
match mode {
25052513
Mode::Std => {
25062514
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -3134,13 +3142,15 @@ impl Step for CodegenCranelift {
31343142
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
31353143

31363144
let build_cargo = || {
3137-
let mut cargo = builder.cargo(
3145+
let mut cargo = builder::Cargo::new(
3146+
builder,
31383147
compiler,
31393148
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
31403149
SourceType::InTree,
31413150
target,
31423151
"run",
31433152
);
3153+
31443154
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_cranelift"));
31453155
cargo
31463156
.arg("--manifest-path")
@@ -3260,13 +3270,15 @@ impl Step for CodegenGCC {
32603270
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
32613271

32623272
let build_cargo = || {
3263-
let mut cargo = builder.cargo(
3273+
let mut cargo = builder::Cargo::new(
3274+
builder,
32643275
compiler,
32653276
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
32663277
SourceType::InTree,
32673278
target,
32683279
"run",
32693280
);
3281+
32703282
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_gcc"));
32713283
cargo
32723284
.arg("--manifest-path")

src/bootstrap/src/core/build_steps/tool.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::process::Command;
55

66
use crate::core::build_steps::compile;
77
use crate::core::build_steps::toolstate::ToolState;
8+
use crate::core::builder;
89
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
910
use crate::core::config::TargetSelection;
1011
use crate::utils::channel::GitInfo;
@@ -142,7 +143,8 @@ pub fn prepare_tool_cargo(
142143
source_type: SourceType,
143144
extra_features: &[String],
144145
) -> CargoCommand {
145-
let mut cargo = builder.cargo(compiler, mode, source_type, target, command);
146+
let mut cargo = builder::Cargo::new(builder, compiler, mode, source_type, target, command);
147+
146148
let dir = builder.src.join(path);
147149
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
148150

0 commit comments

Comments
 (0)