Skip to content

Fix cross-compilation of Cargo #145083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ pub fn prepare_tool_cargo(
/// Determines how to build a `ToolTarget`, i.e. which compiler should be used to compile it.
/// The compiler stage is automatically bumped if we need to cross-compile a stage 1 tool.
pub enum ToolTargetBuildMode {
/// Build the tool using rustc that corresponds to the selected CLI stage.
/// Build the tool for the given `target` using rustc that corresponds to the top CLI
/// stage.
Build(TargetSelection),
/// Build the tool so that it can be attached to the sysroot of the passed compiler.
/// Since we always dist stage 2+, the compiler that builds the tool in this case has to be
Expand Down Expand Up @@ -366,7 +367,10 @@ pub(crate) fn get_tool_target_compiler(
} else {
// If we are cross-compiling a stage 1 tool, we cannot do that with a stage 0 compiler,
// so we auto-bump the tool's stage to 2, which means we need a stage 1 compiler.
builder.compiler(build_compiler_stage.max(1), builder.host_target)
let build_compiler = builder.compiler(build_compiler_stage.max(1), builder.host_target);
// We also need the host stdlib to compile host code (proc macros/build scripts)
builder.std(build_compiler, builder.host_target);
build_compiler
};
builder.std(compiler, target);
compiler
Expand Down
16 changes: 16 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,22 @@ mod snapshot {
.render_steps(), @"[build] rustc 0 <host> -> cargo 1 <host>");
}

#[test]
fn build_cargo_cross() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("build")
.paths(&["cargo"])
.hosts(&[TEST_TRIPLE_1])
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 1 <host> -> cargo 2 <target1>
");
}

#[test]
fn dist_default_stage() {
let ctx = TestCtx::new();
Expand Down
Loading