@@ -15,11 +15,41 @@ only way to build a modern version of rustc is a slightly less modern
1515version.
1616
1717This 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
2454The ` stage2 ` compiler is the one distributed with ` rustup ` and all other
2555install 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
81111This is a detailed look into the separate bootstrap stages. When running
82112` x.py ` you will see output such as:
0 commit comments