Skip to content

Enforce in bootstrap that dist and install must have stage at least 1 #145472

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

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Aug 15, 2025

This is a continuation of my efforts to fix staging in bootstrap after the stage0 redesign. This PR gets rid of all compiler_for usages in the dist steps 🎉 The only remaining usages are in the test steps, which are my next goal, and which will be the final boss.. both because they are quite tricky, and because most of the the rest of the steps have been already fixed.

The changes are relatively straightforward, x dist defaults to stage 2, so in that case we want to use a stage 1 build compiler for everything (except stdlib, but we usually use it even there because of uplifting).

What I didn't fix yet are the docs steps, because they are very implicit right now, and fixing them deserves its own PR.

The first commit reverts the tests that I accidentally removed in #145340 🤦‍♂️ I did it in this PR to avoid further git conflicts..

Best reviewed commit-by-commit.

r? @jieyouxu

try-job: dist-i686-linux
try-job: dist-armhf-linux
try-job: dist-x86_64-linux
try-job: dist-x86_64-msvc
try-job: dist-apple-various
try-job: dist-x86_64-apple
try-job: x86_64-msvc-2

@rustbot rustbot added A-bootstrap-stamp Area: bootstrap stamp logic 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 Aug 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 15, 2025

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as outdated.

@rustbot

This comment has been minimized.

@Kobzol
Copy link
Member Author

Kobzol commented Aug 20, 2025

@bors try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 20, 2025
Enforce in bootstrap that dist and install must have stage at least 1

try-job: dist-i686-linux
try-job: dist-armhf-linux
try-job: dist-x86_64-linux
try-job: dist-x86_64-msvc
try-job: dist-apple-various
try-job: dist-x86_64-apple
@rust-bors
Copy link

rust-bors bot commented Aug 20, 2025

☀️ Try build successful (CI)
Build commit: f9464d8 (f9464d83262ce8f495c129d9e1059a8d108f3df9, parent: f605b57042ffeb320d7ae44490113a827139b766)

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, the other changes I'm on board with. The only bit I'm not sure is the rust-std build optimization, IMO it's not worth the hack to introduce a special case. WDYT?

let sysroot = self.sysroot;
let dst = sysroot.join("lib/rustlib/etc");
t!(fs::create_dir_all(&dst));
let cp_debugger_script = |file: &str| {
builder.install(&builder.src.join("src/etc/").join(file), &dst, FileType::Regular);
};
if host.contains("windows-msvc") {
if target.contains("windows-msvc") {
Copy link
Member

Choose a reason for hiding this comment

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

Remark: I really hope in the future we have some way to share an in-tree structured target spec with rustc... Target tuple string matching feels bad every time I see it 😔

Comment on lines 782 to 783
"Note: stage {top_stage} library for `{}` would be uplifted from stage 1, so stage was downgraded from {top_stage} to 1 to avoid needless compiler build(s)",
run.target
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: maybe say

so build compiler stage was downgraded from {top_stage} to 1 to avoid needless compiler build(s)

?

Comment on lines 772 to 776
// This is a build time optimization for running just `x dist rust-std` (without
// `x dist rustc`).
// If we know that we will be uplifting a stage2+ library from stage 1 anyway,
// there is no point in building a stage2 rustc, which will then not do anything (because
// the stdlib will be uplifted).
Copy link
Member

Choose a reason for hiding this comment

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

Discussion:

  • Who's actually using ./x dist rust-std specifically? Usually, we would be distributing a toolchain together, right? Or at least both compiler and std?
  • I feel uneasy about doing this build optimization, it feels rather "special" (hacky) especially when this is the dist flow. Could we get away with just doing the straightforward ™️ build? I feel like we should just do the "useless" stage 2 rustc build, and then use the same stage 2 std uplifting logic, instead of doing this special casing.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are some CI jobs that do ./x dist --host='' --target i686-unknown-linux-gnu,aarch64-unknown-linux-gnu. But I confirmed it produced the same steps with/without this "optimization".

I agree, let's get rid of it.

@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 Aug 20, 2025
@Kobzol
Copy link
Member Author

Kobzol commented Aug 20, 2025

Agreed, removed the special case, and fixed one doc bug that I found when testing the x dist cross-compilation scenarios (the docs dist steps just invoke all default doc steps, which I'm planning to change, so it exposed this issue. Not sure why we didn't hit it on CI...).

@Kobzol
Copy link
Member Author

Kobzol commented Aug 20, 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 Aug 20, 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.

Thanks!

@jieyouxu
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Aug 20, 2025

📌 Commit 7da375e has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2025
@samueltardieu
Copy link
Member

I can't seem to create rollups right now, so prefer this rollup=never over the next rollup=iffy that would run alone.

@bors p=1

bors added a commit that referenced this pull request Aug 22, 2025
Enforce in bootstrap that dist and install must have stage at least 1

This is a continuation of my efforts to fix staging in bootstrap after the stage0 redesign. This PR gets rid of all `compiler_for` usages in the `dist` steps 🎉 The only remaining usages are in the `test` steps, which are my next goal, and which will be the final boss.. both because they are quite tricky, and because most of the the rest of the steps have been already fixed.

The changes are relatively straightforward, `x dist` defaults to stage 2, so in that case we want to use a stage 1 build compiler for everything (except stdlib, but we usually use it even there because of uplifting).

What I didn't fix yet are the docs steps, because they are *very* implicit right now, and fixing them deserves its own PR.

The first commit reverts the tests that I accidentally removed in #145340 🤦‍♂️ I did it in this PR to avoid further git conflicts..

Best reviewed commit-by-commit.

r? `@jieyouxu`

try-job: dist-i686-linux
try-job: dist-armhf-linux
try-job: dist-x86_64-linux
try-job: dist-x86_64-msvc
try-job: dist-apple-various
try-job: dist-x86_64-apple
@rustbot
Copy link
Collaborator

rustbot commented Aug 23, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Kobzol
Copy link
Member Author

Kobzol commented Aug 23, 2025

@bors try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 23, 2025
Enforce in bootstrap that dist and install must have stage at least 1

try-job: dist-i686-linux
try-job: dist-armhf-linux
try-job: dist-x86_64-linux
try-job: dist-x86_64-msvc
try-job: dist-apple-various
try-job: dist-x86_64-apple
try-job: x86_64-msvc-2
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 23, 2025

💔 Test for ba8e5de failed: CI. Failed jobs:

@Kobzol
Copy link
Member Author

Kobzol commented Aug 23, 2025

Well this was a detective hunt.. Luckily I could reproduce it locally. Because of the changes of this PR, the dist::Std step is now invoked twice during x dist (once with the stage1 build_compiler, and once with the stage2 build_compiler). The actual std build is reused, but the tarball is generated and compressed twice.

Since recently, bootstrap is caching all command executions by default. Since we were caching the rust-installer invocation, which was extracting the rust-std tarball twice, it wasn't executed for the second time, and nothing was thus created on disk, which triggered assertions in bootstrap.

I removed caching for all tool invocations.

@Kobzol
Copy link
Member Author

Kobzol commented Aug 23, 2025

@bors try

rust-bors bot added a commit that referenced this pull request Aug 23, 2025
Enforce in bootstrap that dist and install must have stage at least 1

try-job: dist-i686-linux
try-job: dist-armhf-linux
try-job: dist-x86_64-linux
try-job: dist-x86_64-msvc
try-job: dist-apple-various
try-job: dist-x86_64-apple
try-job: x86_64-msvc-2
@rust-bors

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 23, 2025

☀️ Try build successful (CI)
Build commit: 7fcf301 (7fcf30178209c10ea8218e69a3c2f2d02fd368dc, parent: 5b6ceb58f800079f8c59f5194b5db08924693927)

@Kobzol
Copy link
Member Author

Kobzol commented Aug 23, 2025

@rustbot ready

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.

Mostly looks good, just two questions

View changes since this review

Comment on lines +794 to +797
// It's possible that std was uplifted and thus built with a different build compiler
// So we need to read the stamp that was actually generated when std was built
let stamp =
builder.std(build_compiler, target).expect("Standard library has to be built for dist");
Copy link
Member

Choose a reason for hiding this comment

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

Remark: sneaky...

Comment on lines +835 to +838
// We currently always ship a stage 2 rustc-dev component, so we build it with the
// stage 1 compiler. This might change in the future.
// The precise stage used here is important, so we hard-code it.
build_compiler: run.builder.compiler(1, run.builder.config.host_target),
Copy link
Member

Choose a reason for hiding this comment

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

Question: hm, does this mean that ./x dist rustc-dev --stage=1 silently does the wrong thing without it being a hard error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. rustc-dev only works for stage 2, nothing else, currently. I can add a hard error if you want.

Copy link
Member

@jieyouxu jieyouxu Aug 24, 2025

Choose a reason for hiding this comment

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

I think, at least for the moment, we should hard error instead of ignoring an explicitly requested stage for this.

Though that makes the overall ./x dist awkward... because what if someone writes ./x dist --stage=1?

run.builder.config.host_target,
run.target,
),
build_compiler: run.builder.compiler(1, run.builder.config.host_target),
Copy link
Member

Choose a reason for hiding this comment

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

Question: same thing, does this silently do the wrong thing if someone specifies ./x dist analysis --stage=1? Not that this does much in the first place...

Comment on lines +1585 to +1586
// Do not cache tool invocations, as they can have side effects
cmd.do_not_cache();
Copy link
Member

Choose a reason for hiding this comment

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

Remark: hmm, this is rather sneaky...

Copy link
Member Author

Choose a reason for hiding this comment

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

When we implemented command caching, I was worried about bugs being caused by it, but I had no "proof". This PR showed that such bugs can indeed happen, and that it is VERY annoying to debug. This would be a permanent footgun, so I will instead change the default and make caching opt-in, not opt-out.

@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 Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bootstrap-stamp Area: bootstrap stamp logic 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