Skip to content

Enforce in bootstrap that check must have stage at least 1 #143048

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

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Jun 26, 2025

This PR is another step towards https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Proposal.20to.20cleanup.20stages.20and.20steps.20after.20the.20redesign/with/523586917, this time dealing with x check.

It enforces the invariant that:

  • We check std stage N with rustc stage N
  • We check everything else stage N with rustc stage N - 1

It creates a single function that prepares a proper build compiler for checking something, and also adds snapshot tests for various common check steps. Some obsolete code was also removed.

The default check stage also becomes 1, for all profiles. I tested manually that x check std with download-ci-rustc still works and doesn't build rustc locally.

Subsumes #139170.

r? @ghost

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Jun 26, 2025
@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from f06e41e to aed5f23 Compare June 26, 2025 08:03
@Kobzol
Copy link
Contributor Author

Kobzol commented Jun 26, 2025

CC @jieyouxu (one of many heaps of bootstrap fixup commits I have in store 😆)

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jun 26, 2025

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

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 26, 2025
@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from aed5f23 to a36ee24 Compare June 26, 2025 14:29
@Kobzol
Copy link
Contributor Author

Kobzol commented Jun 26, 2025

Cross-compilation checks are now doing too much work, I need to take a look at how we can reduce that, because x check --stage1 with cross-compilation is no longer a thing.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

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

@Kobzol Kobzol force-pushed the bootstrap-check-stage-1 branch from a36ee24 to 22fb548 Compare July 1, 2025 15:43
@Kobzol Kobzol marked this pull request as ready for review July 1, 2025 15:44
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

This PR modifies src/bootstrap/defaults.

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

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

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

@Kobzol
Copy link
Contributor Author

Kobzol commented Jul 1, 2025

r? @jieyouxu

@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

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

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 3.096 Building wheels for collected packages: reuse
#16 3.098   Building wheel for reuse (pyproject.toml): started
#16 3.311   Building wheel for reuse (pyproject.toml): finished with status 'done'
#16 3.312   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132719 sha256=d2a2565e7037ad3883fb9337653f2e25bbb588534fbef3697286cbc26d1bf634
#16 3.312   Stored in directory: /tmp/pip-ephem-wheel-cache-4cv2rae2/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#16 3.314 Successfully built reuse
#16 3.315 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#16 3.711 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#16 3.712 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#16 DONE 3.8s

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

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

@jieyouxu jieyouxu removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 2, 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 like this a lot in general, it does feel much more self-consistent and coherent.

I left some questions/discussions for things that I wanted to double-check, but overall looks good!

Comment on lines -121 to -127
// We skip populating the sysroot in non-zero stage because that'll lead
// to rlib/rmeta conflicts if std gets built during this session.
if compiler.stage == 0 {
let libdir = builder.sysroot_target_libdir(compiler, target);
let hostdir = builder.sysroot_target_libdir(compiler, compiler.host);
add_to_sysroot(builder, &libdir, &hostdir, &stamp);
}
Copy link
Member

Choose a reason for hiding this comment

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

Remark: we really do have a lot of hacks for stage 0 std...

Comment on lines +183 to +185
self.stage.or(self
.built_by
.map(|compiler| if self.name == "std" { compiler.stage } else { compiler.stage + 1 }))
Copy link
Member

@jieyouxu jieyouxu Jul 2, 2025

Choose a reason for hiding this comment

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

Discussion: this makes me feel a bit uneasy, but I guess the logic here is: anything that's not the standard library should be considered a non-library artifact, and should be considered a product of the stage n (compiler, standard library) pair (and so gets numbered as the next stage)? I.e. reading back https://hackmd.io/QXj6LqntQTKPgm3uBuE-aA again, the core model is

stage corresponds to what gets built, not what is used to build it

(The following is me trying to make sure I understand this)


Let's call the (compiler, library) pair12

$$\mathbf{CLP}_{\mathrm{stage}} := \left\langle \text{compiler}_{\mathrm{stage}}, \text{library}_{\mathrm{stage}} \right\rangle$$

where the separation between stages is delineated by which $\mathrm{compiler}$ gets built. Then, by design, because the standard library is "special" and tightly coupled with the compiler, we fix the immediate standard library built by $\mathrm{compiler}_{\mathrm{stage}}$ to be of the same $\mathrm{stage}$, i.e. $\mathrm{library}_{\mathrm{stage}}$.

With the stage 0 redesign, we now have a nice straightforward "derivation chain" ($\longrightarrow$; artifacts can be used to build new artifacts) property where

$$\left\langle \text{compiler}_{\mathrm{stage}}, \text{library}_{\mathrm{stage}} \right\rangle \longrightarrow \left\langle \text{compiler}_{\mathrm{stage + 1}}, \text{library}_{\mathrm{stage + 1}} \right\rangle$$

actually holds even for $\mathrm{stage} = 0$.

However, for:

  • bootstrap tools
    Tools that are unconditionally built by the stage 0 $\mathbf{CLP}$, i.e. always depends on $\mathbf{CLP}_{0}$. Their stage numbering will be called $\mathrm{BootstrapTool}_{1}$, at least in the short-term.
  • host rustc tools
    Tools that depend on rustc_private and so on $\mathrm{compiler}_{\mathrm{stage}}$. This means that they will be numbered as $\mathrm{HostRustcTool}_{\mathrm{stage} + 1}$.
  • std tools
    Tools that depend on the whole $\mathbf{CLP}_{\mathrm{stage}}$, i.e. both $\mathrm{compiler}_{\mathrm{stage}}$, and $\mathrm{library}_{\mathrm{stage}}$. Similiarly, this means that they will be numbered as $\mathrm{StdTool}_{\mathrm{stage} + 1}$.

They then follow the general "what gets built" model (?).

mental-model

Footnotes

  1. I can't come up with a better name, it's not exactly a toolchain, neither is it a "complete" sysroot I think

  2. Not to be confused with the Chilean Peso.

Comment on lines +1295 to +1300
ctx.config("check")
.path("library")
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[check] rustc 1 <host> -> std 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.

Discussion (not for this PR): I do wonder how we would encode / fix the download-rustc logic here. I can see why the previous pretend-to-be- $\mathrm{CLP}_{2}$ scheme is very confusing.

Comment on lines +1411 to +1414
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[check] compiletest <host>
Copy link
Member

Choose a reason for hiding this comment

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

Remark: yes, this looks right 👍

&compiler.host,
&target,
);
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
Copy link
Member

Choose a reason for hiding this comment

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

Question: I don't remember, does the check macro support free args? I don't think this is actually equivalent, specifically the free_args part. Looking at src/tools/coverage-dump, it supports a --demangle flag:

if &args[1..] == &["--demangle"] {
return demangle();
}

Although, as the check step, this does not matter, right?

Comment on lines +252 to +253
// A small number of tools rely on in-tree standard
// library crates (e.g. compiletest needs libtest).
Copy link
Member

Choose a reason for hiding this comment

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

Nit: compiletest needs internal library feature from in-tree std (which could be different from stage 0 std), but no longer libtest.

Comment on lines 255 to 256
builder.std(build_compiler, host);
builder.std(build_compiler, target);
builder.ensure(Std::new(build_compiler, target));
Copy link
Member

@jieyouxu jieyouxu Jul 2, 2025

Choose a reason for hiding this comment

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

Question: wait, why is this different? For $\mathrm{stage} \ge 1$, isn't this equivalent? I.e.

if compiler.stage == 0 {
if target != compiler.host {
panic!(
r"It is not possible to build the standard library for `{target}` using the stage0 compiler.
You have to build a stage1 compiler for `{}` first, and then use it to build a standard library for `{target}`.
",
compiler.host
)
}
// We still need to link the prebuilt standard library into the ephemeral stage0 sysroot
self.ensure(StdLink::from_std(Std::new(compiler, target), compiler));
} else {
// This step both compiles the std and links it into the compiler's sysroot.
// Yes, it's quite magical and side-effecty.. would be nice to refactor later.
self.ensure(Std::new(compiler, target));
}

At this point, wouldn't we have already rejected invoking ./x check flow with $\mathrm{stage} = 0$?

Comment on lines +1303 to +1304
.targets(&[TEST_TRIPLE_1])
.hosts(&[TEST_TRIPLE_1])
Copy link
Member

Choose a reason for hiding this comment

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

Nit (tiny, just for consistency): can you swap targets() and hosts() around? Usually the ordering is hosts then targets right :D

@@ -48,7 +48,7 @@ ENV SCRIPT \
python3 ../x.py build src/tools/build-manifest && \
python3 ../x.py test --stage 0 src/tools/compiletest && \
python3 ../x.py check compiletest --set build.compiletest-use-stage0-libtest=true && \
python3 ../x.py check --stage 1 --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
python3 ../x.py check --stage 2 --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: actually, can you add a comment for this specifically that we're exercising cross-compile here, so --stage 1 isn't sufficient?

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) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants