Rollup merge of #135391 - jieyouxu:conditional-tracing, r=onur-ozkan
bootstrap: Implement conditional `tracing` infra Add a conditional `tracing` setup that is gated behind `BOOTSTRAP_TRACING` env var. This `tracing` infra is implemented by: - Introducing an optional `tracing` cargo feature in bootstrap. - Added optional `tracing*` dependencies which are gated behind the `tracing` cargo feature. - When `BOOTSTRAP_TRACING` is set, `bootstrap.py` will build bootstrap with `--features=tracing`. There is a small trick here to share `BOOTSTRAP_TRACING` env var without having to add a separate env var: - `BOOTSTRAP_TRACING=1` is not a registered `tracing` filter target, so that can be used to enable the `tracing` cargo feature yet not actually enable any tracing logs (useful for editor r-a setups without actually outputting any tracing logs). - `BOOTSTRAP_TRACING=TRACE` and such are actually valid `tracing` filters, but that sets `BOOTSTRAP_TRACING` anyway. Example usage: https://github.com/rust-lang/rust/pull/135299 (that experimental PR is not conditionally gated) This PR is intentionally kept minimal to focus on the infra itself. To get actual mileage, instrumentations will need to be added to individual `Step`s and such. r? `@onur-ozkan` (or reroll)
This commit is contained in:
commit
94e1724a88
|
|
@ -75,6 +75,7 @@
|
|||
- [Prologue](./building/bootstrapping/intro.md)
|
||||
- [What Bootstrapping does](./building/bootstrapping/what-bootstrapping-does.md)
|
||||
- [How Bootstrap does it](./building/bootstrapping/how-bootstrap-does-it.md)
|
||||
- [Debugging bootstrap](./building/bootstrapping/debugging-bootstrap.md)
|
||||
|
||||
# High-level Compiler Architecture
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,100 @@
|
|||
# Debugging bootstrap
|
||||
|
||||
> FIXME: this page could be expanded
|
||||
|
||||
## `tracing` in bootstrap
|
||||
|
||||
Bootstrap has conditional [`tracing`][tracing] setup to provide structured logging.
|
||||
|
||||
[tracing]: https://docs.rs/tracing/0.1.41/tracing/index.html
|
||||
|
||||
### Enabling `tracing` output
|
||||
|
||||
Bootstrap will conditionally enable `tracing` output if the `BOOTSTRAP_TRACING` env var is set.
|
||||
|
||||
Example usage:
|
||||
|
||||
```bash
|
||||
$ BOOTSTRAP_TRACING=TRACE ./x build library --stage 1
|
||||
```
|
||||
|
||||
Example output[^experimental]:
|
||||
|
||||

|
||||
|
||||
[^experimental]: This shows what's *possible* with the infra in an experimental implementation.
|
||||
|
||||
The env var `BOOTSTRAP_TRACING` accepts a [`tracing` env-filter][tracing-env-filter]. The `TRACE` filter will enable *all* `trace` level or less verbose level tracing output.
|
||||
|
||||
[tracing-env-filter]: https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html
|
||||
|
||||
### Using `tracing` in bootstrap
|
||||
|
||||
Both `tracing::*` macros and the `tracing::instrument` proc-macro attribute need to be gated behind `tracing` feature. Examples:
|
||||
|
||||
```rs
|
||||
#[cfg(feature = "tracing")]
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Step for Foo {
|
||||
type Output = ();
|
||||
|
||||
#[cfg_attr(feature = "tracing", instrument(level = "trace", name = "Foo::should_run", skip_all))]
|
||||
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||
#[cfg(feature = "tracing")]
|
||||
trace!(?run, "entered Foo::should_run");
|
||||
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "tracing",
|
||||
instrument(
|
||||
level = "trace",
|
||||
name = "Foo::run",
|
||||
skip_all,
|
||||
fields(compiler = ?builder.compiler),
|
||||
),
|
||||
)]
|
||||
fn run(self, builder: &Builder<'_>) -> Self::Output {
|
||||
#[cfg(feature = "tracing")]
|
||||
trace!(?run, "entered Foo::run");
|
||||
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For `#[instrument]`, it's recommended to:
|
||||
|
||||
- Gate it behind `trace` level for fine-granularity, possibly `debug` level for core functions.
|
||||
- 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.
|
||||
|
||||
### Enabling `tracing` bootstrap feature in rust-analyzer
|
||||
|
||||
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.
|
||||
|
||||
```json
|
||||
"rust-analyzer.check.overrideCommand": [
|
||||
"BOOTSTRAP_TRACING=1", // <- BOOTSTRAP_TRACING=1 won't enable tracing filter, but it will activate bootstrap's `tracing` feature
|
||||
"python3",
|
||||
"x.py",
|
||||
"check",
|
||||
"--json-output",
|
||||
"--build-dir=build-rust-analyzer"
|
||||
],
|
||||
```
|
||||
|
||||
```json
|
||||
"rust-analyzer.cargo.buildScripts.overrideCommand": [
|
||||
"BOOTSTRAP_TRACING=1", // <- note this
|
||||
"python3",
|
||||
"x.py",
|
||||
"check",
|
||||
"--json-output",
|
||||
"--build-dir=build-rust-analyzer"
|
||||
],
|
||||
```
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 137 KiB |
|
|
@ -17,5 +17,8 @@ In this section, we give a high-level overview of
|
|||
[what Bootstrap does](./what-bootstrapping-does.md), followed by a high-level
|
||||
introduction to [how Bootstrap does it](./how-bootstrap-does-it.md).
|
||||
|
||||
Additionally, see [debugging bootstrap](./debugging-bootstrap.md) to learn
|
||||
about debugging methods.
|
||||
|
||||
[boot]: https://en.wikipedia.org/wiki/Bootstrapping_(compilers)
|
||||
[ocaml-compiler]: https://github.com/rust-lang/rust/tree/ef75860a0a72f79f97216f8aaa5b388d98da6480/src/boot
|
||||
|
|
|
|||
Loading…
Reference in New Issue