Skip to content

Consolidate staging for rustc_private tools #144303

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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Jul 22, 2025

This PR continues bootstrap refactoring, this time by consolidating staging for Mode::ToolRustc tools. This refactoring was in the critical path of refactoring test/dist/clippy/doc steps, and getting rid of the rmeta/rlib sysroot copy, because tools are pervasive and they are being used for a lot of things in bootstrap.

The main idea is to explicitly model the fact that a stage N Mode::ToolRustc tool always works with two different compilers:

  • Stage N-1 rustc (build_compiler) builds stage N rustc (target_compiler)
  • Rlib artifacts from stage N rustc are copied to the sysroot of stage N-1 rustc
  • Stage N-1 rustc builds the (stage N) tool itself, the tool links to the rlib artifacts of the stage N rustc

Before, the code often used compiler, which meant sometimes the build compiler, sometimes the target compiler, and sometimes neither (looking at you, download-rustc). This is especially annoying when you get to a situation where you have an install step that invokes a dist step that invokes a tool build step, where some compiler is being propagated through, without it being clear what does that compiler represent. This refactoring hopefully makes that clearer and more explicit. It also gets rid of a few builder.ensure(Rustc(...)) calls within bootstrap, which is always nice.

Rustdoc needs to be handled a bit specially, because it acts as a compiler itself, I documented that in the changes.

It wasn't practical to do these refactorings in multiple PRs, so I did it all in one PR. The meat of the change is 9ee6d1c.

I tested manually that x build rustdoc and x build miri still works even with download-rustc, although I cannot promise any extra support for download-rustc, IMO we will just have to reimplement it from scratch in a different way.

As usually, I did some drive-by refactorings to bootstrap, trying to document and clarify things, add more step metadata and tests.

Since these changes broke Cargo, which was incorrectly using Mode::ToolRustc, I also changed cargo to ToolTarget in this PR.

Best reviewed commit-by-commit (note that I renamed link_compiler to target_compiler, in accordance to the rest of bootstrap, in the last commit).

r? @jieyouxu

try-job: x86_64-gnu-aux

@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2025

jieyouxu is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 22, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jul 23, 2025

☔ The latest upstream changes (presumably #143412) made this pull request unmergeable. Please resolve the merge conflicts.

@Kobzol Kobzol force-pushed the bootstrap-tool-cleanup branch from 2e63ce8 to 7bf4a1a Compare July 23, 2025 14:14
@jieyouxu
Copy link
Member

Will start looking at this today, might take me some time to get through.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good overall. You can r=me after comment nit.

@jieyouxu
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 28, 2025
@Kobzol
Copy link
Member Author

Kobzol commented Jul 28, 2025

@bors r=jieyouxu

@bors
Copy link
Collaborator

bors commented Jul 28, 2025

📌 Commit 7bf4a1a has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 28, 2025
@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

💔 Test failed (CI). Failed jobs:

@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Member Author

Kobzol commented Jul 29, 2025

Uaah, some issues with cargo. I had a branch stacked on top of this that also fixes up Cargo, but there were some additional issues with cargo tests.. well, let's land it here, these changes are really hard to do piecemeal..

@Kobzol
Copy link
Member Author

Kobzol commented Jul 29, 2025

@bors try

@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

⌛ Trying commit c4fef48 with merge 2802fd0

To cancel the try build, run the command @bors try cancel.

rust-bors bot added a commit that referenced this pull request Jul 29, 2025
Consolidate staging for `rustc_private` tools

try-job: x86_64-gnu-aux
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

💔 Test failed (CI). Failed jobs:

@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Member Author

Kobzol commented Jul 29, 2025

@bors try

@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

⌛ Trying commit 0438a46 with merge 2f3f0ce

To cancel the try build, run the command @bors try cancel.

rust-bors bot added a commit that referenced this pull request Jul 29, 2025
Consolidate staging for `rustc_private` tools

try-job: x86_64-gnu-aux
@rust-log-analyzer

This comment has been minimized.

@Kobzol Kobzol force-pushed the bootstrap-tool-cleanup branch from 0438a46 to f731cd1 Compare July 29, 2025 11:36
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-aux failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

💔 Test failed (CI). Failed jobs:

@Kobzol
Copy link
Member Author

Kobzol commented Jul 29, 2025

@bors try

rust-bors bot added a commit that referenced this pull request Jul 29, 2025
Consolidate staging for `rustc_private` tools

try-job: x86_64-gnu-aux
@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

⌛ Trying commit f731cd1 with merge 180dfb2

To cancel the try build, run the command @bors try cancel.

@rust-bors
Copy link

rust-bors bot commented Jul 29, 2025

☀️ Try build successful (CI)
Build commit: 180dfb2 (180dfb2915c406778b9b7484f8ac8e564f5a0d5d, parent: 552904134b564a74489db50aebe7070fdcce895c)

@Kobzol
Copy link
Member Author

Kobzol commented Jul 29, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 29, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions regarding cargo...

Comment on lines +241 to +242
// FIXME: support testing stage 0 cargo?
assert!(run.builder.top_stage > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: should we just exit here (gracefully) instead of an assert panic? Or rather, declare this case unsupported, as otherwise the cargo test suite would have to work with both possibly-beta rustc and in-tree rustc?

Comment on lines +853 to +857
// Cargo is compilable with a stable compiler, but since we run in bootstrap,
// with RUSTC_BOOTSTRAP being set, some "clever" build scripts enable specialization
// based on this, which breaks stuff. We thus have to explicitly allow these features
// here.
allow_features: "min_specialization,specialization",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭 Do we know which ones? ahash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, ahash and friends.

Comment on lines +1609 to +1610
[build] rustc 0 <host> -> cargo 1 <host>
[build] rustdoc 0 <host>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question [CARGO_TEST_STAGING 1/2]: there's some funky staging going on with the staging, I think? Usually ./x test tests/ui --stage=1 means to test xxx using the stage 1 (compiler, library). However, ./x test cargo here means... --stage=0?

Comment on lines +1625 to +1626
[build] rustc 1 <host> -> cargo 2 <host>
[build] rustdoc 1 <host>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question [CARGO_TEST_STAGING 2/2]: but here, ./x test cargo --stage=2 doesn't build stage 2 (compiler, library) 🤔

@jieyouxu
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants