Skip to content

Commit 8b6ead1

Browse files
committed
update dev guidelines
Signed-off-by: onur-ozkan <[email protected]>
1 parent a0e475a commit 8b6ead1

File tree

3 files changed

+41
-61
lines changed

3 files changed

+41
-61
lines changed

src/doc/rustc-dev-guide/src/building/bootstrapping/what-bootstrapping-does.md

+34-52
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ compiler.
4545

4646
```mermaid
4747
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;
4949
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;
5353
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;
5555
s1ca -->|copy| s2c["stage2 compiler"]:::with-s1c;
5656
5757
classDef empty width:0px,height:0px;
@@ -62,19 +62,22 @@ graph TD
6262

6363
### Stage 0: the pre-compiled compiler
6464

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
6666
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.)
6868

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 stage0 compiler is then used only to compile [`src/bootstrap`] and [`compiler/rustc`].
70+
When assembling the libraries and binaries that will become the stage1 `rustc` compiler,
71+
the freshly compiled `rustc` and beta `std` are used.
72+
73+
Note that to build the stage1 compiler we use the precompiled beta compiler and beta std from stage0.
74+
Therefore, to use a compiler with a std that is freshly built from the tree, you need to build the
75+
stage2 compiler.
76+
77+
There are two concepts at play here: a compiler (with its set of dependencies) and its
78+
'target' or 'object' libraries (`std` and `rustc`). Both are staged, but in a staggered manner.
7579

7680
[`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
7881
[`src/bootstrap`]: https://github.com/rust-lang/rust/tree/master/src/bootstrap
7982

8083
### Stage 1: from current code, by an earlier compiler
@@ -84,26 +87,25 @@ The rustc source code is then compiled with the `stage0` compiler to produce the
8487

8588
### Stage 2: the truly current compiler
8689

87-
We then rebuild our `stage1` compiler with itself to produce the `stage2`
90+
We then rebuild our `stage1` compiler with in-tree std to produce the `stage2`
8891
compiler.
8992

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`.
93+
The `stage1` compiler itself was built by precompiled `stage0` compiler and std
94+
and hence not by the source in your working directory. This means that the ABI
95+
generated by the `stage0` compiler may not match the ABI that would have been made
96+
by the `stage1` compiler, which can cause problems for dynamic libraries, tests
97+
and tools using `rustc_private`.
9798

9899
Note that the `proc_macro` crate avoids this issue with a `C` FFI layer called
99100
`proc_macro::bridge`, allowing it to be used with `stage1`.
100101

101102
The `stage2` compiler is the one distributed with `rustup` and all other install
102103
methods. However, it takes a very long time to build because one must first
103104
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).
105+
compiler with itself.
106+
107+
For development, you usually only want to use `--stage 1` flag to build things.
108+
See [Building the compiler](../how-to-build-and-run.html#building-the-compiler).
107109

108110
### Stage 3: the same-result test
109111

@@ -114,10 +116,11 @@ something has broken.
114116
### Building the stages
115117

116118
The script [`./x`] tries to be helpful and pick the stage you most likely meant
117-
for each subcommand. These defaults are as follows:
119+
for each subcommand. Here are some `x` commands with their default stages:
118120

119-
- `check`: `--stage 0`
120-
- `doc`: `--stage 0`
121+
- `check`: `--stage 1`
122+
- `clippy`: `--stage 1`
123+
- `doc`: `--stage 1`
121124
- `build`: `--stage 1`
122125
- `test`: `--stage 1`
123126
- `dist`: `--stage 2`
@@ -208,9 +211,6 @@ include, but are not limited to:
208211

209212
### Building vs. running
210213

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-
214214
In short, _stage 0 uses the `stage0` compiler to create `stage0` artifacts which
215215
will later be uplifted to be the stage1 compiler_.
216216

@@ -268,23 +268,6 @@ However, when cross-compiling, `stage1` `std` will only run on the host. So the
268268

269269
(See in the table how `stage2` only builds non-host `std` targets).
270270

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-
288271
### What is a 'sysroot'?
289272

290273
When you build a project with `cargo`, the build artifacts for dependencies are
@@ -459,7 +442,6 @@ compiler itself uses to run. These aren't actually used by artifacts the new
459442
compiler generates. This step also copies the `rustc` and `rustdoc` binaries we
460443
generated into `build/$HOST/stage/bin`.
461444

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.
445+
The `stage1/bin/rustc` is a fully functional compiler built with the beta compiler and std.
446+
To use a compiler built entirely from source with the in-tree compiler and std, you need to build
447+
the stage2 compiler, which is compiled using the stage1 compiler and std.

src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ probably the best "go to" command for building a local compiler:
217217
This may *look* like it only builds the standard library, but that is not the case.
218218
What this command does is the following:
219219

220-
- Build `std` using the stage0 compiler
221220
- Build `rustc` using the stage0 compiler
222221
- This produces the stage1 compiler
223222
- Build `std` using the stage1 compiler
@@ -241,23 +240,22 @@ build. The **full** `rustc` build (what you get with `./x build
241240
--stage 2 compiler/rustc`) has quite a few more steps:
242241

243242
- Build `rustc` with the stage1 compiler.
244-
- The resulting compiler here is called the "stage2" compiler.
245-
- Build `std` with stage2 compiler.
243+
- The resulting compiler here is called the "stage2" compiler, which uses stage1 std from the previous command.
246244
- Build `librustdoc` and a bunch of other things with the stage2 compiler.
247245

248246
You almost never need to do this.
249247

250248
### Build specific components
251249

252250
If you are working on the standard library, you probably don't need to build
253-
the compiler unless you are planning to use a recently added nightly feature.
254-
Instead, you can just build using the bootstrap compiler.
251+
every other default component. Instead, you can build a specific component by
252+
providing its name, like this:
255253

256254
```bash
257-
./x build --stage 0 library
255+
./x build --stage 1 library
258256
```
259257

260-
If you choose the `library` profile when running `x setup`, you can omit `--stage 0` (it's the
258+
If you choose the `library` profile when running `x setup`, you can omit `--stage 1` (it's the
261259
default).
262260

263261
## Creating a rustup toolchain
@@ -271,7 +269,7 @@ you will likely need to build at some point; for example, if you want
271269
to run the entire test suite).
272270

273271
```bash
274-
rustup toolchain link stage0 build/host/stage0-sysroot # beta compiler + stage0 std
272+
rustup toolchain link stage0 build/host/stage0-sysroot # beta compiler + beta std
275273
rustup toolchain link stage1 build/host/stage1
276274
rustup toolchain link stage2 build/host/stage2
277275
```

src/doc/rustc-dev-guide/src/tests/ci.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ kinds of builds (sets of jobs).
6868
After each push to a pull request, a set of `pr` jobs are executed. Currently,
6969
these execute the `x86_64-gnu-llvm-X`, `x86_64-gnu-tools`, `mingw-check-1`, `mingw-check-2`
7070
and `mingw-check-tidy` jobs, all running on Linux. These execute a relatively short
71-
(~30 minutes) and lightweight test suite that should catch common issues. More
71+
(~40 minutes) and lightweight test suite that should catch common issues. More
7272
specifically, they run a set of lints, they try to perform a cross-compile check
7373
build to Windows mingw (without producing any artifacts) and they test the
7474
compiler using a *system* version of LLVM. Unfortunately, it would take too many

0 commit comments

Comments
 (0)