Skip to content

Commit 1d1efed

Browse files
committed
Fix x test cargo
1 parent 528e7dc commit 1d1efed

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use crate::core::build_steps::llvm::get_llvm_version;
1818
use crate::core::build_steps::run::get_completion_paths;
1919
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
2020
use crate::core::build_steps::tool::{
21-
self, COMPILETEST_ALLOW_FEATURES, RustcPrivateCompilers, SourceType, Tool,
21+
self, COMPILETEST_ALLOW_FEATURES, RustcPrivateCompilers, SourceType, Tool, ToolTargetBuildMode,
22+
get_tool_target_compiler,
2223
};
2324
use crate::core::build_steps::toolstate::ToolState;
2425
use crate::core::build_steps::{compile, dist, llvm};
@@ -293,7 +294,7 @@ impl Step for Cargotest {
293294
/// Runs `cargo test` for cargo itself.
294295
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
295296
pub struct Cargo {
296-
stage: u32,
297+
build_compiler: Compiler,
297298
host: TargetSelection,
298299
}
299300

@@ -310,35 +311,29 @@ impl Step for Cargo {
310311
}
311312

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

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

338333
let cargo = tool::prepare_tool_cargo(
339334
builder,
340-
compiler,
341-
Mode::ToolRustc,
335+
self.build_compiler,
336+
Mode::ToolTarget,
342337
self.host,
343338
Kind::Test,
344339
Self::CRATE_PATH,
@@ -355,7 +350,7 @@ impl Step for Cargo {
355350
// Forcibly disable tests using nightly features since any changes to
356351
// those features won't be able to land.
357352
cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
358-
cargo.env("PATH", path_for_cargo(builder, compiler));
353+
cargo.env("PATH", path_for_cargo(builder, self.build_compiler));
359354
// Cargo's test suite uses `CARGO_RUSTC_CURRENT_DIR` to determine the path that `file!` is
360355
// relative to. Cargo no longer sets this env var, so we have to do that. This has to be the
361356
// same value as `-Zroot-dir`.
@@ -367,7 +362,7 @@ impl Step for Cargo {
367362
crates: vec!["cargo".into()],
368363
target: self.host.triple.to_string(),
369364
host: self.host.triple.to_string(),
370-
stage,
365+
stage: self.build_compiler.stage + 1,
371366
},
372367
builder,
373368
);

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)