Skip to content

Commit 4742200

Browse files
committed
improve comments and docs
Signed-off-by: onur-ozkan <[email protected]>
1 parent 8ee015b commit 4742200

File tree

10 files changed

+36
-73
lines changed

10 files changed

+36
-73
lines changed

src/bootstrap/defaults/bootstrap.library.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# These defaults are meant for contributors to the standard library and documentation.
22
[build]
3-
# When building the standard library, you almost never want to build the compiler itself.
43
build-stage = 1
54
test-stage = 1
65
bench-stage = 1
@@ -10,8 +9,10 @@ bench-stage = 1
109
incremental = true
1110
# Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown.
1211
lto = "off"
13-
# Download rustc by default for library profile if compiler-affecting
14-
# directories are not modified. For CI this is disabled.
12+
# When building the standard library, you almost never want to build the compiler itself.
13+
#
14+
# If compiler-affecting directories are not modified, use precompiled rustc to speed up
15+
# library development by skipping compiler builds.
1516
download-rustc = "if-unchanged"
1617

1718
[llvm]

src/bootstrap/src/core/build_steps/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Step for Std {
6666
let compiler = builder.compiler(builder.top_stage, builder.config.build);
6767

6868
if builder.top_stage == 0 {
69-
// Reuse the beta compiler's libstd
69+
// Reuse the stage0 libstd
7070
builder.ensure(compile::Std::new(compiler, target));
7171
return;
7272
}

src/bootstrap/src/core/build_steps/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ impl Step for Rustc {
10321032
let compiler = self.compiler;
10331033
let target = self.target;
10341034

1035-
// NOTE: the ABI of the beta compiler is different from the ABI of the downloaded compiler,
1035+
// NOTE: the ABI of the stage0 compiler is different from the ABI of the downloaded compiler,
10361036
// so its artifacts can't be reused.
10371037
if builder.download_rustc() && compiler.stage != 0 {
10381038
trace!(stage = compiler.stage, "`download_rustc` requested");
@@ -1787,9 +1787,9 @@ impl Step for Sysroot {
17871787
t!(fs::create_dir_all(&sysroot));
17881788

17891789
// In some cases(see https://github.com/rust-lang/rust/issues/109314), when the stage0
1790-
// compiler relies on more recent version of LLVM than the beta compiler, it may not
1790+
// compiler relies on more recent version of LLVM than the stage0 compiler, it may not
17911791
// be able to locate the correct LLVM in the sysroot. This situation typically occurs
1792-
// when we upgrade LLVM version while the beta compiler continues to use an older version.
1792+
// when we upgrade LLVM version while the stage0 compiler continues to use an older version.
17931793
//
17941794
// Make sure to add the correct version of LLVM into the stage0 sysroot.
17951795
if compiler.stage == 0 {

src/bootstrap/src/core/build_steps/test.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ impl Step for Compiletest {
15701570

15711571
if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
15721572
eprintln!("\
1573-
ERROR: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1573+
ERROR: `--stage 0` runs compiletest on the stage0 (precompiled) compiler, not your local changes, and will almost always cause tests to fail
15741574
HELP: to test the compiler, use `--stage 1` instead
15751575
HELP: to test the standard library, use `--stage 0 library/std` instead
15761576
NOTE: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `COMPILETEST_FORCE_STAGE0=1`."
@@ -1598,9 +1598,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
15981598
// NOTE: Only stage 1 is special cased because we need the rustc_private artifacts to match the
15991599
// running compiler in stage 2 when plugins run.
16001600
let (stage, stage_id) = if suite == "ui-fulldeps" && compiler.stage == 1 {
1601-
// At stage 0 (stage - 1) we are using the beta compiler. Using `self.target` can lead
1602-
// finding an incorrect compiler path on cross-targets, as the stage 0 beta compiler is
1603-
// always equal to `build.build` in the configuration.
1601+
// At stage 0 (stage - 1) we are using the stage0 compiler. Using `self.target` can lead
1602+
// finding an incorrect compiler path on cross-targets, as the stage 0 is always equal to
1603+
// `build.build` in the configuration.
16041604
let build = builder.build.build;
16051605
compiler = builder.compiler(compiler.stage - 1, build);
16061606
let test_stage = compiler.stage + 1;
@@ -1694,7 +1694,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
16941694
}
16951695

16961696
if mode == "rustdoc-json" {
1697-
// Use the beta compiler for jsondocck
1697+
// Use the stage0 compiler for jsondocck
16981698
let json_compiler = compiler.with_stage(0);
16991699
cmd.arg("--jsondocck-path")
17001700
.arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }).tool_path);

src/bootstrap/src/core/builder/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ mod defaults {
394394
first(cache.all::<tool::ErrorIndex>()),
395395
&[tool::ErrorIndex { compiler: Compiler::new(1, a) }]
396396
);
397-
// docs should be built with the beta compiler, not with the stage0 artifacts.
397+
// docs should be built with the stage0 compiler, not with the stage0 artifacts.
398398
// recall that rustdoc is off-by-one: `stage` is the compiler rustdoc is _linked_ to,
399399
// not the one it was built by.
400400
assert_eq!(

src/bootstrap/src/core/download.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl Config {
662662
}
663663
};
664664

665-
// For the beta compiler, put special effort into ensuring the checksums are valid.
665+
// For the stage0 compiler, put special effort into ensuring the checksums are valid.
666666
let checksum = if should_verify {
667667
let error = format!(
668668
"src/stage0 doesn't contain a checksum for {url}. \

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,12 @@ The stage0 compiler is by default the very recent _beta_ `rustc` compiler and it
6666
associated dynamic libraries, which `./x.py` will download for you. (You can
6767
also configure `./x.py` to change stage0 to something else.)
6868

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.
69+
The precompiled stage0 compiler is then used only to compile [`src/bootstrap`] and [`compiler/rustc`]
70+
with precompiled stage0 std.
7271

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.
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.
7675

7776
There are two concepts at play here: a compiler (with its set of dependencies) and its
7877
'target' or 'object' libraries (`std` and `rustc`). Both are staged, but in a staggered manner.
@@ -87,7 +86,7 @@ The rustc source code is then compiled with the `stage0` compiler to produce the
8786

8887
### Stage 2: the truly current compiler
8988

90-
We then rebuild our `stage1` compiler with in-tree std to produce the `stage2`
89+
We then rebuild the compiler using `stage1` compiler with in-tree std to produce the `stage2`
9190
compiler.
9291

9392
The `stage1` compiler itself was built by precompiled `stage0` compiler and std
@@ -194,8 +193,8 @@ include, but are not limited to:
194193
without building `rustc` from source ('build with `stage0`, then test the
195194
artifacts'). If you're working on the standard library, this is normally the
196195
test command you want.
197-
- `./x build --stage 0` means to build with the beta `rustc`.
198-
- `./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`.
199198

200199
#### Examples of what *not* to do
201200

@@ -442,6 +441,6 @@ compiler itself uses to run. These aren't actually used by artifacts the new
442441
compiler generates. This step also copies the `rustc` and `rustdoc` binaries we
443442
generated into `build/$HOST/stage/bin`.
444443

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.
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.

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

-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ you will likely need to build at some point; for example, if you want
269269
to run the entire test suite).
270270

271271
```bash
272-
rustup toolchain link stage0 build/host/stage0-sysroot # beta compiler + beta std
273272
rustup toolchain link stage1 build/host/stage1
274273
rustup toolchain link stage2 build/host/stage2
275274
```

src/doc/rustc-dev-guide/src/building/new-target.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Look for existing targets to use as examples.
8585
After adding your target to the `rustc_target` crate you may want to add
8686
`core`, `std`, ... with support for your new target. In that case you will
8787
probably need access to some `target_*` cfg. Unfortunately when building with
88-
stage0 (the beta compiler), you'll get an error that the target cfg is
88+
stage0 (a precompiled compiler), you'll get an error that the target cfg is
8989
unexpected because stage0 doesn't know about the new target specification and
9090
we pass `--check-cfg` in order to tell it to check.
9191

src/doc/rustc-dev-guide/src/building/suggested.md

+9-45
Original file line numberDiff line numberDiff line change
@@ -273,51 +273,15 @@ lets you use `cargo fmt`.
273273
[the section on vscode]: suggested.md#configuring-rust-analyzer-for-rustc
274274
[the section on rustup]: how-to-build-and-run.md?highlight=rustup#creating-a-rustup-toolchain
275275

276-
## Faster builds with `--keep-stage`.
277-
278-
Sometimes just checking whether the compiler builds is not enough. A common
279-
example is that you need to add a `debug!` statement to inspect the value of
280-
some state or better understand the problem. In that case, you don't really need
281-
a full build. By bypassing bootstrap's cache invalidation, you can often get
282-
these builds to complete very fast (e.g., around 30 seconds). The only catch is
283-
this requires a bit of fudging and may produce compilers that don't work (but
284-
that is easily detected and fixed).
285-
286-
The sequence of commands you want is as follows:
287-
288-
- Initial build: `./x build library`
289-
- As [documented previously], this will build a functional stage1 compiler as
290-
part of running all stage0 commands (which include building a `std`
291-
compatible with the stage1 compiler) as well as the first few steps of the
292-
"stage 1 actions" up to "stage1 (sysroot stage1) builds std".
293-
- Subsequent builds: `./x build library --keep-stage 1`
294-
- Note that we added the `--keep-stage 1` flag here
295-
296-
[documented previously]: ./how-to-build-and-run.md#building-the-compiler
297-
298-
As mentioned, the effect of `--keep-stage 1` is that we just _assume_ that the
299-
old standard library can be re-used. If you are editing the compiler, this is
300-
almost always true: you haven't changed the standard library, after all. But
301-
sometimes, it's not true: for example, if you are editing the "metadata" part of
302-
the compiler, which controls how the compiler encodes types and other states
303-
into the `rlib` files, or if you are editing things that wind up in the metadata
304-
(such as the definition of the MIR).
305-
306-
**The TL;DR is that you might get weird behavior from a compile when using
307-
`--keep-stage 1`** -- for example, strange [ICEs](../appendix/glossary.html#ice)
308-
or other panics. In that case, you should simply remove the `--keep-stage 1`
309-
from the command and rebuild. That ought to fix the problem.
310-
311-
You can also use `--keep-stage 1` when running tests. Something like this:
312-
313-
- Initial test run: `./x test tests/ui`
314-
- Subsequent test run: `./x test tests/ui --keep-stage 1`
315-
316-
### Iterating the standard library with `--keep-stage`
317-
318-
If you are making changes to the standard library, you can use `./x build
319-
--keep-stage 0 library` to iteratively rebuild the standard library without
320-
rebuilding the compiler.
276+
## Faster Builds with CI-rustc
277+
278+
If you are not working on the compiler, you often don't need to build the compiler tree.
279+
For example, you can skip building the compiler and only build the `library` tree or the
280+
tools under `src/tools`. To achieve that, you have to enable this by setting the `download-rustc`
281+
option in your configuration. This tells bootstrap to use the latest nightly compiler for `stage > 0`
282+
steps, meaning it will have two precompiled compilers: stage0 compiler and `download-rustc` compiler
283+
for `stage > 0` steps. This way, it will never need to build the in-tree compiler. As a result, your
284+
build time will be significantly reduced by not building the in-tree compiler.
321285

322286
## Using incremental compilation
323287

0 commit comments

Comments
 (0)