@@ -45,13 +45,13 @@ compiler.
45
45
46
46
``` mermaid
47
47
graph TD
48
- s0c["stage0 compiler (1.63 )"]:::downloaded -->|A| s0l("stage0 std (1.64 )"):::with-s0c ;
48
+ s0c["stage0 compiler (1.86.0-beta.1 )"]:::downloaded -->|A| s0l("stage0 std (1.86.0-beta.1 )"):::downloaded ;
49
49
s0c & s0l --- stepb[ ]:::empty;
50
- stepb -->|B| s0ca["stage0 compiler artifacts (1.64 )"]:::with-s0c;
51
- s0ca -->|copy| s1c["stage1 compiler (1.64 )"]:::with-s0c;
52
- s1c -->|C| s1l("stage1 std (1.64 )"):::with-s1c;
50
+ stepb -->|B| s0ca["stage0 compiler artifacts (1.87.0-dev )"]:::with-s0c;
51
+ s0ca -->|copy| s1c["stage1 compiler (1.87.0-dev )"]:::with-s0c;
52
+ s1c -->|C| s1l("stage1 std (1.87.0-dev )"):::with-s1c;
53
53
s1c & s1l --- stepd[ ]:::empty;
54
- stepd -->|D| s1ca["stage1 compiler artifacts (1.64 )"]:::with-s1c;
54
+ stepd -->|D| s1ca["stage1 compiler artifacts (1.87.0-dev )"]:::with-s1c;
55
55
s1ca -->|copy| s2c["stage2 compiler"]:::with-s1c;
56
56
57
57
classDef empty width:0px,height:0px;
@@ -62,19 +62,21 @@ graph TD
62
62
63
63
### Stage 0: the pre-compiled compiler
64
64
65
- The stage0 compiler is usually the current _ beta_ ` rustc ` compiler and its
65
+ The stage0 compiler is by default the very recent _ beta_ ` rustc ` compiler and its
66
66
associated dynamic libraries, which ` ./x.py ` will download for you. (You can
67
- also configure ` ./x.py ` to use something else.)
67
+ also configure ` ./x.py ` to change stage0 to something else.)
68
68
69
- The stage0 compiler is then used only to compile [ ` src/bootstrap ` ] ,
70
- [ ` library/std ` ] , and [ ` compiler/rustc ` ] . When assembling the libraries and
71
- binaries that will become the stage1 ` rustc ` compiler, the freshly compiled
72
- ` std ` and ` rustc ` are used. There are two concepts at play here: a compiler
73
- (with its set of dependencies) and its 'target' or 'object' libraries (` std ` and
74
- ` rustc ` ). Both are staged, but in a staggered manner.
69
+ The precompiled stage0 compiler is then used only to compile [ ` src/bootstrap ` ] and [ ` compiler/rustc ` ]
70
+ with precompiled stage0 std.
71
+
72
+ Note that to build the stage1 compiler we use the precompiled stage0 compiler and std.
73
+ Therefore, to use a compiler with a std that is freshly built from the tree, you need to
74
+ build the stage2 compiler.
75
+
76
+ There are two concepts at play here: a compiler (with its set of dependencies) and its
77
+ 'target' or 'object' libraries (` std ` and ` rustc ` ). Both are staged, but in a staggered manner.
75
78
76
79
[ `compiler/rustc` ] : https://github.com/rust-lang/rust/tree/master/compiler/rustc
77
- [ `library/std` ] : https://github.com/rust-lang/rust/tree/master/library/std
78
80
[ `src/bootstrap` ] : https://github.com/rust-lang/rust/tree/master/src/bootstrap
79
81
80
82
### Stage 1: from current code, by an earlier compiler
@@ -84,26 +86,25 @@ The rustc source code is then compiled with the `stage0` compiler to produce the
84
86
85
87
### Stage 2: the truly current compiler
86
88
87
- We then rebuild our ` stage1 ` compiler with itself to produce the ` stage2 `
89
+ We then rebuild the compiler using ` stage1 ` compiler with in-tree std to produce the ` stage2 `
88
90
compiler.
89
91
90
- In theory, the ` stage1 ` compiler is functionally identical to the ` stage2 `
91
- compiler, but in practice there are subtle differences. In particular, the
92
- ` stage1 ` compiler itself was built by ` stage0 ` and hence not by the source in
93
- your working directory. This means that the ABI generated by the ` stage0 `
94
- compiler may not match the ABI that would have been made by the ` stage1 `
95
- compiler, which can cause problems for dynamic libraries, tests, and tools using
96
- ` rustc_private ` .
92
+ The ` stage1 ` compiler itself was built by precompiled ` stage0 ` compiler and std
93
+ and hence not by the source in your working directory. This means that the ABI
94
+ generated by the ` stage0 ` compiler may not match the ABI that would have been made
95
+ by the ` stage1 ` compiler, which can cause problems for dynamic libraries, tests
96
+ and tools using ` rustc_private ` .
97
97
98
98
Note that the ` proc_macro ` crate avoids this issue with a ` C ` FFI layer called
99
99
` proc_macro::bridge ` , allowing it to be used with ` stage1 ` .
100
100
101
101
The ` stage2 ` compiler is the one distributed with ` rustup ` and all other install
102
102
methods. However, it takes a very long time to build because one must first
103
103
build the new compiler with an older compiler and then use that to build the new
104
- compiler with itself. For development, you usually only want the ` stage1 `
105
- compiler, which you can build with ` ./x build library ` . See [ Building the
106
- compiler] ( ../how-to-build-and-run.html#building-the-compiler ) .
104
+ compiler with itself.
105
+
106
+ For development, you usually only want to use ` --stage 1 ` flag to build things.
107
+ See [ Building the compiler] ( ../how-to-build-and-run.html#building-the-compiler ) .
107
108
108
109
### Stage 3: the same-result test
109
110
@@ -114,10 +115,11 @@ something has broken.
114
115
### Building the stages
115
116
116
117
The script [ ` ./x ` ] tries to be helpful and pick the stage you most likely meant
117
- for each subcommand. These defaults are as follows :
118
+ for each subcommand. Here are some ` x ` commands with their default stages :
118
119
119
- - ` check ` : ` --stage 0 `
120
- - ` doc ` : ` --stage 0 `
120
+ - ` check ` : ` --stage 1 `
121
+ - ` clippy ` : ` --stage 1 `
122
+ - ` doc ` : ` --stage 1 `
121
123
- ` build ` : ` --stage 1 `
122
124
- ` test ` : ` --stage 1 `
123
125
- ` dist ` : ` --stage 2 `
@@ -191,8 +193,8 @@ include, but are not limited to:
191
193
without building ` rustc ` from source ('build with ` stage0 ` , then test the
192
194
artifacts'). If you're working on the standard library, this is normally the
193
195
test command you want.
194
- - ` ./x build --stage 0 ` means to build with the beta ` rustc ` .
195
- - ` ./x doc --stage 0 ` means to document using the beta ` rustdoc ` .
196
+ - ` ./x build --stage 0 ` means to build with the stage0 ` rustc ` .
197
+ - ` ./x doc --stage 0 ` means to document using the stage0 ` rustdoc ` .
196
198
197
199
#### Examples of what * not* to do
198
200
@@ -208,9 +210,6 @@ include, but are not limited to:
208
210
209
211
### Building vs. running
210
212
211
- Note that ` build --stage N compiler/rustc ` ** does not** build the stage N
212
- compiler: instead it builds the stage N+1 compiler _ using_ the stage N compiler.
213
-
214
213
In short, _ stage 0 uses the ` stage0 ` compiler to create ` stage0 ` artifacts which
215
214
will later be uplifted to be the stage1 compiler_ .
216
215
@@ -268,23 +267,6 @@ However, when cross-compiling, `stage1` `std` will only run on the host. So the
268
267
269
268
(See in the table how ` stage2 ` only builds non-host ` std ` targets).
270
269
271
- ### Why does only libstd use ` cfg(bootstrap) ` ?
272
-
273
- For docs on ` cfg(bootstrap) ` itself, see [ Complications of
274
- Bootstrapping] ( #complications-of-bootstrapping ) .
275
-
276
- The ` rustc ` generated by the ` stage0 ` compiler is linked to the freshly-built
277
- ` std ` , which means that for the most part only ` std ` needs to be ` cfg ` -gated, so
278
- that ` rustc ` can use features added to ` std ` immediately after their addition,
279
- without need for them to get into the downloaded ` beta ` compiler.
280
-
281
- Note this is different from any other Rust program: ` stage1 ` ` rustc ` is built by
282
- the _ beta_ compiler, but using the _ master_ version of ` libstd ` !
283
-
284
- The only time ` rustc ` uses ` cfg(bootstrap) ` is when it adds internal lints that
285
- use diagnostic items, or when it uses unstable library features that were
286
- recently changed.
287
-
288
270
### What is a 'sysroot'?
289
271
290
272
When you build a project with ` cargo ` , the build artifacts for dependencies are
@@ -459,7 +441,6 @@ compiler itself uses to run. These aren't actually used by artifacts the new
459
441
compiler generates. This step also copies the ` rustc ` and ` rustdoc ` binaries we
460
442
generated into ` build/$HOST/stage/bin ` .
461
443
462
- The ` stage1/bin/rustc ` is a fully functional compiler, but it doesn't yet have
463
- any libraries to link built binaries or libraries to. The next 3 steps will
464
- provide those libraries for it; they are mostly equivalent to constructing the
465
- ` stage1/bin ` compiler so we don't go through them individually here.
444
+ The ` stage1/bin/rustc ` is a fully functional compiler built with stage0 (precompiled) compiler and std.
445
+ To use a compiler built entirely from source with the in-tree compiler and std, you need to build the
446
+ stage2 compiler, which is compiled using the stage1 (in-tree) compiler and std.
0 commit comments