Rollup merge of #137882 - onur-ozkan:remove-extra-compiler-stage, r=Kobzol

do not build additional stage on compiler paths

When calling `x build compiler (or rustc) --stage N` bootstrap builds stage N+1 compiler, which is clearly not what we requested. This doesn't happen when running `x build --stage N` without explicitly targeting the compiler.

The changes applied fix this issue.

r? ghost
This commit is contained in:
Matthias Krüger 2025-03-03 20:47:12 +01:00 committed by GitHub
commit a4b6181156
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 9 deletions

View file

@ -994,7 +994,9 @@ impl Step for Rustc {
fn make_run(run: RunConfig<'_>) {
let crates = run.cargo_crates_in_set();
run.builder.ensure(Rustc {
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
compiler: run
.builder
.compiler(run.builder.top_stage.saturating_sub(1), run.build_triple()),
target: run.target,
crates,
});
@ -1911,7 +1913,7 @@ impl Step for Assemble {
fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Assemble {
target_compiler: run.builder.compiler(run.builder.top_stage + 1, run.target),
target_compiler: run.builder.compiler(run.builder.top_stage, run.target),
});
}

View file

@ -653,6 +653,20 @@ mod dist {
&["compiler/rustc".into(), "library".into()],
);
assert_eq!(builder.config.stage, 2);
// `compile::Rustc` includes one-stage-off compiler information as the target compiler
// artifacts get copied from there to the target stage sysroot.
// For example, `stage2/bin/rustc` gets copied from the `stage1-rustc` build directory.
assert_eq!(
first(builder.cache.all::<compile::Rustc>()),
&[
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_1, stage = 0),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_1, stage = 1),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_2, stage = 1),
]
);
assert_eq!(
first(builder.cache.all::<compile::Std>()),
&[
@ -664,15 +678,34 @@ mod dist {
std!(TEST_TRIPLE_1 => TEST_TRIPLE_3, stage = 2),
]
);
assert_eq!(builder.cache.all::<compile::Assemble>().len(), 5);
assert_eq!(
first(builder.cache.all::<compile::Rustc>()),
first(builder.cache.all::<compile::Assemble>()),
&[
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_1, stage = 0),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_1, stage = 1),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_1, stage = 2),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_2, stage = 1),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_2, stage = 2),
compile::Assemble {
target_compiler: Compiler {
host: TargetSelection::from_user(TEST_TRIPLE_1),
stage: 0
}
},
compile::Assemble {
target_compiler: Compiler {
host: TargetSelection::from_user(TEST_TRIPLE_1),
stage: 1
}
},
compile::Assemble {
target_compiler: Compiler {
host: TargetSelection::from_user(TEST_TRIPLE_1),
stage: 2
}
},
compile::Assemble {
target_compiler: Compiler {
host: TargetSelection::from_user(TEST_TRIPLE_2),
stage: 2
}
},
]
);
}