Skip to content

Commit 27dffea

Browse files
committed
Auto merge of #137215 - onur-ozkan:rustc-tool-build-stages, r=jieyouxu,Kobzol
stabilize stage management for rustc tools rust-lang/rust#135990 got out of control due to excessive complexity. This PR aims to achieve the same goal with a simpler approach, likely through multiple smaller PRs. I will keep the other one read-only and open as a reference for future work. This work stabilizes the staging logic for `ToolRustc` programs, so you no longer need to handle build and target compilers separately in steps. Previously, most tools didn't do this correctly, which was causing the compiler to be built twice (e.g., `x test cargo --stage 1` would compile the stage 2 compiler before, but now it only compiles the stage 1 compiler). I also tried to document how we should write `ToolRustc` steps as they are quite different and require more attention than other tools. Next goal is to stabilize how stages are handled for the rustc itself. Currently, `x build --stage 1` builds the stage 1 compiler which is fine, but `x build compiler --stage 1` builds stage 2 compiler. ~~for now, r? ghost~~
2 parents 3f70a2f + 97b80c8 commit 27dffea

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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+
- [Writing tools in Bootstrap](./building/bootstrapping/writing-tools-in-bootstrap.md)
7879
- [Debugging bootstrap](./building/bootstrapping/debugging-bootstrap.md)
7980

8081
# High-level Compiler Architecture
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Writing tools in Bootstrap
2+
3+
There are three types of tools you can write in bootstrap:
4+
5+
- **`Mode::ToolBootstrap`**
6+
Use this for tools that don’t need anything from the in-tree compiler and can run with the stage0 `rustc`.
7+
The output is placed in the "stage0-bootstrap-tools" directory. This mode is for general-purpose tools built
8+
entirely with the stage0 compiler, including target libraries and only works for stage 0.
9+
10+
- **`Mode::ToolStd`**
11+
Use this for tools that rely on the locally built std. The output goes into the "stageN-tools" directory.
12+
This mode is rarely used, mainly for `compiletest` which requires `libtest`.
13+
14+
- **`Mode::ToolRustc`**
15+
Use this for tools that depend on both the locally built `rustc` and the target `std`. This is more complex than
16+
the other modes because the tool must be built with the same compiler used for `rustc` and placed in the "stageN-tools"
17+
directory. When you choose `Mode::ToolRustc`, `ToolBuild` implementation takes care of this automatically.
18+
If you need to use the builder’s compiler for something specific, you can get it from `ToolBuildResult`, which is
19+
returned by the tool's [`Step`].
20+
21+
Regardless of the tool type you must return `ToolBuildResult` from the tool’s [`Step`] implementation and use `ToolBuild` inside it.
22+
23+
[`Step`]: https://doc.rust-lang.org/nightly/nightly-rustc/bootstrap/core/builder/trait.Step.html

0 commit comments

Comments
 (0)