|
| 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 |
0 commit comments