Skip to content

Commit dbee504

Browse files
authored
Extract Bootstrap into its own section (#1939)
* Extract Bootstrap into its own section Add brief explanation for `Step` and `Builder::ensure` as core Bootstrap internal concepts. * Drop common commands page (use `x --help` instead) * Add `make` as an alternative entry point * Add src/bootstrap/README.md link
1 parent 144e535 commit dbee504

File tree

4 files changed

+79
-16
lines changed

4 files changed

+79
-16
lines changed

Diff for: src/SUMMARY.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
- [with Windows Performance Analyzer](./profiling/wpa_profiling.md)
3434
- [crates.io Dependencies](./crates-io.md)
3535

36-
3736
# Contributing to Rust
3837

3938
- [Contribution Procedures](./contributing.md)
@@ -58,12 +57,17 @@
5857
- [Licenses](./licenses.md)
5958
- [Editions](guides/editions.md)
6059

60+
# Bootstrapping
61+
62+
- [Prologue](./building/bootstrapping/intro.md)
63+
- [What Bootstrapping does](./building/bootstrapping/what-bootstrapping-does.md)
64+
- [How Bootstrap does it](./building/bootstrapping/how-bootstrap-does-it.md)
65+
6166
# High-level Compiler Architecture
6267

6368
- [Prologue](./part-2-intro.md)
6469
- [Overview of the compiler](./overview.md)
6570
- [The compiler source code](./compiler-src.md)
66-
- [Bootstrapping](./building/bootstrapping.md)
6771
- [Queries: demand-driven compilation](./query.md)
6872
- [The Query Evaluation Model in Detail](./queries/query-evaluation-model-in-detail.md)
6973
- [Incremental compilation](./queries/incremental-compilation.md)

Diff for: src/building/bootstrapping/how-bootstrap-does-it.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# How Bootstrap does it
2+
3+
The core concept in Bootstrap is a build [`Step`], which are chained together
4+
by [`Builder::ensure`]. [`Builder::ensure`] takes a [`Step`] as input, and runs
5+
the [`Step`] if and only if it has not already been run. Let's take a closer
6+
look at [`Step`].
7+
8+
## Synopsis of [`Step`]
9+
10+
A [`Step`] represents a granular collection of actions involved in the process
11+
of producing some artifact. It can be thought of like a rule in Makefiles.
12+
The [`Step`] trait is defined as:
13+
14+
```rs,no_run
15+
pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
16+
type Output: Clone;
17+
18+
const DEFAULT: bool = false;
19+
const ONLY_HOSTS: bool = false;
20+
21+
// Required methods
22+
fn run(self, builder: &Builder<'_>) -> Self::Output;
23+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_>;
24+
25+
// Provided method
26+
fn make_run(_run: RunConfig<'_>) { ... }
27+
}
28+
```
29+
30+
- `run` is the function that is responsible for doing the work.
31+
[`Builder::ensure`] invokes `run`.
32+
- `should_run` is the command-line interface, which determines if an invocation
33+
such as `x build foo` should run a given [`Step`]. In a "default" context
34+
where no paths are provided, then `make_run` is called directly.
35+
- `make_run` is invoked only for things directly asked via the CLI and not
36+
for steps which are dependencies of other steps.
37+
38+
## The entry points
39+
40+
There's a couple of preliminary steps before core Bootstrap code is reached:
41+
42+
1. Shell script or `make`: [`./x`](https://github.com/rust-lang/rust/blob/master/x) or [`./x.ps1`](https://github.com/rust-lang/rust/blob/master/x.ps1) or `make`
43+
2. Convenience wrapper script: [`x.py`](https://github.com/rust-lang/rust/blob/master/x.py)
44+
3. [`src/bootstrap/bootstrap.py`](https://github.com/rust-lang/rust/blob/master/src/bootstrap/bootstrap.py)
45+
4. [`src/bootstrap/src/bin/main.rs`](https://github.com/rust-lang/rust/blob/master/src/bootstrap/src/bin/main.rs)
46+
47+
See [src/bootstrap/README.md](https://github.com/rust-lang/rust/blob/master/src/bootstrap/README.md)
48+
for a more specific description of the implementation details.
49+
50+
[`Step`]: https://doc.rust-lang.org/nightly/nightly-rustc/bootstrap/core/builder/trait.Step.html
51+
[`Builder::ensure`]: https://doc.rust-lang.org/nightly/nightly-rustc/bootstrap/core/builder/struct.Builder.html#method.ensure

Diff for: src/building/bootstrapping/intro.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Bootstrapping the compiler
2+
3+
[*Bootstrapping*][boot] is the process of using a compiler to compile itself.
4+
More accurately, it means using an older compiler to compile a newer version
5+
of the same compiler.
6+
7+
This raises a chicken-and-egg paradox: where did the first compiler come from?
8+
It must have been written in a different language. In Rust's case it was
9+
[written in OCaml][ocaml-compiler]. However it was abandoned long ago and the
10+
only way to build a modern version of rustc is a slightly less modern
11+
version.
12+
13+
This is exactly how `x.py` works: it downloads the current beta release of
14+
rustc, then uses it to compile the new compiler.
15+
16+
In this section, we give a high-level overview of
17+
[what Bootstrap does](./what-bootstrapping-does.md), followed by a high-level
18+
introduction to [how Bootstrap does it](./how-bootstrap-does-it.md).
19+
20+
[boot]: https://en.wikipedia.org/wiki/Bootstrapping_(compilers)
21+
[ocaml-compiler]: https://github.com/rust-lang/rust/tree/ef75860a0a72f79f97216f8aaa5b388d98da6480/src/boot

Diff for: src/building/bootstrapping.md renamed to src/building/bootstrapping/what-bootstrapping-does.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
# Bootstrapping the compiler
1+
# What Bootstrapping does
22

33
<!-- toc -->
44

5-
[*Bootstrapping*][boot] is the process of using a compiler to compile itself.
6-
More accurately, it means using an older compiler to compile a newer version
7-
of the same compiler.
8-
9-
This raises a chicken-and-egg paradox: where did the first compiler come from?
10-
It must have been written in a different language. In Rust's case it was
11-
[written in OCaml][ocaml-compiler]. However it was abandoned long ago and the
12-
only way to build a modern version of rustc is a slightly less modern
13-
version.
14-
15-
This is exactly how `x.py` works: it downloads the current beta release of
16-
rustc, then uses it to compile the new compiler.
17-
185
Note that this documentation mostly covers user-facing information. See
196
[bootstrap/README.md][bootstrap-internals] to read about bootstrap internals.
207

0 commit comments

Comments
 (0)