Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
ba066c2
Auto merge of #145014 - bjorn3:revert_preserve_debug_gdb_scripts, r=lqd
bors Aug 7, 2025
703be26
Rollup merge of #137831 - estebank:auto-trait-err, r=compiler-errors
Zalathar Aug 7, 2025
fe35e62
Rollup merge of #138689 - jedbrown:jed/nvptx-target-feature, r=ZuseZ4
Zalathar Aug 7, 2025
af24ebc
Rollup merge of #140267 - jogru0:control_flow, r=dtolnay
Zalathar Aug 7, 2025
c1b37b2
Rollup merge of #143028 - dianne:let-else-storage, r=oli-obk,traviscross
Zalathar Aug 7, 2025
44e6fc9
Rollup merge of #143764 - dianne:primary-binding-drop-order, r=Nadrie…
Zalathar Aug 7, 2025
5176fed
Rollup merge of #143808 - JonathanBrouwer:should_panic_parser, r=jdon…
Zalathar Aug 7, 2025
3466f7c
Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-…
Zalathar Aug 7, 2025
ba5f822
Rollup merge of #143929 - petrochenkov:depresolve, r=lcnr
Zalathar Aug 7, 2025
ba0bb25
Rollup merge of #144133 - oli-obk:stabilize-const-type-id, r=lcnr
Zalathar Aug 7, 2025
61772ac
Rollup merge of #144369 - joshtriplett:mbe-expr-semi-deny-by-default,…
Zalathar Aug 7, 2025
535dce4
Rollup merge of #144439 - xizheyin:symbol-rs, r=petrochenkov
Zalathar Aug 7, 2025
6b5cf85
Rollup merge of #144473 - zeroomega:rustc_inconsistency, r=Mark-Simul…
Zalathar Aug 7, 2025
d26f68a
Rollup merge of #144601 - kornelski:cargo-fix-mismatched_lifetime_syn…
Zalathar Aug 7, 2025
3bee633
Rollup merge of #144650 - Borgerr:additional-tce-tests, r=WaffleLapki…
Zalathar Aug 7, 2025
47bc4f3
Rollup merge of #144659 - mati865:gnullvm-vendor-libunwind, r=Kobzol
Zalathar Aug 7, 2025
bf0e40b
Rollup merge of #144682 - nxsaken:strict_overflow_ops, r=Mark-Simulacrum
Zalathar Aug 7, 2025
0afc5e0
Rollup merge of #145033 - nnethercote:fix-144994, r=fmease
Zalathar Aug 7, 2025
9c2d9bb
Rollup merge of #145040 - tshepang:rdg-sync, r=Kobzol
Zalathar Aug 7, 2025
c368c78
Auto merge of #144997 - BoxyUwU:bootstrap_bump, r=Mark-Simulacrum
bors Aug 7, 2025
fe168de
Auto merge of #145043 - Zalathar:rollup-3dbvdrm, r=Zalathar
bors Aug 7, 2025
3d7fa27
Auto merge of #145056 - flip1995:clippy-subtree-update, r=Manishearth
bors Aug 7, 2025
f81b8b7
Auto merge of #143807 - rperier:rustc_llvm_werror, r=cuviper
bors Aug 7, 2025
c52ba93
Auto merge of #144873 - cjgillot:implications, r=lqd
bors Aug 10, 2025
a7b3681
Update rustc dev guide
tiif Aug 11, 2025
c2d3ba5
Update debugging/profiling bootstrap page
Kobzol Aug 11, 2025
c7a72d4
Rollup merge of #144921 - lolbinarycat:rustdoc-intra-doc-gfm-141866, …
Zalathar Aug 12, 2025
ca99a78
Rollup merge of #145251 - tiif:support_trait, r=BoxyUwU
Zalathar Aug 12, 2025
da466ed
Rollup merge of #145253 - Kobzol:pr-check-2-doc-stage-1, r=jieyouxu
Zalathar Aug 12, 2025
3d1e8fd
Rollup merge of #145260 - SabrinaJewson:vec-allocator-docs, r=dtolnay
Zalathar Aug 12, 2025
7cd7556
Rollup merge of #145263 - rustbot:docs-update, r=ehuss
Zalathar Aug 12, 2025
736bfc4
Rollup merge of #145273 - estebank:not-not, r=samueltardieu
Zalathar Aug 12, 2025
950ccb8
Rollup merge of #145283 - theemathas:patch-1, r=Noratrieb
Zalathar Aug 12, 2025
0e081e8
Rollup merge of #145291 - Zalathar:no-warning, r=Kobzol
Zalathar Aug 12, 2025
c4de28f
Rollup merge of #145292 - ada4a:patch-2, r=tgross35
Zalathar Aug 12, 2025
7978029
Auto merge of #145300 - Zalathar:rollup-0eqbt6a, r=Zalathar
bors Aug 12, 2025
16003b1
Auto merge of #144678 - jdonszelmann:no-mangle-extern, r=bjorn3
bors Aug 12, 2025
55a9790
Replace `stage0-tools-bin` with `stage1-tools-bin`
Kobzol Aug 12, 2025
49bf3e6
Auto merge of #145295 - Kobzol:unify-stages, r=jieyouxu
bors Aug 12, 2025
36b4b36
Auto merge of #145093 - nikic:dead-on-return, r=nnethercote
bors Aug 13, 2025
ab2b0f7
Auto merge of #144722 - ywxt:parallel-reproducibile, r=SparrowLii
bors Aug 13, 2025
1a078ff
Auto merge of #145298 - nikic:llvm21-rc3, r=cuviper
bors Aug 13, 2025
a648e63
Complete functionality and general cleanup
Sa4dUs Aug 14, 2025
658685b
Rollup merge of #137872 - estebank:extra-vert, r=compiler-errors
Kobzol Aug 14, 2025
ffbdd9a
Rollup merge of #144631 - fneddy:fix_be_test_intrinsic_const_bad, r=c…
Kobzol Aug 14, 2025
1b8228e
Rollup merge of #145233 - joshtriplett:cfg-select-expr, r=jieyouxu
Kobzol Aug 14, 2025
538ca3f
Rollup merge of #145261 - Kobzol:bootstrap-tracing, r=jieyouxu
Kobzol Aug 14, 2025
7839f32
Rollup merge of #145324 - Kobzol:bootstrap-host-only, r=jieyouxu
Kobzol Aug 14, 2025
0e290f9
Rollup merge of #145353 - CathalMullan:jemalloc-tools, r=Kobzol
Kobzol Aug 14, 2025
e386b6c
Rollup merge of #145379 - joshtriplett:bootstrap-timings, r=jieyouxu
Kobzol Aug 14, 2025
36d0f02
Rollup merge of #145397 - lcnr:lcnr/rustc-dev-guide-3, r=BoxyUwU
Kobzol Aug 14, 2025
de731af
Rollup merge of #145398 - estebank:use-default-fields-resolver, r=pet…
Kobzol Aug 14, 2025
42bcd4f
Rollup merge of #145401 - estebank:remove-useless-iter, r=compiler-er…
Kobzol Aug 14, 2025
13a5544
Rollup merge of #145403 - shepmaster:grammar, r=estebank
Kobzol Aug 14, 2025
afba9f6
Auto merge of #145407 - Kobzol:rollup-g6yhx82, r=Kobzol
bors Aug 14, 2025
328977b
Auto merge of #144591 - RalfJung:pattern-valtrees, r=BoxyUwU
bors Aug 15, 2025
d113c70
Rollup merge of #118087 - GrigorenkoPV:refcell_try_map, r=Mark-Simula…
Zalathar Aug 15, 2025
d63df27
Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov
Zalathar Aug 15, 2025
74001cf
Rollup merge of #142640 - Sa4dUs:ad-intrinsic, r=ZuseZ4
Zalathar Aug 15, 2025
6330f16
Rollup merge of #143075 - workingjubilee:interrupts-may-return-neverm…
Zalathar Aug 15, 2025
6c9a42c
Rollup merge of #144865 - WaffleLapkin:track-tail, r=lqd
Zalathar Aug 15, 2025
980ff00
Rollup merge of #144944 - He1pa:E0793, r=compiler-errors
Zalathar Aug 15, 2025
2aa48da
Rollup merge of #144947 - tautschnig:remove-stray-checked_div-comment…
Zalathar Aug 15, 2025
ab8339f
Rollup merge of #145004 - bjorn3:remove_unused_fields, r=WaffleLapkin
Zalathar Aug 15, 2025
381a3e5
Rollup merge of #145005 - tardyp:lto_big_filesize, r=bjorn3
Zalathar Aug 15, 2025
b2a6c47
Rollup merge of #145012 - Kivooeo:fun-problem-fun-fix, r=compiler-errors
Zalathar Aug 15, 2025
432bf77
Rollup merge of #145065 - petrochenkov:riblock, r=davidtwco
Zalathar Aug 15, 2025
a2858f9
Rollup merge of #145120 - maurer:llvm-time, r=nikic
Zalathar Aug 15, 2025
94ff644
Rollup merge of #145189 - rust-lang:cargo_update, r=clubby789
Zalathar Aug 15, 2025
854855a
Rollup merge of #145235 - compiler-errors:comment, r=BoxyUwU
Zalathar Aug 15, 2025
a31b9be
Rollup merge of #145275 - StackOverflowExcept1on:fix-wasm32v1-none, r…
Zalathar Aug 15, 2025
3077ecb
Rollup merge of #145322 - LorrensP-2158466:early-prelude-processing, …
Zalathar Aug 15, 2025
7280ab7
Rollup merge of #145331 - theemathas:std-prelude-2024, r=tgross35
Zalathar Aug 15, 2025
aef2b6b
Rollup merge of #145369 - estebank:issue-145367, r=compiler-errors
Zalathar Aug 15, 2025
4d20c7c
Rollup merge of #145378 - xizheyin:144968, r=davidtwco
Zalathar Aug 15, 2025
e5f6579
Rollup merge of #145389 - GuillaumeGomez:unstable-search, r=fmease
Zalathar Aug 15, 2025
7c0b8fc
Rollup merge of #145392 - Zalathar:create-mappings, r=petrochenkov
Zalathar Aug 15, 2025
2446ebf
Auto merge of #145423 - Zalathar:rollup-9jtefpl, r=Zalathar
bors Aug 15, 2025
230d0a3
Auto merge of #144991 - lcnr:ignore-usages-from-ignored-candidates, r…
bors Aug 15, 2025
e3cad40
Auto merge of #142071 - lcnr:revealing-use, r=compiler-errors
bors Aug 15, 2025
ce496e0
Auto merge of #145304 - m-ou-se:simplify-panic, r=oli-obk
bors Aug 16, 2025
18d5900
Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obk
bors Aug 17, 2025
26b9fd2
Auto merge of #145284 - nnethercote:type_name-print-regions, r=lcnr
bors Aug 17, 2025
c956173
Prepare for merging from rust-lang/rust
invalid-email-address Aug 18, 2025
6e6eb4c
Merge ref '425a9c0a0e36' from rust-lang/rust
invalid-email-address Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6bcdcc73bd11568fd85f5a38b58e1eda054ad1cd
425a9c0a0e365c0b8c6cfd00c2ded83a73bed9a0
1 change: 0 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
- [Installation](./autodiff/installation.md)
- [How to debug](./autodiff/debugging.md)
- [Autodiff flags](./autodiff/flags.md)
- [Current limitations](./autodiff/limitations.md)

# Source Code Representation

Expand Down
27 changes: 0 additions & 27 deletions src/autodiff/limitations.md

This file was deleted.

148 changes: 49 additions & 99 deletions src/building/bootstrapping/debugging-bootstrap.md
Original file line number Diff line number Diff line change
@@ -1,120 +1,100 @@
# Debugging bootstrap

There are two main ways to debug bootstrap itself. The first is through println logging, and the second is through the `tracing` feature.

> FIXME: this section should be expanded
There are two main ways of debugging (and profiling bootstrap). The first is through println logging, and the second is through the `tracing` feature.

## `println` logging

Bootstrap has extensive unstructured logging. Most of it is gated behind the `--verbose` flag (pass `-vv` for even more detail).

If you want to know which `Step` ran a command, you could invoke bootstrap like so:
If you want to see verbose output of executed Cargo commands and other kinds of detailed logs, pass `-v` or `-vv` when invoking bootstrap. Note that the logs are unstructured and may be overwhelming.

```
$ ./x dist rustc --dry-run -vv
learning about cargo
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)
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)
> Assemble { target_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu } }
> Libdir { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, target: x86_64-unknown-linux-gnu }
> Sysroot { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, force_recompile: false }
Removing sysroot /home/jyn/src/rust2/build/tmp-dry-run/x86_64-unknown-linux-gnu/stage1 to avoid caching bugs
< Sysroot { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, force_recompile: false }
< Libdir { compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu }, target: x86_64-unknown-linux-gnu }
...
```

This will go through all the recursive dependency calculations, where `Step`s internally call `builder.ensure()`, without actually running cargo or the compiler.

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:

```
c Sysroot { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu }, force_recompile: false }
using sysroot /home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0-sysroot
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
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"
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) }
...
```

In most cases this should not be necessary.
## `tracing` in bootstrap

TODO: we should convert all this to structured logging so it's easier to control precisely.
Bootstrap has a conditional `tracing` feature, which provides the following features:
- It enables structured logging using [`tracing`][tracing] events and spans.
- It generates a [Chrome trace file] that can be used to visualize the hierarchy and durations of executed steps and commands.
- You can open the generated `chrome-trace.json` file using Chrome, on the `chrome://tracing` tab, or e.g. using [Perfetto].
- It generates [GraphViz] graphs that visualize the dependencies between executed steps.
- You can open the generated `step-graph-*.dot` file using e.g. [xdot] to visualize the step graph, or use e.g. `dot -Tsvg` to convert the GraphViz file to an SVG file.
- It generates a command execution summary, which shows which commands were executed, how many of their executions were cached, and what commands were the slowest to run.
- The generated `command-stats.txt` file is in a simple human-readable format.

## `tracing` in bootstrap
The structured logs will be written to standard error output (`stderr`), while the other outputs will be stored in files in the `<build-dir>/bootstrap-trace/<pid>` directory. For convenience, bootstrap will also create a symlink to the latest generated trace output directory at `<build-dir>/bootstrap-trace/latest`.

Bootstrap has conditional [`tracing`][tracing] setup to provide structured logging.
> Note that if you execute bootstrap with `--dry-run`, the tracing output directory might change. Bootstrap will always print a path where the tracing output files were stored at the end of its execution.

[tracing]: https://docs.rs/tracing/0.1.41/tracing/index.html
[Chrome trace file]: https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/
[Perfetto]: https://ui.perfetto.dev/
[GraphViz]: https://graphviz.org/doc/info/lang.html
[xdot]: https://github.com/jrfonseca/xdot.py

### Enabling `tracing` output

Bootstrap will conditionally build `tracing` support and enable `tracing` output if the `BOOTSTRAP_TRACING` env var is set.

#### Basic usage

Example basic usage[^just-trace]:
To enable the conditional `tracing` feature, run bootstrap with the `BOOTSTRAP_TRACING` environment variable.

[^just-trace]: It is not recommended to use *just* `BOOTSTRAP_TRACING=TRACE` because that will dump *everything* at `TRACE` level, including logs intentionally gated behind custom targets as they are too verbose even for `TRACE` level by default.
[tracing_subscriber filter]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html

```bash
$ BOOTSTRAP_TRACING=bootstrap=TRACE ./x build library --stage 1
$ BOOTSTRAP_TRACING=trace ./x build library --stage 1
```

Example output[^unstable]:

```
$ BOOTSTRAP_TRACING=bootstrap=TRACE ./x check src/bootstrap/
$ BOOTSTRAP_TRACING=trace ./x build library --stage 1 --dry-run
Building bootstrap
Compiling bootstrap v0.0.0 (/home/joe/repos/rust/src/bootstrap)
Finished `dev` profile [unoptimized] target(s) in 2.74s
DEBUG bootstrap parsing flags
bootstrap::core::config::flags::Flags::parse args=["check", "src/bootstrap/"]
DEBUG bootstrap parsing config based on flags
DEBUG bootstrap creating new build based on config
bootstrap::Build::build
TRACE bootstrap setting up job management
TRACE bootstrap downloading rustfmt early
bootstrap::handling hardcoded subcommands (Format, Suggest, Perf)
DEBUG bootstrap not a hardcoded subcommand; returning to normal handling, cmd=Check { all_targets: false }
DEBUG bootstrap handling subcommand normally
bootstrap::executing real run
bootstrap::(1) executing dry-run sanity-check
bootstrap::(2) executing actual run
Checking stage0 library artifacts (x86_64-unknown-linux-gnu)
Finished `release` profile [optimized + debuginfo] target(s) in 0.04s
Checking stage0 compiler artifacts {rustc-main, rustc_abi, rustc_arena, rustc_ast, rustc_ast_ir, rustc_ast_lowering, rustc_ast_passes, rustc_ast_pretty, rustc_attr_data_structures, rustc_attr_parsing, rustc_baked_icu_data, rustc_borrowck, rustc_builtin_macros, rustc_codegen_llvm, rustc_codegen_ssa, rustc_const_eval, rustc_data_structures, rustc_driver, rustc_driver_impl, rustc_error_codes, rustc_error_messages, rustc_errors, rustc_expand, rustc_feature, rustc_fluent_macro, rustc_fs_util, rustc_graphviz, rustc_hir, rustc_hir_analysis, rustc_hir_pretty, rustc_hir_typeck, rustc_incremental, rustc_index, rustc_index_macros, rustc_infer, rustc_interface, rustc_lexer, rustc_lint, rustc_lint_defs, rustc_llvm, rustc_log, rustc_macros, rustc_metadata, rustc_middle, rustc_mir_build, rustc_mir_dataflow, rustc_mir_transform, rustc_monomorphize, rustc_next_trait_solver, rustc_parse, rustc_parse_format, rustc_passes, rustc_pattern_analysis, rustc_privacy, rustc_query_impl, rustc_query_system, rustc_resolve, rustc_sanitizers, rustc_serialize, rustc_session, rustc_smir, rustc_span, rustc_symbol_mangling, rustc_target, rustc_trait_selection, rustc_traits, rustc_transmute, rustc_ty_utils, rustc_type_ir, rustc_type_ir_macros, stable_mir} (x86_64-unknown-linux-gnu)
Finished `release` profile [optimized + debuginfo] target(s) in 0.23s
Checking stage0 bootstrap artifacts (x86_64-unknown-linux-gnu)
Checking bootstrap v0.0.0 (/home/joe/repos/rust/src/bootstrap)
Finished `release` profile [optimized + debuginfo] target(s) in 0.64s
DEBUG bootstrap checking for postponed test failures from `test --no-fail-fast`
Build completed successfully in 0:00:08
Finished `dev` profile [unoptimized] target(s) in 0.05s
15:56:52.477 INFO > tool::LibcxxVersionTool {target: x86_64-unknown-linux-gnu} (builder/mod.rs:1715)
15:56:52.575 INFO > compile::Assemble {target_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }} (builder/mod.rs:1715)
15:56:52.575 INFO > tool::Compiletest {compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu} (builder/mod.rs:1715)
15:56:52.576 INFO > tool::ToolBuild {build_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, tool: "compiletest", path: "src/tools/compiletest", mode: ToolBootstrap, source_type: InTree, extra_features: [], allow_features: "internal_output_capture", cargo_args: [], artifact_kind: Binary} (builder/mod.rs:1715)
15:56:52.576 INFO > builder::Libdir {compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu} (builder/mod.rs:1715)
15:56:52.576 INFO > compile::Sysroot {compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, force_recompile: false} (builder/mod.rs:1715)
15:56:52.578 INFO > compile::Assemble {target_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }} (builder/mod.rs:1715)
15:56:52.578 INFO > tool::Compiletest {compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu} (builder/mod.rs:1715)
15:56:52.578 INFO > tool::ToolBuild {build_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, tool: "compiletest", path: "src/tools/compiletest", mode: ToolBootstrap, source_type: InTree, extra_features: [], allow_features: "internal_output_capture", cargo_args: [], artifact_kind: Binary} (builder/mod.rs:1715)
15:56:52.578 INFO > builder::Libdir {compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu} (builder/mod.rs:1715)
15:56:52.578 INFO > compile::Sysroot {compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, force_recompile: false} (builder/mod.rs:1715)
Finished `release` profile [optimized] target(s) in 0.11s
Tracing/profiling output has been written to <src-root>/build/bootstrap-trace/latest
Build completed successfully in 0:00:00
```

[^unstable]: This output is always subject to further changes.

#### Controlling tracing output

The env var `BOOTSTRAP_TRACING` accepts a [`tracing` env-filter][tracing-env-filter].
The environment variable `BOOTSTRAP_TRACING` accepts a [`tracing_subscriber` filter][tracing-env-filter]. If you set `BOOTSTRAP_TRACING=trace`, you will enable all logs, but that can be overwhelming. You can thus use the filter to reduce the amount of data logged.

There are two orthogonal ways to control which kind of tracing logs you want:

1. You can specify the log **level**, e.g. `DEBUG` or `TRACE`.
2. You can also control the log **target**, e.g. `bootstrap` or `bootstrap::core::config` vs custom targets like `CONFIG_HANDLING`.
- Custom targets are used to limit what is output when `BOOTSTRAP_TRACING=bootstrap=TRACE` is used, as they can be too verbose even for `TRACE` level by default. Currently used custom targets:
- `CONFIG_HANDLING`

The `TRACE` filter will enable *all* `trace` level or less verbose level tracing output.
1. You can specify the log **level**, e.g. `debug` or `trace`.
- If you select a level, all events/spans with an equal or higher priority level will be shown.
2. You can also control the log **target**, e.g. `bootstrap` or `bootstrap::core::config` or a custom target like `CONFIG_HANDLING` or `STEP`.
- Custom targets are used to limit what kinds of spans you are interested in, as the `BOOTSTRAP_TRACING=trace` output can be quite verbose. Currently, you can use the following custom targets:
- `CONFIG_HANDLING`: show spans related to config handling
- `STEP`: show all executed steps. Note that executed commands have `info` event level.
- `COMMAND`: show all executed commands. Note that executed commands have `trace` event level.

You can of course combine them (custom target logs are typically gated behind `TRACE` log level additionally):

```bash
$ BOOTSTRAP_TRACING=CONFIG_HANDLING=TRACE ./x build library --stage 1
$ BOOTSTRAP_TRACING=CONFIG_HANDLING=trace,STEP=info,COMMAND=trace ./x build library --stage 1
```

[^unstable]: This output is always subject to further changes.

[tracing-env-filter]: https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html

Note that the level that you specify using `BOOTSTRAP_TRACING` also has an effect on the spans that will be recorded in the Chrome trace file.

##### FIXME(#96176): specific tracing for `compiler()` vs `compiler_for()`

The additional targets `COMPILER` and `COMPILER_FOR` are used to help trace what
Expand All @@ -123,12 +103,6 @@ if [#96176][cleanup-compiler-for] is resolved.

[cleanup-compiler-for]: https://github.com/rust-lang/rust/issues/96176

### Rendering step graph

When you run bootstrap with the `BOOTSTRAP_TRACING` environment variable configured, bootstrap will automatically output a DOT file that shows all executed steps and their dependencies. The files will have a prefix `bootstrap-steps`. You can use e.g. `xdot` to visualize the file or e.g. `dot -Tsvg` to convert the DOT file to a SVG file.

A separate DOT file will be outputted for dry-run and non-dry-run execution.

### Using `tracing` in bootstrap

Both `tracing::*` macros and the `tracing::instrument` proc-macro attribute need to be gated behind `tracing` feature. Examples:
Expand All @@ -149,15 +123,6 @@ impl Step for Foo {
todo!()
}

#[cfg_attr(
feature = "tracing",
instrument(
level = "trace",
name = "Foo::run",
skip_all,
fields(compiler = ?builder.compiler),
),
)]
fn run(self, builder: &Builder<'_>) -> Self::Output {
trace!(?run, "entered Foo::run");

Expand All @@ -172,21 +137,6 @@ For `#[instrument]`, it's recommended to:
- Explicitly pick an instrumentation name via `name = ".."` to distinguish between e.g. `run` of different steps.
- Take care to not cause diverging behavior via tracing, e.g. building extra things only when tracing infra is enabled.

### Profiling bootstrap

You can set the `BOOTSTRAP_PROFILE=1` environment variable to enable command execution profiling during bootstrap. This generates:

* A Chrome trace file (for visualization in `chrome://tracing` or [Perfetto](https://ui.perfetto.dev)) if tracing is enabled via `BOOTSTRAP_TRACING=COMMAND=trace`
* A plain-text summary file, `bootstrap-profile-{pid}.txt`, listing all commands sorted by execution time (slowest first), along with cache hits and working directories

Note: the `.txt` report is always generated when `BOOTSTRAP_PROFILE=1` is set — tracing is not required.

Example usage:

```bash
$ BOOTSTRAP_PROFILE=1 BOOTSTRAP_TRACING=COMMAND=trace ./x build library
```

### rust-analyzer integration?

Unfortunately, because bootstrap is a `rust-analyzer.linkedProjects`, you can't ask r-a to check/build bootstrap itself with `tracing` feature enabled to get relevant completions, due to lack of support as described in <https://github.com/rust-lang/rust-analyzer/issues/8521>.
2 changes: 1 addition & 1 deletion src/building/optimized-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Here is an example of how can `opt-dist` be used locally (outside of CI):
```
3. Run the tool with the `local` mode and provide necessary parameters:
```bash
./build/host/stage0-tools-bin/opt-dist local \
./build/host/stage1-tools-bin/opt-dist local \
--target-triple <target> \ # select target, e.g. "x86_64-unknown-linux-gnu"
--checkout-dir <path> \ # path to rust checkout, e.g. "."
--llvm-dir <path> \ # path to built LLVM toolchain, e.g. "/foo/bar/llvm/install"
Expand Down
Loading