Skip to content

Commit 0438a46

Browse files
committed
Fix x test cargo
1 parent c4fef48 commit 0438a46

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

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

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
1515
use crate::core::build_steps::run::get_completion_paths;
1616
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
1717
use crate::core::build_steps::tool::{
18-
self, COMPILETEST_ALLOW_FEATURES, RustcPrivateCompilers, SourceType, Tool,
18+
self, COMPILETEST_ALLOW_FEATURES, RustcPrivateCompilers, SourceType, Tool, ToolTargetBuildMode,
19+
get_tool_target_compiler,
1920
};
2021
use crate::core::build_steps::toolstate::ToolState;
2122
use crate::core::build_steps::{compile, dist, llvm};
@@ -290,7 +291,7 @@ impl Step for Cargotest {
290291
/// Runs `cargo test` for cargo itself.
291292
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
292293
pub struct Cargo {
293-
stage: u32,
294+
build_compiler: Compiler,
294295
host: TargetSelection,
295296
}
296297

@@ -307,35 +308,29 @@ impl Step for Cargo {
307308
}
308309

309310
fn make_run(run: RunConfig<'_>) {
310-
// If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
311-
// as tests for this step don't work with a lower stage.
312-
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
313-
run.builder.top_stage
314-
} else {
315-
2
316-
};
317-
318-
run.builder.ensure(Cargo { stage, host: run.target });
311+
run.builder.ensure(Cargo {
312+
build_compiler: get_tool_target_compiler(
313+
run.builder,
314+
ToolTargetBuildMode::Build(run.target),
315+
),
316+
host: run.target,
317+
});
319318
}
320319

321320
/// Runs `cargo test` for `cargo` packaged with Rust.
322321
fn run(self, builder: &Builder<'_>) {
323-
let stage = self.stage;
324-
325-
if stage < 2 {
326-
eprintln!("WARNING: cargo tests on stage {stage} may not behave well.");
327-
eprintln!("HELP: consider using stage 2");
328-
}
329-
330-
let compiler = builder.compiler(stage, self.host);
331-
332-
let cargo = builder.ensure(tool::Cargo::from_build_compiler(compiler, self.host));
333-
let compiler = cargo.build_compiler;
322+
// FIXME: we now use the same compiler to build cargo and then we also test that compiler
323+
// using cargo.
324+
// We could build cargo using a different compiler, but that complicates some things,
325+
// because when we run cargo tests, the crates that are being compiled are accessing the
326+
// sysroot of the build compiler, rather than the compiler being tested.
327+
// Since these two compilers are currently the same, it works.
328+
builder.ensure(tool::Cargo::from_build_compiler(self.build_compiler, self.host));
334329

335330
let cargo = tool::prepare_tool_cargo(
336331
builder,
337-
compiler,
338-
Mode::ToolRustc,
332+
self.build_compiler,
333+
Mode::ToolTarget,
339334
self.host,
340335
Kind::Test,
341336
Self::CRATE_PATH,
@@ -352,7 +347,7 @@ impl Step for Cargo {
352347
// Forcibly disable tests using nightly features since any changes to
353348
// those features won't be able to land.
354349
cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
355-
cargo.env("PATH", path_for_cargo(builder, compiler));
350+
cargo.env("PATH", path_for_cargo(builder, self.build_compiler));
356351
// Cargo's test suite uses `CARGO_RUSTC_CURRENT_DIR` to determine the path that `file!` is
357352
// relative to. Cargo no longer sets this env var, so we have to do that. This has to be the
358353
// same value as `-Zroot-dir`.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ impl Step for Cargo {
841841
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
842842
builder.build.require_submodule("src/tools/cargo", None);
843843

844+
builder.std(self.build_compiler, self.target);
844845
builder.ensure(ToolBuild {
845846
build_compiler: self.build_compiler,
846847
target: self.target,
@@ -849,7 +850,11 @@ impl Step for Cargo {
849850
path: "src/tools/cargo",
850851
source_type: SourceType::Submodule,
851852
extra_features: Vec::new(),
852-
allow_features: "",
853+
// Cargo is compilable with a stable compiler, but since we run in bootstrap,
854+
// with RUSTC_BOOTSTRAP being set, some "clever" build scripts enable specialization
855+
// based on this, which breaks stuff. We thus have to explicitly allow these features
856+
// here.
857+
allow_features: "min_specialization,specialization",
853858
cargo_args: Vec::new(),
854859
artifact_kind: ToolArtifactKind::Binary,
855860
})

src/bootstrap/src/core/builder/tests.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,12 +1606,8 @@ mod snapshot {
16061606
ctx.config("test")
16071607
.path("cargo")
16081608
.render_steps(), @r"
1609-
[build] llvm <host>
1610-
[build] rustc 0 <host> -> rustc 1 <host>
1611-
[build] rustc 1 <host> -> std 1 <host>
1612-
[build] rustc 1 <host> -> rustc 2 <host>
1613-
[build] rustc 2 <host> -> cargo 3 <host>
1614-
[build] rustdoc 2 <host>
1609+
[build] rustc 0 <host> -> cargo 1 <host>
1610+
[build] rustdoc 0 <host>
16151611
");
16161612
}
16171613

@@ -1626,9 +1622,8 @@ mod snapshot {
16261622
[build] llvm <host>
16271623
[build] rustc 0 <host> -> rustc 1 <host>
16281624
[build] rustc 1 <host> -> std 1 <host>
1629-
[build] rustc 1 <host> -> rustc 2 <host>
1630-
[build] rustc 2 <host> -> cargo 3 <host>
1631-
[build] rustdoc 2 <host>
1625+
[build] rustc 1 <host> -> cargo 2 <host>
1626+
[build] rustdoc 1 <host>
16321627
");
16331628
}
16341629

0 commit comments

Comments
 (0)