Skip to content

Commit fb88941

Browse files
authored
Consolidate information about bootstrapping into one place (#851)
Previously, 'How to build and run' had a long section on the different stages of boostrap. But new contributors aren't interested in bootstrap; they want to start their build (because they heard it takes forever and want to start it so they aren't waiting more than necessary). This moves the section on stages into the bootstrapping page, and links there instead of discussing it on the main page.
1 parent d8db731 commit fb88941

File tree

2 files changed

+38
-50
lines changed

2 files changed

+38
-50
lines changed

src/building/bootstrapping.md

+36-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,41 @@ only way to build a modern version of rustc is a slightly less modern
1515
version.
1616

1717
This is exactly how `x.py` works: it downloads the current `beta` release of
18-
rustc, then uses it to compile the new compiler. The beta release is
19-
called `stage0` and the newly built compiler is `stage1` (or `stage0
20-
artifacts`). To get the full benefits of the new compiler (e.g. optimizations
21-
and new features), the `stage1` compiler then compiles _itself_ again. This
22-
last compiler is called `stage2` (or `stage1 artifacts`).
18+
rustc, then uses it to compile the new compiler.
19+
20+
## Stages of bootstrapping
21+
22+
Compiling `rustc` is done in stages:
23+
24+
- **Stage 0:** the stage0 compiler is usually (you can configure `x.py` to use
25+
something else) the current _beta_ `rustc` compiler and its associated dynamic
26+
libraries (which `x.py` will download for you). This stage0 compiler is then
27+
used only to compile `rustbuild`, `std`, and `rustc`. When compiling
28+
`rustc`, this stage0 compiler uses the freshly compiled `std`.
29+
There are two concepts at play here: a compiler (with its set of dependencies)
30+
and its 'target' or 'object' libraries (`std` and `rustc`).
31+
Both are staged, but in a staggered manner.
32+
- **Stage 1:** the code in your clone (for new version) is then
33+
compiled with the stage0 compiler to produce the stage1 compiler.
34+
However, it was built with an older compiler (stage0), so to
35+
optimize the stage1 compiler we go to next the stage.
36+
- In theory, the stage1 compiler is functionally identical to the
37+
stage2 compiler, but in practice there are subtle differences. In
38+
particular, the stage1 compiler itself was built by stage0 and
39+
hence not by the source in your working directory: this means that
40+
the symbol names used in the compiler source may not match the
41+
symbol names that would have been made by the stage1 compiler. This is
42+
important when using dynamic linking and the lack of ABI compatibility
43+
between versions. This primarily manifests when tests try to link with any
44+
of the `rustc_*` crates or use the (now deprecated) plugin infrastructure.
45+
These tests are marked with `ignore-stage1`.
46+
- **Stage 2:** we rebuild our stage1 compiler with itself to produce
47+
the stage2 compiler (i.e. it builds itself) to have all the _latest
48+
optimizations_. (By default, we copy the stage1 libraries for use by
49+
the stage2 compiler, since they ought to be identical.)
50+
- _(Optional)_ **Stage 3**: to sanity check our new compiler, we
51+
can build the libraries with the stage2 compiler. The result ought
52+
to be identical to before, unless something has broken.
2353

2454
The `stage2` compiler is the one distributed with `rustup` and all other
2555
install methods. However, it takes a very long time to build because one must
@@ -76,7 +106,7 @@ contribution [here][bootstrap-build].
76106

77107
[bootstrap-build]: https://github.com/rust-lang/rust/pull/71994
78108

79-
## Stages of bootstrap
109+
## Understanding stages of bootstrap
80110

81111
This is a detailed look into the separate bootstrap stages. When running
82112
`x.py` you will see output such as:

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

+2-44
Original file line numberDiff line numberDiff line change
@@ -80,50 +80,8 @@ effectively deal with the repo for various common tasks.
8080
This chapter focuses on the basics to be productive, but
8181
if you want to learn more about `x.py`, read its README.md
8282
[here](https://github.com/rust-lang/rust/blob/master/src/bootstrap/README.md).
83-
84-
## Bootstrapping
85-
86-
One thing to keep in mind is that `rustc` is a _bootstrapping_
87-
compiler. That is, since `rustc` is written in Rust, we need to use an
88-
older version of the compiler to compile the newer version. In
89-
particular, the newer version of the compiler and some of the artifacts needed
90-
to build it, such as `std` and other tooling, may use some unstable features
91-
internally, requiring a specific version which understands these unstable
92-
features.
93-
94-
The result is that compiling `rustc` is done in stages:
95-
96-
- **Stage 0:** the stage0 compiler is usually (you can configure `x.py` to use
97-
something else) the current _beta_ `rustc` compiler and its associated dynamic
98-
libraries (which `x.py` will download for you). This stage0 compiler is then
99-
used only to compile `rustbuild`, `std`, and `rustc`. When compiling
100-
`rustc`, this stage0 compiler uses the freshly compiled `std`.
101-
There are two concepts at play here: a compiler (with its set of dependencies)
102-
and its 'target' or 'object' libraries (`std` and `rustc`).
103-
Both are staged, but in a staggered manner.
104-
- **Stage 1:** the code in your clone (for new version) is then
105-
compiled with the stage0 compiler to produce the stage1 compiler.
106-
However, it was built with an older compiler (stage0), so to
107-
optimize the stage1 compiler we go to next the stage.
108-
- In theory, the stage1 compiler is functionally identical to the
109-
stage2 compiler, but in practice there are subtle differences. In
110-
particular, the stage1 compiler itself was built by stage0 and
111-
hence not by the source in your working directory: this means that
112-
the symbol names used in the compiler source may not match the
113-
symbol names that would have been made by the stage1 compiler. This is
114-
important when using dynamic linking and the lack of ABI compatibility
115-
between versions. This primarily manifests when tests try to link with any
116-
of the `rustc_*` crates or use the (now deprecated) plugin infrastructure.
117-
These tests are marked with `ignore-stage1`.
118-
- **Stage 2:** we rebuild our stage1 compiler with itself to produce
119-
the stage2 compiler (i.e. it builds itself) to have all the _latest
120-
optimizations_. (By default, we copy the stage1 libraries for use by
121-
the stage2 compiler, since they ought to be identical.)
122-
- _(Optional)_ **Stage 3**: to sanity check our new compiler, we
123-
can build the libraries with the stage2 compiler. The result ought
124-
to be identical to before, unless something has broken.
125-
126-
To read more about the bootstrap process, [read this chapter][bootstrap].
83+
To read more about the bootstrap process and why `x.py` is necessary,
84+
[read this chapter][bootstrap].
12785

12886
[bootstrap]: ./bootstrapping.md
12987

0 commit comments

Comments
 (0)