Skip to content

Commit 768f397

Browse files
committed
rustc-dev-guide: document BOOTSTRAP_LOG and bootstrap tracing setup
1 parent 6c13a24 commit 768f397

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/doc/rustc-dev-guide/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
- [Prologue](./building/bootstrapping/intro.md)
7676
- [What Bootstrapping does](./building/bootstrapping/what-bootstrapping-does.md)
7777
- [How Bootstrap does it](./building/bootstrapping/how-bootstrap-does-it.md)
78+
- [`tracing` in bootstrap](./building/bootstrapping/bootstrap-tracing.md)
7879

7980
# High-level Compiler Architecture
8081

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# `tracing` in bootstrap
2+
3+
To minimize bootstrap build times, `tracing` in bootstrap is gated behind the `logging` cargo feature, which in turn is activated by `bootstrap.py` (via `x.py`) if `BOOTSTRAP_LOG` env var is set.
4+
5+
## Using `tracing` in bootstrap
6+
7+
Due to the conditional compilation via the `logging` cargo feature, this means that `tracing` usages in bootstrap need to be also gated behind the `logging` feature:
8+
9+
- `tracing` macros (like `trace!`) and anything from `tracing`, `tracing_subscriber` and `tracing-tree` will need to be gated by `#[cfg(feature = "logging")]`.
10+
- `tracing`'s `#[instrument(..)]` macro will need to be gated like `#![cfg_attr(feature = "logging", instrument(..))]`.
11+
12+
## Enabling `logging` bootstrap feature in rust-analyzer
13+
14+
You can adjust your `settings.json`'s `rust-analyzer.check.overrideCommand` and `rust-analyzer.cargo.buildScripts.overrideCommand` if you want to also enable `logging` cargo feature by default in your editor. This is mostly useful if you want proper r-a completions and such when working on bootstrap itself.
15+
16+
```json
17+
"rust-analyzer.check.overrideCommand": [
18+
"BOOTSTRAP_LOG=1", // <- BOOTSTRAP_LOG=1 won't enable tracing filter, but it will activate bootstrap's `logging` feature
19+
"python3",
20+
"x.py",
21+
"check",
22+
"--json-output",
23+
"--build-dir=build-rust-analyzer"
24+
],
25+
```
26+
27+
```json
28+
"rust-analyzer.cargo.buildScripts.overrideCommand": [
29+
"BOOTSTRAP_LOG=1", // <- note this
30+
"python3",
31+
"x.py",
32+
"check",
33+
"--json-output",
34+
"--build-dir=build-rust-analyzer"
35+
],
36+
```

src/doc/rustc-dev-guide/src/building/bootstrapping/intro.md

+3
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ In this section, we give a high-level overview of
1717
[what Bootstrap does](./what-bootstrapping-does.md), followed by a high-level
1818
introduction to [how Bootstrap does it](./how-bootstrap-does-it.md).
1919

20+
See also [tracing in bootstrap](./bootstrap-tracing.md) for structured debug
21+
logging.
22+
2023
[boot]: https://en.wikipedia.org/wiki/Bootstrapping_(compilers)
2124
[ocaml-compiler]: https://github.com/rust-lang/rust/tree/ef75860a0a72f79f97216f8aaa5b388d98da6480/src/boot

0 commit comments

Comments
 (0)