Commit graph

7811 commits

Author SHA1 Message Date
Jacob Pratt
62582eb78e
Rollup merge of #145390 - joshtriplett:rustc-diag-value-earlier, r=lcnr
Shorten some dependency chains in the compiler

(I recommend reviewing this commit by commit.)

One of the long dependency chains in the compiler is:
- Many things depend on `rustc_errors`.
- `rustc_errors` depended on many things prior to this PR, including `rustc_target`, `rustc_type_ir`, `rustc_hir`, and `rustc_lint_defs`.
- `rustc_lint_defs` depended on `rustc_hir` prior to this PR.
- `rustc_hir` depends on `rustc_target`.
- `rustc_target` is large and takes a while.

This PR breaks that chain, through a few steps:
- The `IntoDiagArgs` trait, from `rustc_errors`, moves earlier in the dependency chain. This allows `rustc_errors` to stop depending on a pile of crates just to implement `IntoDiagArgs` for their types.
- Split `rustc_hir_id` out of `rustc_hir`, so crates that just need `HirId` and similar don't depend on all of `rust_hir` (and thus `rustc_target`).
- Make `rustc_lint_defs` stop depending on `rustc_hir`.
2025-08-21 01:12:17 -04:00
Jacob Pratt
b0dd772ce1
Rollup merge of #145256 - GuillaumeGomez:bootstrap-test-codegen-backend, r=Kobzol,bjorn3
Add new `--test-codegen-backend` bootstrap option

This new bootstrap command line flag allows to do:

```shell
./x.py test tests/ui/intrinsics/panic-uninitialized-zeroed.rs --stage 1 -j8 --test-codegen-backend gcc
```

This is the last step before running it into the CI.

Supersedes rust-lang/rust#144687.

r? ``````@Kobzol``````
2025-08-21 01:12:15 -04:00
Josh Triplett
e46ec741a1 Update test output for change to number of crates 2025-08-20 15:03:57 -07:00
bors
e8a792daf5 Auto merge of #145645 - Kobzol:uplift-fix, r=jieyouxu
Fix rustc uplifting (take two)

The rustc uplifting logic is really annoying.. https://github.com/rust-lang/rust/pull/145557 was not enough to fix it.

Consider https://github.com/rust-lang/rust/issues/145534#issuecomment-3201868888: in this situation, we do a stage3 build of a cross-compiled rustc (it happens because we run `x test --stage 2`, which mistakenly builds a stage3 rustc, but it doesn't matter what casuses it, what matters is that the stage3 build isn't working).

Currently, a stage3 cross-compiled build of rustc works like this:
1) stage0 (host) -> stage1 (host)
2) stage1 (host) -> stage2 (host)
3) stage2 (host) -> stage3 (target)

The problem is that in the uplifting logic, I assumed that we will have a stage2 (target) rustc available, which we can uplift. And that would indeed be an ideal solution. But currently, we will actually build a stage2 (*host*) rustc, and only then start the cross-compilation. So the uplifting is broken.

I spend a couple of hours trying to fix this, and do the uplifting "from the other direction", so that already when we assemble a stage3 rustc, we notice that an uplift should happen, and we only build stage1 (host) rustc, which also helps avoid one needless rustc build. However, this was relatively complicated and would require larger changes that I was not confident landing at this time.

So instead I decided to do a much simpler fix, and just disable rustc uplifting when cross-compiling. Since we currently do the `stage2 (host) -> stage3 (target)` step, it should not actually affect stage3 cross-compiled builds in any way (I hope..), and should only affect stage4+ builds, about which I don't really care (the only change there should be more rustc builds). For normal builds, the stage2 host rustc should (hopefully) always be present, so we shouldn't run into this issue.

Eventually, I would like to remove rustc uplifting completely. However, `x test --stage 2` on CI still currently builds a stage3 rustc for some reason, and if we removed uplifting completely, even for non-cross-compiled builds, that would cause an additional rustc build, and that's not great. So for now let's just allow uplifting for non-cross-compiled builds.

Fixes rust-lang/rust#145534.

r? `@jieyouxu`
2025-08-20 12:10:34 +00:00
Guillaume Gomez
e4cdc0f56e Split compiletest --codegen-backend into two options --default-codegen-backend and --override-codegen-backend 2025-08-20 12:19:20 +02:00
Guillaume Gomez
5a451b8c1c Add new --test-codegen-backend bootstrap option 2025-08-20 12:19:19 +02:00
Jakub Beránek
f254075e95
Disable rustc uplifting during cross-compilation 2025-08-20 08:52:14 +02:00
bors
f605b57042 Auto merge of #145601 - jieyouxu:rollup-t5mbqhc, r=jieyouxu
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#145538 (bufreader::Buffer::backshift: don't move the uninit bytes)
 - rust-lang/rust#145542 (triagebot: Don't warn no-mentions on subtree updates)
 - rust-lang/rust#145549 (Update rust maintainers in openharmony.md)
 - rust-lang/rust#145550 (Avoid using `()` in `derive(From)` output.)
 - rust-lang/rust#145556 (Allow stability attributes on extern crates)
 - rust-lang/rust#145560 (Remove unused `PartialOrd`/`Ord` from bootstrap)
 - rust-lang/rust#145568 (ignore frontmatters in `TokenStream::new`)
 - rust-lang/rust#145571 (remove myself from some adhoc-groups and pings)
 - rust-lang/rust#145576 (Add change tracker entry for `--timings`)
 - rust-lang/rust#145578 (Add VEXos "linked files" support to `armv7a-vex-v5`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-19 23:52:06 +00:00
Jakub Beránek
0079da4862
Add snapshot tests for stage 3 compiler builds 2025-08-19 23:36:43 +02:00
许杰友 Jieyou Xu (Joe)
4a4247adc8
Rollup merge of #145576 - jieyouxu:bootstrap-timings, r=Kobzol
Add change tracker entry for `--timings`

Follow-up to rust-lang/rust#145379. Forgor when reviewing.

r? `@Kobzol`
2025-08-19 19:50:07 +08:00
许杰友 Jieyou Xu (Joe)
07518a7a25
Rollup merge of #145560 - Kobzol:bootstrap-remove-ord, r=jieyouxu
Remove unused `PartialOrd`/`Ord` from bootstrap

It was just wasting compile-time. There is one remaining "old" bootstrap test that uses the `Ord` impl on one test step, I'll remove that later.
2025-08-19 19:50:04 +08:00
许杰友 Jieyou Xu (Joe)
caabaf77ab
Rollup merge of #145490 - Kobzol:bootstrap-io-tracing, r=jieyouxu
Trace some basic I/O operations in bootstrap

When working on removing the rmeta sysroot copies, it is quite difficult to figure out *why* was did a certain file appear in a given directory. This should help with that a bit.

r? `@jieyouxu`
2025-08-19 19:45:34 +08:00
许杰友 Jieyou Xu (Joe)
b1a7bac798
Rollup merge of #145452 - Kobzol:bootstrap-strip, r=jieyouxu
Do not strip binaries in bootstrap everytime if they are unchanged

I was profiling bootstrap to figure out why a no-op build takes upward of two seconds on my machine. I found that half of that is Cargo (which is mostly unavoidable) and the rest (~900ms) is running strip. We don't need to restrip already stripped binaries all the time.

r? `@jieyouxu`
2025-08-19 19:45:32 +08:00
Stuart Cook
3ced940a31
Rollup merge of #145565 - Kobzol:bootstrap-ci-print-error, r=jieyouxu
Improve context of bootstrap errors in CI

Inspired by https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/printing.20test.20suite.20name.20by.20default/with/534920583, this PR attempts to improve the context displayed when a bootstrap invocation fails in CI.

Since https://github.com/rust-lang/rust/pull/145261, we now see the latest started step when a failure occurs. However, we can go further.

1) The first commit prints the actual executed bootstrap invocation command arguments when bootstrap ends. Since CI jobs often run multiple bootstrap commands, this makes it easier to figure out which one of them failed (before it was annoying having to search for that in CI logs). Because bootstrap doesn't really use `Result`s much, and most of them time it ends with the `detail_exit` function, which YOLOs `std::process::exit(...)`, I added the print there.
2) Adds `#[track_caller]` to a few bootstrap Cargo builder functions. This makes the log that we print when a command fails more accurate:
```
2025-08-16T18:18:51.6998201Z Command ... failed ...
2025-08-16T18:18:51.7003653Z Created at: src/bootstrap/src/core/builder/cargo.rs:423:33
2025-08-16T18:18:51.7004032Z Executed at: src/bootstrap/src/core/build_steps/doc.rs:933:26
```
Before, the `cargo.rs:XYZ` location wasn't very useful.
3) Is the most wild thing (I'll revert if you find it too magical). We store the step stack of the currently active `Builder` instance in a global variable, and when bootstrap exits with a failure, we print the stack, to make it easier to find out what was happening when a failure occurred. We could print an actual captured `Backtrace`, but I think that would be too much information in the common case. We now pass `RUST_BACKTRACE=1` on CI, so if bootstrap actually crashes unexpectedly, we would see the stacktrace.

The end of the bootsrap failure log in CI now looks like this now:

```
Bootstrap failed while executing `x build library`

---BOOTSTRAP step stack start---

Assemble { target_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu, forced_compiler: false } }
Rustc { target: x86_64-unknown-linux-gnu, build_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, crates: [] }

---BOOTSTRAP step stack end---
```

r? `@jieyouxu`
2025-08-19 14:18:28 +10:00
Stuart Cook
cf2f50e332
Rollup merge of #145557 - Kobzol:rustc-link-fix, r=jieyouxu
Fix uplifting in `Assemble` step

In https://github.com/rust-lang/rust/pull/145310, I removed [this line](https://github.com/rust-lang/rust/pull/145310/files#diff-5a1e05f2688d271039171a547d407d0c8a96715ee64d35562fc76b4c9a874303L2109), which adjusted the stage of the build compiler if an uplift has happened. This broke stage3+ uplifted rustc builds (https://github.com/rust-lang/rust/issues/145534). I could swear I tested this in the PR, but somehow I missed it.

Instead of keeping the original returned stage, I made it more explicit by returning the actually used `build_compiler` from the `Rustc` step, and then use that in the `Assemble` step.

The changes to `RustcLink` were needed to fix `ui-fulldeps`, which apparently build a stage3 rustc, because I haven't fixed the test steps yet 😅

Hopefully we might be able to remove `RustcLink` if the approach from https://github.com/rust-lang/rust/pull/144252 will work.

Should fix https://github.com/rust-lang/rust/issues/145534.

r? ``@jieyouxu``
2025-08-19 14:18:26 +10:00
Stuart Cook
b9fdc6b01a
Rollup merge of #144252 - Kobzol:rmeta-sysroot, r=jieyouxu
Do not copy .rmeta files into the sysroot of the build compiler during check of rustc/std

Before, when bootstrap did a check build of rustc stage N (with a build compiler that was stage N-1), it automatically copied the resulting `.rmeta` artifacts into the sysroot of the stage N-1 build compiler, so that stage N `rustc_private` tools such as `miri` could be compiled using the stage N-1 build compiler. This has a number of issues:

- It was done unconditionally, even if no `rustc_private` tools were actually built.
- If we did a check and a build of the same stage compiler in the same bootstrap invocation, the generated rmeta and rlib files could clash. This is also why you can see that `check::Std` actually doesn't copy the artifacts anymore (which forced us to build std instead of just checking it in a bunch of `Check` steps).
- It was polluting the sysroot of the build compiler. This is especially annoying for the stage 0 compiler, because we are forced to create an artificial sysroot for it, so that we can copy new stuff into it.
- It was very implicit in bootstrap.

Based on suggestions by ```@cuviper``` and ```@bjorn3,``` I tried to change how this behaves. Instead of copying the rmeta artifacts into the sysroot of the build compiler (from where they would be loaded implicitly), they are now stored in a separate transient bootstrap build directory, and they are then explicitly passed *only* when checking `rustc_private` tools using the `-L` flag. The flags are passed out-of-band through our rustc wrapper, to avoid invalidating the build cache. This is the first commit.

The second commit does the same for std. For a few months, we used to build std instead of just checking it when doing a cross-compile check of something that required std, this now fixes it. There is still the previous ordering requirement though, that `check::Std` has to be executed as the last check step, or rather nothing that requires checked std should be executed *after* it, because it will run into rmeta/rlib duplications (4fa90ef799/src/bootstrap/src/core/builder/mod.rs (L1066)). I tried to fix in this PR, but it quickly runs into the fact that building things currently copies *rlib* artifacts into the build compiler sysroot. I want to fix that as one of the next steps. After we get rid of all the copies (or rather, we only do the copies for dist/stage2+ and do not copy anything into the stage0 compiler's sysroot), we could hopefully finally get rid of `stage0-sysroot`.

Based on my local tests, this seems to be working fine. If it works on CI, and we don't run into other issues after merging it, I'd like to do the same also for rlib artifacts generated during `x build`.

r? ```@jieyouxu```
2025-08-19 14:18:18 +10:00
Jakub Beránek
533ecdbc1c
Assume UTF-8 in sysroot paths 2025-08-18 22:12:48 +02:00
Jakub Beránek
4c212513cf
Fix uplifting in Assemble step 2025-08-18 22:09:30 +02:00
Jieyou Xu
d2e126435a
Add change tracker entry for --timings 2025-08-18 22:50:13 +08:00
Jakub Beránek
a1f5bbeed8
Provide more useful command creation spans 2025-08-18 12:41:12 +02:00
Jakub Beránek
e31aea8903
Remove unused PartialOrd/Ord from bootstrap 2025-08-18 10:56:51 +02:00
Jakub Beránek
22519d3c2d
Do not overwrite the value of RUSTC_ADDITIONAL_SYSROOT_PATHS 2025-08-18 10:46:33 +02:00
Jakub Beránek
abecf68112
Trace some basic I/O operations in bootstrap 2025-08-18 08:05:56 +02:00
Jakub Beránek
814b8e682c
Only check std in cross-compilation instead of building it 2025-08-16 11:24:19 +02:00
Jakub Beránek
ddf39cabf2
Avoid copying rustc rmeta artifacts into the build compiler sysroot
This helps to avoid polluting the sysroot of the build compiler.
2025-08-16 09:49:18 +02:00
Jakub Beránek
cdea62dc44
Optimize copy_src_dirs 2025-08-16 08:57:05 +02:00
Jakub Beránek
5107ac92bb
Do not call fs::remove_file in cp_link_filtered_recurse
The target is removed by `copy_link` too, so no need to duplicate the syscall.
2025-08-16 08:56:41 +02:00
Jacob Pratt
56e9a67d16
Rollup merge of #145455 - Kobzol:bootstrap-copy-src-dirs-dry-run, r=jieyouxu
Do not copy files in `copy_src_dirs` in dry run

This reduces the time to run the current 9 dist snapshot tests from ~24s to ~2s on my PC.

r? `@jieyouxu`
2025-08-15 18:13:32 -04:00
Jacob Pratt
4fa90ef799
Rollup merge of #145454 - Kobzol:bootstrap-fix-step-debug-repr, r=jieyouxu
Fix tracing debug representation of steps without arguments in bootstrap

I was wondering why I see `lainSourceTarbal` in tracing logs...

r? `@jieyouxu`
2025-08-15 18:13:31 -04:00
Jacob Pratt
71adb87994
Rollup merge of #145453 - Kobzol:bootstrap-cmd-span, r=jieyouxu
Remove duplicated tracing span in bootstrap

`trace_cmd` is now called also in the `stream` method, so including it also here was duplicating command spans.

r? `@jieyouxu`
2025-08-15 18:13:31 -04:00
Jakub Beránek
24f5cc41c8
Do not copy files in copy_src_dirs in dry run 2025-08-15 16:58:52 +02:00
Jakub Beránek
e9ce9ff498
Fix tracing debug representation of steps without arguments in bootstrap 2025-08-15 16:54:13 +02:00
Jakub Beránek
33218a25c8
Remove duplicated tracing span in bootstrap 2025-08-15 16:30:05 +02:00
Jakub Beránek
ef3bb6fb0b
Do not strip binaries in bootstrap everytime if they are unchanged 2025-08-15 16:26:07 +02:00
Jakub Beránek
82c6ad3eda
Rollup merge of #145413 - joshtriplett:bootstrap-reduce-deps, r=clubby789
bootstrap: Reduce dependencies

Eliminate the `fd-lock` dependency by using the new native locking in std.

Eliminate the `xattr` dependency by turning off a feature flag in `tar`, since
the tarballs that we extract with bootstrap don't need it.
2025-08-15 16:03:59 +02:00
Jakub Beránek
0734cbda19
Rollup merge of #145340 - Kobzol:bootstrap-codegen-backend-check-split, r=jieyouxu
Split codegen backend check step into two and don't run it with `x check compiler`

This reduces the amount of work that is done during `x check compiler`. We still check both backends during `x check` by defaut, even if they are not in `rust.codegen-backends`, as just checking them shouldn't require expensive preparations, like building GCC.

r? `@jieyouxu`
2025-08-15 16:03:57 +02:00
Jakub Beránek
36dfed6435
Remove usage of compiler_for from the compile::Rustc step 2025-08-15 08:23:57 +02:00
Jakub Beránek
d8a51f58b3
Remove usage of compiler_for from the compile::Std step 2025-08-15 08:21:15 +02:00
Jakub Beránek
8a7be4ab5e
Rename compiler to build_compiler in the compile::Std step 2025-08-15 08:21:14 +02:00
Jakub Beránek
2a2903c49e
Split codegen backend check step into two and don't run it with x check compiler 2025-08-15 08:19:46 +02:00
Josh Triplett
56b33cd5fa bootstrap: Remove dependency on xattr
Extracting the Rust tarballs doesn't require this.
2025-08-14 20:55:08 -07:00
Josh Triplett
ffdc40f30a bootstrap: Switch from fd-lock to native locking in std
In the process, fix a race condition, by never truncating or writing to
the file unless we currently hold the lock.
2025-08-14 20:55:02 -07:00
Jakub Beránek
86c25f8dd1
Rollup merge of #145379 - joshtriplett:bootstrap-timings, r=jieyouxu
bootstrap: Support passing `--timings` to cargo

Useful for optimizing the sequencing of the compiler's own build.
2025-08-14 21:48:45 +02:00
Jakub Beránek
55f2234000
Rollup merge of #145353 - CathalMullan:jemalloc-tools, r=Kobzol
bootstrap: Fix jemalloc 64K page support for aarch64 tools

Resolves rust-lang/rust#133748

The prior page size fix only targeted the compile build step, not the tools step: https://github.com/rust-lang/rust/pull/135081

Also note that since `miri` always uses jemalloc, I didn't copy the `builder.config.jemalloc(target)` check to the tools section.

Tested by running `strings` on the compiled `miri` binary to see the LG_PAGE value.

Before:

```
> strings miri | grep '^LG_PAGE'
LG_PAGE 14
```

After:

```
> strings miri | grep '^LG_PAGE'
LG_PAGE 16
```

May also need a separate fix for the standalone miri repository: https://github.com/rust-lang/miri/issues/4514 (likely a change needed in miri-script?)
2025-08-14 21:48:44 +02:00
Jakub Beránek
06246bfc73
Rollup merge of #145324 - Kobzol:bootstrap-host-only, r=jieyouxu
Rename and document `ONLY_HOSTS` in bootstrap

Everytime I examined the `ONLY_HOSTS` flag of bootstrap steps, I was utterly confused. Why is it called ONLY_HOSTS? How does the fact that it is skipped if `--target` is passed, but `--host` is not (which was not accurate) help me?

The reality of the flag is that if it is true, the targets for which the given Step will be built is determined based on the `--host` flag, while if it is false, it is determined based on the `--target` flag, that's pretty much it. The previous comment was just a (not very helpful and not even accurate) corollary of that.

I clarified the comment, and also renamed the flag to `IS_HOST` (happy to brainstorm better names, but the doc. comment change is IMO the main improvement).

r? ``@jieyouxu``
2025-08-14 21:48:43 +02:00
Jakub Beránek
ebd4a10dcf
Rollup merge of #145261 - Kobzol:bootstrap-tracing, r=jieyouxu
Improve tracing in bootstrap

I was annoyed that bootstrap had like 5 separate ways of debugging/tracing/profiling, and it was hard for me to understand how are individual steps executed. This PR tries to unify severla things behind `BOOTSTRAP_TRACING`, and improve tracing/profiling in general:
- All generated tracing outputs are now stored in a single directory to make it easier to examine them, plus bootstrap prepares a `latest` symlink to the latest generated tracing output directory for convenience.
- All executed spans are now logged automatically (without requiring usage of `#[tracing::instrument]`).
- A custom span/event formatter was implemented, to provide domain-specific output (like location of executed commands or spans) and hopefully also to reduce visual clutter.
  - `tracing_forest` was removed. While it did some useful postprocessing, it didn't expose enough information for making the dynamic step spans work.
- You can now explicitly log steps (`STEP=info`) and/or commands (`COMMAND=info`), to have more granular control over what gets logged.
- `print-step-timings` also show when a step starts its execution (not just when it ends it), so that when some step fails in CI, we can actually see what step it was (before we would only see the end of the previous step).
- The rustc-dev-guide page on debugging/profiling bootstrap was updated.

There are still some things that work outside of tracing (`print-step-timings` and `dump-bootstrap-shims`), but I think that for now this improvement is good enough.

I removed the `> step`, `< step` verbose output, because I found it unusable, as verbose bootstrap output also enables verbose Cargo output, and then you simply drown in too much data, and because I think that the new tracing system makes it obsolete (although it does require recompilation with the `tracing` feature). If you want to keep it, happy to revert 690c781475. And the information about cached steps is now also shown in the Graphviz step dependency graph.

We can modify the tracing output however we want, as we now implement it ourselves. Notably, we could also show exit logs for step spans, currently I only show enter spans. Maybe creating indents for each executed nested command is also not needed. Happy to hear feedback!

Some further improvements could be to print step durations, if we decide to also log step exit events. We could also try to enable tracing in CI logs, but it might be too verbose.

Best reviewed commit-by-commit.

r? ``@jieyouxu``

CC ``@Shourya742``
2025-08-14 21:48:43 +02:00
Jakub Beránek
e08c75533c
Rename and document ONLY_HOSTS in bootstrap 2025-08-14 16:58:28 +02:00
Jakub Beránek
f382d547d9
Remove ONLY_HOSTS value overrides that just set the default value and had no comment 2025-08-14 16:58:05 +02:00
Josh Triplett
d10a8a3321 bootstrap: Support passing --timings to cargo
Useful for optimizing the sequencing of the compiler's own build.
2025-08-13 22:02:11 -07:00
bors
2c1ac85679 Auto merge of #145131 - Kobzol:bootstrap-clippy, r=jieyouxu
Enforce in bootstrap that clippy must have stage at least 1

This mostly piggybacks on the previous `x check` [rework](https://github.com/rust-lang/rust/pull/143048).

The new "rules" follow the new staging logic. So `x clippy <foo>` lints `foo` using stage0 Clippy. `x clippy --stage 2 <foo>` lints `foo` using stage1 Clippy (which is built from in-tree sources).

I had to fix some latent issues with `prepare_compiler_for_check` along the way.

Checking `rustc_private` tools should now check less compiler crates (or rather not check compiler examples/tests/etc.), potentially speeding it up slightly.

I also had to make some manual adjustments to `x clippy ci` so that it doesn't do needless work.

r? `@jieyouxu`
2025-08-14 04:23:07 +00:00