-
Notifications
You must be signed in to change notification settings - Fork 547
[WIP] Fix and clean up the terminology for stages #807
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,13 +57,13 @@ When you use the bootstrap system, you'll call it through `x.py`. | |
However, most of the code lives in `src/bootstrap`. | ||
`bootstrap` has a difficult problem: it is written in Rust, but yet it is run | ||
before the rust compiler is built! To work around this, there are two | ||
components of bootstrap: the main one written in rust, and `bootstrap.py`. | ||
components of bootstrap: the main one written in Rust, called `rustbuild`, | ||
and `bootstrap.py`. | ||
`bootstrap.py` is what gets run by x.py. It takes care of downloading the | ||
`stage0` compiler, which will then build the bootstrap binary written in | ||
Rust. | ||
bootstrap compiler, which will then compile `rustbuild`. | ||
|
||
Because there are two separate codebases behind `x.py`, they need to | ||
be kept in sync. In particular, both `bootstrap.py` and the bootstrap binary | ||
be kept in sync. In particular, both `bootstrap.py` and `rustbuild` | ||
parse `config.toml` and read the same command line arguments. `bootstrap.py` | ||
keeps these in sync by setting various environment variables, and the | ||
programs sometimes to have add arguments that are explicitly ignored, to be | ||
|
@@ -78,6 +78,47 @@ contribution [here][bootstrap-build]. | |
|
||
## Stages of bootstrap | ||
|
||
Like most other bootstrapping compilers, `rustc` is compiled in stages. | ||
_Unlike_ most other compilers, where `stage0` refers to the bootstrap compiler, | ||
`stage0` refers to the first compiler built by bootstrap. So the following command: | ||
|
||
```sh | ||
x.py build --stage 0 src/rustc | ||
``` | ||
Comment on lines
+82
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fwiw, I feel like this doesn't seem correct. I call the stage0 compiler the beta compiler which appears in the
It seems to me a lot of confusion stems from the |
||
|
||
will actually perform a full build of rustc. Confusingly, the `build/$target/stageN` directories are named after the compiler they are *used to build*, not the commands you need to build them. | ||
|
||
- **Stage 0:** The stage0 compiler is built by the bootstrap compiler. | ||
The bootstrap compiler is usually (you can configure `x.py` to use | ||
something else) the current beta `rustc` compiler and its associated dynamic | ||
libraries (which `x.py` will download for you). This bootstrap compiler is then | ||
used to compile `rustbuild`, `std`, and `rustc` (plus a few other tools, like `tidy`). When compiling | ||
`rustc`, this bootstrap compiler uses the freshly compiled `std`. | ||
There are two concepts at play here: a compiler (with its set of dependencies) | ||
and its 'target' or 'object' libraries (`std` and `rustc`). | ||
Both are staged, but in a staggered manner. | ||
The `stage0` standard library is the one _linked_ to `stage0` rustc | ||
(allowing you to `use std::vec::Vec` from within the compiler itself), | ||
while `stage1 libstd` is the library _built_ by stage1. `libstd` also include `libcore`, | ||
so without it there are very few programs that rustc can compile. | ||
|
||
- **Stage 1:** In theory, the stage0 compiler is functionally identical to the | ||
stage1 compiler, but in practice there are subtle differences. In | ||
particular, the stage0 compiler was built by bootstrap and | ||
hence not by the source in your working directory: this means that | ||
the symbol names used in the compiler source may not match the | ||
symbol names that would have been made by the stage1 compiler. This is | ||
important when using dynamic linking because Rust does not have ABI compatibility | ||
between versions. This primarily manifests when tests try to link with any | ||
of the `rustc_*` crates or use the (now deprecated) plugin infrastructure. | ||
These tests are marked with `ignore-stage1`. The `stage1` is because | ||
these plugins *link* to the stage1 compiler, even though they are being | ||
*built* by stage0. Rebuilding again also gives us the benefit of the latest optimizations (i.e. those added since the beta fork). | ||
|
||
- _(Optional)_ **Stage 2**: to sanity check our new compiler, we | ||
can build the libraries with the stage1 compiler. The result ought | ||
to be identical to before, unless something has broken. | ||
|
||
This is a detailed look into the separate bootstrap stages. When running | ||
`x.py` you will see output such as: | ||
|
||
|
@@ -163,11 +204,11 @@ The following tables indicate the outputs of various stage actions: | |
`--stage=2` stops here. | ||
|
||
Note that the convention `x.py` uses is that: | ||
- A "stage N artifact" is an artifact that is _produced_ by the stage N compiler. | ||
- The "stage (N+1) compiler" is assembled from "stage N artifacts". | ||
- A `--stage N` flag means build _with_ stage N. | ||
- A "stage N artifact" is an artifact that is part of stage N. | ||
- The compiler in `build/$target/stage(N+1)` is assembled from "stage N artifacts". | ||
- A `--stage N` flag means build a stage N artifact. | ||
|
||
In short, _stage 0 uses the stage0 compiler to create stage0 artifacts which | ||
In short, _stage 0 uses the bootstrap compiler to create stage0 artifacts which | ||
will later be uplifted to stage1_. | ||
|
||
Every time any of the main artifacts (`std` and `rustc`) are compiled, two | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is .. well, not quite true. stage0/bin/rustc is the bootstrap compiler. Really, we should rename it, but "to what?" then the question is.