Skip to content

bootstrap: Don't trigger an unnecessary LLVM build from check builds #144011

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 2 commits into
base: master
Choose a base branch
from

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Jul 16, 2025

Coming back to r-l/r development after a few weeks away, I found a major regression in my dev workflows: running x check compiler (either manually or via rust-analyzer) would have the side-effect of building LLVM, even though that shouldn't be necessary.

For my main build directory this would be a minor annoyance, but for my separate rust-analyzer build directory it's a huge problem because it causes a completely separate build of LLVM, which takes a long time and should be completely unnecessary.


After some investigation, I tracked down the problem to the can_skip_build check in this code:

// Note that this is disabled if LLVM itself is disabled or we're in a check
// build. If we are in a check build we still go ahead here presuming we've
// detected that LLVM is already built and good to go which helps prevent
// busting caches (e.g. like #71152).
if builder.config.llvm_enabled(target) {
let building_is_expensive =
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target, false)
.should_build();
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == build_stage;
let should_skip_build = building_is_expensive && can_skip_build;
if !should_skip_build {
rustc_llvm_env(builder, cargo, target)
}
}

Historically, this would skip the LLVM build for stage 0 check builds. But after the recent stage 0 std redesign and some associated check stage renumbering (e.g. #143048), the condition builder.top_stage == build_stage is now false, because top_stage is 1 (due to the renumbering) but build_stage is 0 (because a “stage 1” non-library check build still uses the stage 0 compiler).


Because this is a critical contributor roadblock for me, I have tried to fix this in a relatively narrow way. It's possible that all of this surrounding logic could be greatly simplified (especially in light of the stage redesign changes), but I didn't want this fix to be held back by scope creep.


(Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Bootstrap.20incorrectly.20building.20LLVM.20for.20check.20builds/near/528991035)

@Zalathar Zalathar added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) A-contributor-roadblock Area: Makes things more difficult for new or seasoned contributors to Rust labels Jul 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 16, 2025
@Zalathar
Copy link
Contributor Author

r? bootstrap

@rustbot rustbot assigned albertlarsan68 and unassigned Kobzol Jul 16, 2025
@rust-log-analyzer

This comment has been minimized.

@Zalathar
Copy link
Contributor Author

Hmm, in addition to those snapshot failures, I'm also seeing LLVM builds in subsequent manual testing. Mysterious.

@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 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Zalathar Zalathar force-pushed the check-compiler-no-llvm branch from 444b227 to 2aafc40 Compare July 16, 2025 08:14
@Zalathar
Copy link
Contributor Author

Updated snapshot tests, several of which included the inappropriate LLVM build (diff).

@rust-log-analyzer

This comment has been minimized.

@Zalathar Zalathar force-pushed the check-compiler-no-llvm branch from 2aafc40 to 857b6a2 Compare July 16, 2025 09:33
@rust-log-analyzer

This comment has been minimized.

@Zalathar
Copy link
Contributor Author

Having to deal with PR CI failures for i686-pc-windows-gnu feels like I am being pranked. Can't wait to see that target further demoted to oblivion.

@Zalathar Zalathar force-pushed the check-compiler-no-llvm branch from 857b6a2 to bf75472 Compare July 16, 2025 10:54
@Zalathar
Copy link
Contributor Author

@bors2 try jobs=x86_64-pc-windows-gnu

@rust-bors
Copy link

rust-bors bot commented Jul 16, 2025

⌛ Trying commit bf75472 with merge 635dd0f

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

rust-bors bot added a commit that referenced this pull request Jul 16, 2025
bootstrap: Don't trigger an LLVM build from check builds using the stage 0 compiler

Coming back to r-l/r development after a few weeks away, I found a major regression in my dev workflows: running `x check compiler` (either manually or via rust-analyzer) would have the side-effect of building LLVM, even though that shouldn't be necessary.

For my main build directory this would be a minor annoyance, but for my separate rust-analyzer build directory it's a huge problem because it causes a completely separate build of LLVM, which takes a long time and should be completely unnecessary.

---

After some investigation, I tracked down the problem to the `can_skip_build` check in this code:

https://github.com/rust-lang/rust/blob/3014e79f9c8d5510ea7b3a3b70d171d0948b1e96/src/bootstrap/src/core/build_steps/compile.rs#L1382-L1396

Historically, this would skip the LLVM build for stage 0 check builds. But after the recent stage 0 std redesign and some associated check stage renumbering (e.g. #143048), the condition `builder.top_stage == build_stage` is now false, because `top_stage` is 1 (due to the renumbering) but `build_stage` is 0 (because a “stage 1” non-library check build still uses the stage 0 compiler).

---

Because this is a critical contributor roadblock for me, I have tried to fix this in a relatively narrow way. It's possible that all of this surrounding logic could be greatly simplified (especially in light of the stage redesign changes), but I didn't want this fix to be held back by scope creep.

---

(Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Bootstrap.20incorrectly.20building.20LLVM.20for.20check.20builds/near/528991035)

r? Kobzol
try-job: x86_64-pc-windows-gnu
@rust-bors
Copy link

rust-bors bot commented Jul 16, 2025

💔 Test failed

@Zalathar
Copy link
Contributor Author

@bors2 try jobs=x86_64-mingw-1,x86_64-mingw-2

@rust-bors
Copy link

rust-bors bot commented Jul 16, 2025

⌛ Trying commit bf75472 with merge ddfea62

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

rust-bors bot added a commit that referenced this pull request Jul 16, 2025
bootstrap: Don't trigger an LLVM build from check builds using the stage 0 compiler

Coming back to r-l/r development after a few weeks away, I found a major regression in my dev workflows: running `x check compiler` (either manually or via rust-analyzer) would have the side-effect of building LLVM, even though that shouldn't be necessary.

For my main build directory this would be a minor annoyance, but for my separate rust-analyzer build directory it's a huge problem because it causes a completely separate build of LLVM, which takes a long time and should be completely unnecessary.

---

After some investigation, I tracked down the problem to the `can_skip_build` check in this code:

https://github.com/rust-lang/rust/blob/3014e79f9c8d5510ea7b3a3b70d171d0948b1e96/src/bootstrap/src/core/build_steps/compile.rs#L1382-L1396

Historically, this would skip the LLVM build for stage 0 check builds. But after the recent stage 0 std redesign and some associated check stage renumbering (e.g. #143048), the condition `builder.top_stage == build_stage` is now false, because `top_stage` is 1 (due to the renumbering) but `build_stage` is 0 (because a “stage 1” non-library check build still uses the stage 0 compiler).

---

Because this is a critical contributor roadblock for me, I have tried to fix this in a relatively narrow way. It's possible that all of this surrounding logic could be greatly simplified (especially in light of the stage redesign changes), but I didn't want this fix to be held back by scope creep.

---

(Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Bootstrap.20incorrectly.20building.20LLVM.20for.20check.20builds/near/528991035)

r? Kobzol
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
@Zalathar Zalathar changed the title bootstrap: Don't trigger an LLVM build from check builds using the stage 0 compiler bootstrap: Don't trigger an unnecessary LLVM build from check builds Jul 16, 2025
@Zalathar
Copy link
Contributor Author

Historical note: The existing stage-sensitive check was introduced back in #110122.

From looking at the context, and considering the many changes that have been made since, I think it should be fine to remove the stage-number check.

@rust-bors
Copy link

rust-bors bot commented Jul 16, 2025

☀️ Try build successful (CI)
Build commit: ddfea62 (ddfea62a5c617a7e19b1257e31a91974fdde3605, parent: f21fbac535ab2c3bc50db20547f4d48477357103)

@mati865
Copy link
Member

mati865 commented Jul 16, 2025

Having to deal with PR CI failures for i686-pc-windows-gnu feels like I am being pranked. Can't wait to see that target further demoted to oblivion.

TBH that error would happen on any Windows target other than *-windows-gnullvm ones, so *-windows-msvc would also fail. i686-pc-windows-gnu just happens to be checked by the tidy job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-roadblock Area: Makes things more difficult for new or seasoned contributors to Rust 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