Skip to content

Commit 558189c

Browse files
authored
Unrolled build for rust-lang#137642
Rollup merge of rust-lang#137642 - BoxyUwU:rdg-push, r=Kobzol Rustc dev guide subtree update r? ``@Kobzol`` ``@jieyouxu``
2 parents ac91805 + 69369a7 commit 558189c

14 files changed

+121
-27
lines changed

src/doc/rustc-dev-guide/.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ on:
66
- master
77
pull_request:
88
schedule:
9-
# Run at 18:00 UTC every day
10-
- cron: '0 18 * * *'
9+
# Run multiple times a day as the successfull cached links are not checked every time.
10+
- cron: '0 */8 * * *'
1111

1212
jobs:
1313
ci:
1414
if: github.repository == 'rust-lang/rustc-dev-guide'
1515
runs-on: ubuntu-latest
1616
env:
1717
MDBOOK_VERSION: 0.4.21
18-
MDBOOK_LINKCHECK2_VERSION: 0.8.1
18+
MDBOOK_LINKCHECK2_VERSION: 0.9.1
1919
MDBOOK_MERMAID_VERSION: 0.12.6
2020
MDBOOK_TOC_VERSION: 0.11.2
2121
DEPLOY_DIR: book/html

src/doc/rustc-dev-guide/.github/workflows/rustc-pull.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ jobs:
111111
to: 196385
112112
type: "stream"
113113
topic: "Subtree sync automation"
114-
content: ${{ steps.message.outputs.message }}
114+
content: ${{ steps.create-message.outputs.message }}

src/doc/rustc-dev-guide/examples/README

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ For each example to compile, you will need to first run the following:
44

55
To create an executable:
66

7-
rustc rustc-driver-example.rs
7+
rustup run nightly rustc rustc-driver-example.rs
8+
9+
You might need to be more specific about the exact nightly version. See the comments at the top of
10+
the examples for the version they were written for.
811

912
To run an executable:
1013

src/doc/rustc-dev-guide/examples/rustc-driver-example.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Tested with nightly-2025-02-13
2+
13
#![feature(rustc_private)]
24

35
extern crate rustc_ast;
@@ -73,7 +75,7 @@ impl rustc_driver::Callbacks for MyCallbacks {
7375
let hir = tcx.hir();
7476
let item = hir.item(id);
7577
match item.kind {
76-
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => {
78+
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
7779
let name = item.ident;
7880
let ty = tcx.type_of(item.hir_id().owner.def_id);
7981
println!("{name:?}:\t{ty:?}")
@@ -87,5 +89,13 @@ impl rustc_driver::Callbacks for MyCallbacks {
8789
}
8890

8991
fn main() {
90-
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
92+
run_compiler(
93+
&[
94+
// The first argument, which in practice contains the name of the binary being executed
95+
// (i.e. "rustc") is ignored by rustc.
96+
"ignored".to_string(),
97+
"main.rs".to_string(),
98+
],
99+
&mut MyCallbacks,
100+
);
91101
}

src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Tested with nightly-2025-02-13
2+
13
#![feature(rustc_private)]
24

35
extern crate rustc_ast;
@@ -18,7 +20,7 @@ use std::path::Path;
1820
use std::sync::Arc;
1921

2022
use rustc_ast_pretty::pprust::item_to_string;
21-
use rustc_driver::{Compilation, run_compiler};
23+
use rustc_driver::{run_compiler, Compilation};
2224
use rustc_interface::interface::{Compiler, Config};
2325
use rustc_middle::ty::TyCtxt;
2426

@@ -74,8 +76,8 @@ impl rustc_driver::Callbacks for MyCallbacks {
7476
for id in hir_krate.items() {
7577
let item = hir_krate.item(id);
7678
// Use pattern-matching to find a specific node inside the main function.
77-
if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind {
78-
let expr = &tcx.hir_body(body_id).value;
79+
if let rustc_hir::ItemKind::Fn { body, .. } = item.kind {
80+
let expr = &tcx.hir_body(body).value;
7981
if let rustc_hir::ExprKind::Block(block, _) = expr.kind {
8082
if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind {
8183
if let Some(expr) = let_stmt.init {
@@ -94,5 +96,13 @@ impl rustc_driver::Callbacks for MyCallbacks {
9496
}
9597

9698
fn main() {
97-
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
99+
run_compiler(
100+
&[
101+
// The first argument, which in practice contains the name of the binary being executed
102+
// (i.e. "rustc") is ignored by rustc.
103+
"ignored".to_string(),
104+
"main.rs".to_string(),
105+
],
106+
&mut MyCallbacks,
107+
);
98108
}

src/doc/rustc-dev-guide/examples/rustc-interface-example.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Tested with nightly-2025-02-13
2+
13
#![feature(rustc_private)]
24

35
extern crate rustc_driver;
@@ -9,8 +11,6 @@ extern crate rustc_interface;
911
extern crate rustc_session;
1012
extern crate rustc_span;
1113

12-
use std::sync::Arc;
13-
1414
use rustc_errors::registry;
1515
use rustc_hash::FxHashMap;
1616
use rustc_session::config;
@@ -56,7 +56,7 @@ fn main() {
5656
expanded_args: Vec::new(),
5757
ice_file: None,
5858
hash_untracked_state: None,
59-
using_internal_features: Arc::default(),
59+
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
6060
};
6161
rustc_interface::run_compiler(config, |compiler| {
6262
// Parse the program and print the syntax tree.
@@ -68,7 +68,7 @@ fn main() {
6868
let hir = tcx.hir();
6969
let item = hir.item(id);
7070
match item.kind {
71-
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => {
71+
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn { .. } => {
7272
let name = item.ident;
7373
let ty = tcx.type_of(item.hir_id().owner.def_id);
7474
println!("{name:?}:\t{ty:?}")

src/doc/rustc-dev-guide/examples/rustc-interface-getting-diagnostics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Tested with nightly-2025-02-13
2+
13
#![feature(rustc_private)]
24

35
extern crate rustc_data_structures;
@@ -15,7 +17,7 @@ use std::sync::{Arc, Mutex};
1517
use rustc_errors::emitter::Emitter;
1618
use rustc_errors::registry::{self, Registry};
1719
use rustc_errors::translation::Translate;
18-
use rustc_errors::{DiagCtxt, DiagInner, FluentBundle};
20+
use rustc_errors::{DiagInner, FluentBundle};
1921
use rustc_session::config;
2022
use rustc_span::source_map::SourceMap;
2123

@@ -79,7 +81,7 @@ fn main() {
7981
expanded_args: Vec::new(),
8082
ice_file: None,
8183
hash_untracked_state: None,
82-
using_internal_features: Arc::default(),
84+
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
8385
};
8486
rustc_interface::run_compiler(config, |compiler| {
8587
let krate = rustc_interface::passes::parse(&compiler.sess);

src/doc/rustc-dev-guide/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
124cc92199ffa924f6b4c7cc819a85b65e0c3984
1+
4ecd70ddd1039a3954056c1071e40278048476fa

src/doc/rustc-dev-guide/src/building/bootstrapping/debugging-bootstrap.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
# Debugging bootstrap
22

3+
There are two main ways to debug bootstrap itself. The first is through println logging, and the second is through the `tracing` feature.
4+
35
> FIXME: this section should be expanded
46
7+
## `println` logging
8+
9+
Bootstrap has extensive unstructured logging. Most of it is gated behind the `--verbose` flag (pass `-vv` for even more detail).
10+
11+
If you want to know which `Step` ran a command, you could invoke bootstrap like so:
12+
13+
```
14+
$ ./x dist rustc --dry-run -vv
15+
learning about cargo
16+
running: RUSTC_BOOTSTRAP="1" "/home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "metadata" "--format-version" "1" "--no-deps" "--manifest-path" "/home/jyn/src/rust2/Cargo.toml" (failure_mode=Exit) (created at src/bootstrap/src/core/metadata.rs:81:25, executed at src/bootstrap/src/core/metadata.rs:92:50)
17+
running: RUSTC_BOOTSTRAP="1" "/home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "metadata" "--format-version" "1" "--no-deps" "--manifest-path" "/home/jyn/src/rust2/library/Cargo.toml" (failure_mode=Exit) (created at src/bootstrap/src/core/metadata.rs:81:25, executed at src/bootstrap/src/core/metadata.rs:92:50)
18+
> Assemble { target_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu } }
19+
> Libdir { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, target: x86_64-unknown-linux-gnu }
20+
> Sysroot { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, force_recompile: false }
21+
Removing sysroot /home/jyn/src/rust2/build/tmp-dry-run/x86_64-unknown-linux-gnu/stage1 to avoid caching bugs
22+
< Sysroot { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, force_recompile: false }
23+
< Libdir { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, target: x86_64-unknown-linux-gnu }
24+
...
25+
```
26+
27+
This will go through all the recursive dependency calculations, where `Step`s internally call `builder.ensure()`, without actually running cargo or the compiler.
28+
29+
In some cases, even this may not be enough logging (if so, please add more!). In that case, you can omit `--dry-run`, which will show the normal output inline with the debug logging:
30+
31+
```
32+
c Sysroot { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu }, force_recompile: false }
33+
using sysroot /home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0-sysroot
34+
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
35+
running: cd "/home/jyn/src/rust2" && env ... RUSTC_VERBOSE="2" RUSTC_WRAPPER="/home/jyn/src/rust2/build/bootstrap/debug/rustc" "/home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-Zroot-dir=/home/jyn/src/rust2" "-v" "-v" "--manifest-path" "/home/jyn/src/rust2/library/sysroot/Cargo.toml" "--message-format" "json-render-diagnostics"
36+
0.293440230s INFO prepare_target{force=false package_id=sysroot v0.0.0 (/home/jyn/src/rust2/library/sysroot) target="sysroot"}: cargo::core::compiler::fingerprint: fingerprint error for sysroot v0.0.0 (/home/jyn/src/rust2/library/sysroot)/Build/TargetInner { name_inferred: true, ..: lib_target("sysroot", ["lib"], "/home/jyn/src/rust2/library/sysroot/src/lib.rs", Edition2021) }
37+
...
38+
```
39+
40+
In most cases this should not be necessary.
41+
42+
TODO: we should convert all this to structured logging so it's easier to control precisely.
43+
544
## `tracing` in bootstrap
645

746
Bootstrap has conditional [`tracing`][tracing] setup to provide structured logging.
@@ -53,11 +92,11 @@ Checking stage0 bootstrap artifacts (x86_64-unknown-linux-gnu)
5392
Build completed successfully in 0:00:08
5493
```
5594

56-
#### Controlling log output
95+
#### Controlling tracing output
5796

5897
The env var `BOOTSTRAP_TRACING` accepts a [`tracing` env-filter][tracing-env-filter].
5998

60-
There are two orthogonal ways to control which kind of logs you want:
99+
There are two orthogonal ways to control which kind of tracing logs you want:
61100

62101
1. You can specify the log **level**, e.g. `DEBUG` or `TRACE`.
63102
2. You can also control the log **target**, e.g. `bootstrap` or `bootstrap::core::config` vs custom targets like `CONFIG_HANDLING`.

src/doc/rustc-dev-guide/src/building/suggested.md

+29-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,35 @@ create a `.vim/coc-settings.json`. The settings can be edited with
120120
[`src/etc/rust_analyzer_settings.json`].
121121

122122
Another way is without a plugin, and creating your own logic in your
123-
configuration. To do this you must translate the JSON to Lua yourself. The
124-
translation is 1:1 and fairly straight-forward. It must be put in the
125-
`["rust-analyzer"]` key of the setup table, which is [shown
126-
here](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer).
123+
configuration. The following code will work for any checkout of rust-lang/rust (newer than Febuary 2025):
124+
125+
```lua
126+
lspconfig.rust_analyzer.setup {
127+
root_dir = function()
128+
local default = lspconfig.rust_analyzer.config_def.default_config.root_dir()
129+
-- the default root detection uses the cargo workspace root.
130+
-- but for rust-lang/rust, the standard library is in its own workspace.
131+
-- use the git root instead.
132+
local compiler_config = vim.fs.joinpath(default, "../src/bootstrap/defaults/config.compiler.toml")
133+
if vim.fs.basename(default) == "library" and vim.uv.fs_stat(compiler_config) then
134+
return vim.fs.dirname(default)
135+
end
136+
return default
137+
end,
138+
on_init = function(client)
139+
local path = client.workspace_folders[1].name
140+
local config = vim.fs.joinpath(path, "src/etc/rust_analyzer_zed.json")
141+
if vim.uv.fs_stat(config) then
142+
-- load rust-lang/rust settings
143+
local file = io.open(config)
144+
local json = vim.json.decode(file:read("*a"))
145+
client.config.settings["rust-analyzer"] = json.lsp["rust-analyzer"].initialization_options
146+
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
147+
end
148+
return true
149+
end
150+
}
151+
```
127152

128153
If you would like to use the build task that is described above, you may either
129154
make your own command in your config, or you can install a plugin such as

src/doc/rustc-dev-guide/src/compiler-debugging.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ error: layout_of(&'a u32) = Layout {
368368
error: aborting due to previous error
369369
```
370370

371-
[`Layout`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/struct.Layout.html
371+
[`Layout`]: https://doc.rust-lang.org/nightly/nightly-rustc/stable_mir/abi/struct.Layout.html
372372

373373

374374
## Configuring CodeLLDB for debugging `rustc`

src/doc/rustc-dev-guide/src/profiling/with_perf.md

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ you made in the beginning. But there are some things to be aware of:
5252
- You probably don't want incremental messing about with your
5353
profile. So something like `CARGO_INCREMENTAL=0` can be helpful.
5454

55+
In case to avoid the issue of `addr2line xxx/elf: could not read first record` when reading
56+
collected data from `cargo`, you may need use the latest version of `addr2line`:
57+
58+
```bash
59+
cargo install addr2line --features="bin"
60+
```
61+
5562
### Gathering a perf profile from a `perf.rust-lang.org` test
5663

5764
Often we want to analyze a specific test from `perf.rust-lang.org`.

src/doc/rustc-dev-guide/src/rustc-driver/getting-diagnostics.md

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ otherwise be printed to stderr.
88
To get diagnostics from the compiler,
99
configure [`rustc_interface::Config`] to output diagnostic to a buffer,
1010
and run [`TyCtxt.analysis`].
11-
The following was tested with <!-- date-check: september 2024 --> `nightly-2024-09-16`:
1211

1312
```rust
1413
{{#include ../../examples/rustc-interface-getting-diagnostics.rs}}

src/doc/rustc-dev-guide/src/rustc-driver/interacting-with-the-ast.md

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
## Getting the type of an expression
66

77
To get the type of an expression, use the [`after_analysis`] callback to get a [`TyCtxt`].
8-
The following was tested with <!-- date-check: december 2024 --> `nightly-2024-12-15`:
98

109
```rust
1110
{{#include ../../examples/rustc-driver-interacting-with-the-ast.rs}}

0 commit comments

Comments
 (0)