Skip to content

Commit 5887658

Browse files
authored
Merge pull request #2610 from Zalathar/build-library
Fix and improve guidance for building/rebuilding the compiler
2 parents 5c5c774 + c7f1fe6 commit 5887658

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,18 @@ Once you've created a `bootstrap.toml`, you are now ready to run
227227
probably the best "go to" command for building a local compiler:
228228

229229
```console
230-
./x build rustc
230+
./x build library
231231
```
232232

233-
What this command does is build `rustc` using the stage0 compiler and stage0 `std`.
233+
What this command does is:
234+
- Build `rustc` using the stage0 compiler and stage0 `std`.
235+
- Build `library` (the standard libraries) with the stage1 compiler that was just built.
236+
- Assemble a working stage1 sysroot, containing the stage1 compiler and stage1 standard libraries.
234237

235238
To build `rustc` with the in-tree `std`, use this command instead:
236239

237240
```console
238-
./x build rustc --stage 2
241+
./x build library --stage 2
239242
```
240243

241244
This final product (stage1 compiler + libs built using that compiler)
@@ -246,7 +249,7 @@ You will probably find that building the stage1 `std` is a bottleneck for you,
246249
but fear not, there is a (hacky) workaround...
247250
see [the section on avoiding rebuilds for std][keep-stage].
248251

249-
[keep-stage]: ./suggested.md#faster-builds-with---keep-stage
252+
[keep-stage]: ./suggested.md#faster-rebuilds-with---keep-stage-std
250253

251254
Sometimes you don't need a full build. When doing some kind of
252255
"type-based refactoring", like renaming a method, or changing the

src/building/suggested.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,40 @@ steps, meaning it will have two precompiled compilers: stage0 compiler and `down
306306
for `stage > 0` steps. This way, it will never need to build the in-tree compiler. As a result, your
307307
build time will be significantly reduced by not building the in-tree compiler.
308308

309+
## Faster rebuilds with `--keep-stage-std`
310+
311+
Sometimes just checking whether the compiler builds is not enough. A common
312+
example is that you need to add a `debug!` statement to inspect the value of
313+
some state or better understand the problem. In that case, you don't really need
314+
a full build. By bypassing bootstrap's cache invalidation, you can often get
315+
these builds to complete very fast (e.g., around 30 seconds). The only catch is
316+
this requires a bit of fudging and may produce compilers that don't work (but
317+
that is easily detected and fixed).
318+
319+
The sequence of commands you want is as follows:
320+
321+
- Initial build: `./x build library`
322+
- Subsequent builds: `./x build library --keep-stage-std=1`
323+
- Note that we added the `--keep-stage-std=1` flag here
324+
325+
As mentioned, the effect of `--keep-stage-std=1` is that we just _assume_ that the
326+
old standard library can be re-used. If you are editing the compiler, this is
327+
often true: you haven't changed the standard library, after all. But
328+
sometimes, it's not true: for example, if you are editing the "metadata" part of
329+
the compiler, which controls how the compiler encodes types and other states
330+
into the `rlib` files, or if you are editing things that wind up in the metadata
331+
(such as the definition of the MIR).
332+
333+
**The TL;DR is that you might get weird behavior from a compile when using
334+
`--keep-stage-std=1`** -- for example, strange [ICEs](../appendix/glossary.html#ice)
335+
or other panics. In that case, you should simply remove the `--keep-stage-std=1`
336+
from the command and rebuild. That ought to fix the problem.
337+
338+
You can also use `--keep-stage-std=1` when running tests. Something like this:
339+
340+
- Initial test run: `./x test tests/ui`
341+
- Subsequent test run: `./x test tests/ui --keep-stage-std=1`
342+
309343
## Using incremental compilation
310344

311345
You can further enable the `--incremental` flag to save additional time in

0 commit comments

Comments
 (0)