Skip to content

Commit 0b28978

Browse files
authored
Rollup merge of rust-lang#145083 - Kobzol:fix-cargo-cross-build, r=jieyouxu
Fix cross-compilation of Cargo Regressed in rust-lang#144303. I guess this wasn't seen in other `ToolTarget` tools, because they are more dependent on the compiler and are ~always built together with other stuff that also built the std, while Cargo is relatively self-contained. Fixes: rust-lang#145059 r? ``@jieyouxu``
2 parents d0ddeb5 + 9eb9b5a commit 0b28978

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ pub fn prepare_tool_cargo(
334334
/// Determines how to build a `ToolTarget`, i.e. which compiler should be used to compile it.
335335
/// The compiler stage is automatically bumped if we need to cross-compile a stage 1 tool.
336336
pub enum ToolTargetBuildMode {
337-
/// Build the tool using rustc that corresponds to the selected CLI stage.
337+
/// Build the tool for the given `target` using rustc that corresponds to the top CLI
338+
/// stage.
338339
Build(TargetSelection),
339340
/// Build the tool so that it can be attached to the sysroot of the passed compiler.
340341
/// Since we always dist stage 2+, the compiler that builds the tool in this case has to be
@@ -366,7 +367,10 @@ pub(crate) fn get_tool_target_compiler(
366367
} else {
367368
// If we are cross-compiling a stage 1 tool, we cannot do that with a stage 0 compiler,
368369
// so we auto-bump the tool's stage to 2, which means we need a stage 1 compiler.
369-
builder.compiler(build_compiler_stage.max(1), builder.host_target)
370+
let build_compiler = builder.compiler(build_compiler_stage.max(1), builder.host_target);
371+
// We also need the host stdlib to compile host code (proc macros/build scripts)
372+
builder.std(build_compiler, builder.host_target);
373+
build_compiler
370374
};
371375
builder.std(compiler, target);
372376
compiler

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,22 @@ mod snapshot {
975975
.render_steps(), @"[build] rustc 0 <host> -> cargo 1 <host>");
976976
}
977977

978+
#[test]
979+
fn build_cargo_cross() {
980+
let ctx = TestCtx::new();
981+
insta::assert_snapshot!(
982+
ctx.config("build")
983+
.paths(&["cargo"])
984+
.hosts(&[TEST_TRIPLE_1])
985+
.render_steps(), @r"
986+
[build] llvm <host>
987+
[build] rustc 0 <host> -> rustc 1 <host>
988+
[build] rustc 1 <host> -> std 1 <host>
989+
[build] rustc 1 <host> -> std 1 <target1>
990+
[build] rustc 1 <host> -> cargo 2 <target1>
991+
");
992+
}
993+
978994
#[test]
979995
fn dist_default_stage() {
980996
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)