Skip to content

bootstrap: Switch download-rustc back on by default for profile = library#154243

Open
jyn514 wants to merge 3 commits intorust-lang:mainfrom
ferrocene:jyn/library-defaults
Open

bootstrap: Switch download-rustc back on by default for profile = library#154243
jyn514 wants to merge 3 commits intorust-lang:mainfrom
ferrocene:jyn/library-defaults

Conversation

@jyn514
Copy link
Copy Markdown
Member

@jyn514 jyn514 commented Mar 23, 2026

See #142505 for context. There are actually three changes here, I left detailed commit messages.

@rustbot rustbot added 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 Mar 23, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 23, 2026

r? @clubby789

rustbot has assigned @clubby789.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@rust-log-analyzer

This comment has been minimized.

@jyn514 jyn514 force-pushed the jyn/library-defaults branch from acdf88b to b7aca74 Compare March 23, 2026 09:17
@rust-log-analyzer

This comment has been minimized.

@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented Mar 23, 2026

I'm not sure if we should propagate download-rustc in its current state, tbh. It has been hacky even before the stage0 redesign, and since then I have zero confidence that it works correctly, I expect that there are many issues with it, and I don't think we have the bandwidth at the moment to deal with them. Of course, some people are using download-rustc today and if it works for them, then that's fine. But enabling it by default when we know it's broken does not seem right.

I think that long-term the best solution is to rip out download-rustc completely and reimplement it in a maintainable way.

jyn514 added 3 commits March 23, 2026 10:32
Example output:
```
$ x b compiler
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.02s
NOTE: detected 3 modifications that could affect a build of rustc
- src/bootstrap/src/core/config/config.rs
- src/bootstrap/src/core/download.rs
- src/build_helper/src/git.rs
skipping rustc download due to `download-rustc = 'if-unchanged'`
Building stage1 compiler artifacts (stage0 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.72s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Build completed successfully in 0:00:05
```
Anything that can change there can also be changed in bootstrap.toml.
We have a separate check to make sure that the local config is
compatable with CI's config.
This was turned off because
`x test --set rust.download-rustc=true --stage=1 library/std` has been
broken for years. The workaround is simple and it's to remove
`test-stage = 1` from the `library` profile defaults.
@jyn514 jyn514 force-pushed the jyn/library-defaults branch from b7aca74 to 0dde8fd Compare March 23, 2026 09:32
@jyn514
Copy link
Copy Markdown
Member Author

jyn514 commented Mar 23, 2026

I wish you had brought this up a couple years ago when I proposed the stage 0 redesign :/ what would you consider to be a "more maintainable way"?

@jyn514
Copy link
Copy Markdown
Member Author

jyn514 commented Mar 23, 2026

If it helps, I'm happy to use my work time to maintain download-rustc so that the burden isn't falling on you and the rest of the bootstrap team.

@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented Mar 24, 2026

I wish you had brought this up a couple years ago when I proposed the stage 0 redesign :/ what would you consider to be a "more maintainable way"?

I only really learned how download-rustc is implemented only after the stage 0 redesign has landed 😅 To clarify, I think that the stage 0 redesign was a great thing, and I don't think that we should have blocked it on the redesign of download-rustc, I'm quite happy that we went with it. I also think that after the redesign, download-rustc is.. actually not needed that much? There are far less rebuilds happening today in bootstrap thanks to the stage 0 redesign. And the plan to use download-rustc to save CI time IMO doesn't really work, as we saw in practice, because there are just too many PRs that change something that could affect rustc, and we had several nasty cases where the cache-busting logic was producing more harm than utility.

But of course I also understand that for some users download-rustc offers benefit, so we should try to bring it to a reasonable state.

Now about the implementation. It is essentially implemented in a way where there are tens (I think last time I counted around 30?) of if conditions scattered across bootstrap, some at quite load-bearing places, that perform some custom logic to make download-rustc work. This was always very fragile, because that logic was sometimes assuming things like "at this point, we had to be called from step B that was called from step C, so we will do this special little thing that will make step D, which surely has to be called after this, work with download-rustc". As we do not have any tests for this (since it's very difficult to test), any changes around this logic lead to bugs that are quite hard to track down. Another problem that the implementation has is that it downloads a stage 2 rustc, but locally that download rustc is primarily used as a stage 1 rustc. That means that the ad-hoc logic has to do all sorts of hacks to convince bootstrap to treat the downloaded rustc as stage 1, which is... as robust as it sounds.

All this existed before the stage 0 redesign, but in a sense it was a bit better, both because of the previous staging logic, but mainly because we did not yet go through a major change of bootstrap for which the implementation was not prepared 😆 Onur did a heroic effort to make it work with the redesign, but it was essentially impossible to keep it working after we were making further changes to bootstrap. When I was systematically going over all steps last year to clean things up after the redesign, there were a few situations where things were only "working" because of two bugs that were cancelling each other out. I think that kind of sums the state it is in 😆 We were also seeing various bugs around download-rustc that were hard to fix without breaking something else, it was the classic bootstrap bug "whack-a-mole". That's where I thought that it would be better to just disable it by default until it is reimplemented.

The way I imagine it would be implemented is ideally by being centralized in a single place in bootstrap, so that we don't need a special case for download-rustc in every third bootstrap step just to make it work. To do that, we would ideally have to make download-rustc less "special". My plan for that was to get rid of all the stage renumbering hacks, which are IMO one of the biggest points here. I would like to do that by turning download-rustc into a stage 1 rustc, so that you can download an archive from CI that you unpack on disk, and it would behave in the same way as if you built rustc locally. And then, if someone actually needs stage 2 download-rustc for some use-cases, we would also add that to CI, either in the same component or in a separate component (there are clear trade-offs there around complexity and archive download size).

I started working on this redesign last year, but then I realized that there is another issue with download-rustc 😆 Which is that it is actually quite heavily intertwined with the implementation of download-ci-llvm, which is also scattered across the codebase, rather than being at a single place. So rewriting download-ci-llvm came into the critical path. I wanted to first refactor that to make it more like download-ci-gcc, which I tried to implement so that it is self-contained and doesn't bleed into other parts of bootstrap. This LLVM refactoring is still ongoing, I guess, I have some WIP branch of is somewhere, but I didn't have time to work on bootstrap properly for over half a year, so... :)

I also wrote about this last year on Zulip.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 7, 2026
…vements, r=Kobzol,jieyouxu

bootstrap: minor improvements to download-rustc

Split out from rust-lang#154243.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 7, 2026
…vements, r=Kobzol,jieyouxu

bootstrap: minor improvements to download-rustc

Split out from rust-lang#154243.
rust-timer added a commit that referenced this pull request Apr 7, 2026
Rollup merge of #154880 - ferrocene:jyn/download-rustc-improvements, r=Kobzol,jieyouxu

bootstrap: minor improvements to download-rustc

Split out from #154243.
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 7, 2026

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

github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 8, 2026
…r=Kobzol,jieyouxu

bootstrap: minor improvements to download-rustc

Split out from rust-lang/rust#154243.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants