Skip to content

Commit 3ee7880

Browse files
committed
Fix and clean up the terminology for stages
- Use 'stage0 rustc' to mean `stage0-rustc` - Use 'bootstrap' to mean `build/$target/stage0` (i.e. the beta compiler) - Mention that 'ignore-stage1' means 'ignore programs linked to stage1', not built by it.
1 parent 7f71c09 commit 3ee7880

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

src/building/bootstrapping.md

+41
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,47 @@ contribution [here][bootstrap-build].
7878

7979
## Stages of bootstrap
8080

81+
Like most other bootstrapping compilers, `rustc` is compiled in stages.
82+
_Unlike_ most other compilers, where `stage0` refers to the bootstrap compiler,
83+
`stage0` refers to the first compiler built by bootstrap. So the following command:
84+
85+
```sh
86+
x.py build --stage 0 src/rustc
87+
```
88+
89+
will actually perform a full build of rustc. Confusingly, the `build/$target/stageN` directories are named after the compiler they are *used to build*, not the commands you need to build them.
90+
91+
- **Stage 0:** The stage0 compiler is built by the bootstrap compiler.
92+
The bootstrap compiler is usually (you can configure `x.py` to use
93+
something else) the current _beta_ `rustc` compiler and its associated dynamic
94+
libraries (which `x.py` will download for you). This bootstrap compiler is then
95+
used to compile `rustbuild`, `std`, and `rustc` (plus a few other tools, like `tidy`). When compiling
96+
`rustc`, this bootstrap compiler uses the freshly compiled `std`.
97+
There are two concepts at play here: a compiler (with its set of dependencies)
98+
and its 'target' or 'object' libraries (`std` and `rustc`).
99+
Both are staged, but in a staggered manner.
100+
The `stage0` standard library is the one _linked_ to `stage0` rustc
101+
(allowing you to `use std::vec::Vec` from within the compiler itself),
102+
while `stage1 libstd` is the library _built_ by stage1. `libstd` also include `libcore`,
103+
so without it there are very few programs that rustc can compile.
104+
105+
- **Stage 1:** In theory, the stage0 compiler is functionally identical to the
106+
stage1 compiler, but in practice there are subtle differences. In
107+
particular, the stage0 compiler was built by bootstrap and
108+
hence not by the source in your working directory: this means that
109+
the symbol names used in the compiler source may not match the
110+
symbol names that would have been made by the stage1 compiler. This is
111+
important when using dynamic linking because Rust does not have ABI compatibility
112+
between versions. This primarily manifests when tests try to link with any
113+
of the `rustc_*` crates or use the (now deprecated) plugin infrastructure.
114+
These tests are marked with `ignore-stage1`. The `stage1` is because
115+
these plugins *link* to the stage1 compiler, even though they are being
116+
*built* by stage0. Rebuilding again also gives us the benefit of the latest optimizations (i.e. those added since the beta fork).
117+
118+
- _(Optional)_ **Stage 2**: to sanity check our new compiler, we
119+
can build the libraries with the stage1 compiler. The result ought
120+
to be identical to before, unless something has broken.
121+
81122
This is a detailed look into the separate bootstrap stages. When running
82123
`x.py` you will see output such as:
83124

src/building/how-to-build-and-run.md

-32
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,6 @@ to build it, such as `libstd` and other tooling, may use some unstable features
109109
internally, requiring a specific version which understands these unstable
110110
features.
111111

112-
The result is that compiling `rustc` is done in stages:
113-
114-
- **Stage 0:** the stage0 compiler is usually (you can configure `x.py` to use
115-
something else) the current _beta_ `rustc` compiler and its associated dynamic
116-
libraries (which `x.py` will download for you). This stage0 compiler is then
117-
used only to compile `rustbuild`, `std`, and `rustc`. When compiling
118-
`rustc`, this stage0 compiler uses the freshly compiled `std`.
119-
There are two concepts at play here: a compiler (with its set of dependencies)
120-
and its 'target' or 'object' libraries (`std` and `rustc`).
121-
Both are staged, but in a staggered manner.
122-
- **Stage 1:** the code in your clone (for new version) is then
123-
compiled with the stage0 compiler to produce the stage1 compiler.
124-
However, it was built with an older compiler (stage0), so to
125-
optimize the stage1 compiler we go to next the stage.
126-
- In theory, the stage1 compiler is functionally identical to the
127-
stage2 compiler, but in practice there are subtle differences. In
128-
particular, the stage1 compiler itself was built by stage0 and
129-
hence not by the source in your working directory: this means that
130-
the symbol names used in the compiler source may not match the
131-
symbol names that would have been made by the stage1 compiler. This is
132-
important when using dynamic linking and the lack of ABI compatibility
133-
between versions. This primarily manifests when tests try to link with any
134-
of the `rustc_*` crates or use the (now deprecated) plugin infrastructure.
135-
These tests are marked with `ignore-stage1`.
136-
- **Stage 2:** we rebuild our stage1 compiler with itself to produce
137-
the stage2 compiler (i.e. it builds itself) to have all the _latest
138-
optimizations_. (By default, we copy the stage1 libraries for use by
139-
the stage2 compiler, since they ought to be identical.)
140-
- _(Optional)_ **Stage 3**: to sanity check our new compiler, we
141-
can build the libraries with the stage2 compiler. The result ought
142-
to be identical to before, unless something has broken.
143-
144112
To read more about the bootstrap process, [read this chapter][bootstrap].
145113

146114
[bootstrap]: ./bootstrapping.md

0 commit comments

Comments
 (0)