Files
rust/src/bootstrap
Matthias Krüger 53e4e6f0cc Rollup merge of #138313 - rustbot:docs-update, r=jieyouxu
Update books

## rust-lang/book

11 commits in 4a01a9182496f807aaa5f72d93a25ce18bcbe105..81a976a237f84b8392c4ce1bd5fd076eb757a2eb
2025-02-27 22:10:41 UTC to 2025-02-24 18:36:27 UTC

- Ch. 10: Make social media discussion generic. (rust-lang/book#4249)
- Another Ch. 17 -> 18 fix (rust-lang/book#4247)
- Ch. 05: further tweak to wording about `user1` availability (rust-lang/book#4246)
- Ch. 02: Fix rand version mistake (from testing) (rust-lang/book#4245)
- Ch. 19: Correct the discussion of `fn` type and closures (rust-lang/book#4244)
- Edition maintenance: scripting the updates for future work (rust-lang/book#4243)
- Ch. 17: fresh-eyes edits (rust-lang/book#4242)
- Ch. 17: drop lifetime not required in 2024 Edition (rust-lang/book#4212)
- Appendix B, Operators: Replace “member access” with “field access” and “method call”. (rust-lang/book#4240)
- Update to Rust 1.85 and 2024 Edition! (rust-lang/book#4241)
- Chapter 1: fix 'four things' now that spacing is not emphasized (rust-lang/book#4239)

## rust-lang/edition-guide

2 commits in daa4b763cd848f986813b5cf8069e1649f7147af..1e27e5e6d5133ae4612f5cc195c15fc8d51b1c9c
2025-03-04 22:02:00 UTC to 2025-02-26 12:47:41 UTC

- Mention both `rustfmt.toml` and `.rustfmt.toml` (rust-lang/edition-guide#372)
- Fix a typo (rust-lang/edition-guide#370)

## rust-lang/nomicon

1 commits in 8f5c7322b65d079aa5b242eb10d89a98e12471e1..b4448fa406a6dccde62d1e2f34f70fc51814cdcc
2025-03-01 04:48:05 UTC to 2025-03-01 04:48:05 UTC

- Update to 2024 edition (rust-lang/nomicon#481)

## rust-lang/reference

8 commits in 615b4cec60c269cfc105d511c93287620032d5b0..dda31c85f2ef2e5d2f0f2f643c9231690a30a626
2025-03-09 14:25:25 UTC to 2025-02-25 16:07:17 UTC

- Rework note blocks and change admonition rendering (rust-lang/reference#1754)
- Add more information on rules and tests (rust-lang/reference#1753)
- Mention `explicit_builtin_cfgs_in_flags` lint cfg chapter (rust-lang/reference#1747)
- fixup test links (rust-lang/reference#1741)
- Fix diagnostics typo: `do_no_recommend` -> `do_not_recommend` (rust-lang/reference#1749)
- panic runtime and C-unwind documentation (rust-lang/reference#1226)
- Closures: fix example of desugaring (rust-lang/reference#1743)
- Update boolean.md, Comment breaks paragraph format (rust-lang/reference#1744)

## rust-lang/rust-by-example

1 commits in 66543bbc5b7dbd4e679092c07ae06ba6c73fd912..6f69823c28ae8d929d6c815181c73d3e99ef16d3
2025-03-09 13:12:24 UTC to 2025-03-09 13:12:24 UTC

- Update mdbook to 0.4.46 (rust-lang/rust-by-example#1914)

try-job: x86_64-gnu-distcheck
2025-03-12 08:06:48 +01:00
..
2023-07-30 11:46:14 +02:00
2025-02-23 08:24:56 +03:00
2025-02-23 08:24:56 +03:00
2025-01-31 09:59:41 +01:00

Bootstrapping Rust

This README is aimed at helping to explain how Rust is bootstrapped, and some of the technical details of the bootstrap build system.

Note that this README only covers internal information, not how to use the tool. Please check bootstrapping dev guide for further information.

Introduction

The build system defers most of the complicated logic of managing invocations of rustc and rustdoc to Cargo itself. However, moving through various stages and copying artifacts is still necessary for it to do. Each time bootstrap is invoked, it will iterate through the list of predefined steps and execute each serially in turn if it matches the paths passed or is a default rule. For each step, bootstrap relies on the step internally being incremental and parallel. Note, though, that the -j parameter to bootstrap gets forwarded to appropriate test harnesses and such.

Build phases

Bootstrap build system goes through a few phases to actually build the compiler. What actually happens when you invoke bootstrap is:

  1. The entry point script (x for unix like systems, x.ps1 for windows systems, x.py cross-platform) is run. This script is responsible for downloading the stage0 compiler/Cargo binaries, and it then compiles the build system itself (this folder). Finally, it then invokes the actual bootstrap binary build system.
  2. In Rust, bootstrap will slurp up all configuration, perform a number of sanity checks (whether compilers exist, for example), and then start building the stage0 artifacts.
  3. The stage0 cargo, downloaded earlier, is used to build the standard library and the compiler, and then these binaries are then copied to the stage1 directory. That compiler is then used to generate the stage1 artifacts which are then copied to the stage2 directory, and then finally, the stage2 artifacts are generated using that compiler.

The goal of each stage is to (a) leverage Cargo as much as possible and failing that (b) leverage Rust as much as possible!

Directory Layout

This build system houses all output under the build directory, which looks like this:

# Root folder of all output. Everything is scoped underneath here
build/

  # Location where the stage0 compiler downloads are all cached. This directory
  # only contains the tarballs themselves, as they're extracted elsewhere.
  cache/
    2015-12-19/
    2016-01-15/
    2016-01-21/
    ...

  # Output directory for building this build system itself. The stage0
  # cargo/rustc are used to build the build system into this location.
  bootstrap/
    debug/
    release/

  # Output of the dist-related steps like dist-std, dist-rustc, and dist-docs
  dist/

  # Temporary directory used for various input/output as part of various stages
  tmp/

  # Each remaining directory is scoped by the "host" triple of compilation at
  # hand.
  x86_64-unknown-linux-gnu/

    # The build artifacts for the `compiler-rt` library for the target that
    # this folder is under. The exact layout here will likely depend on the
    # platform, and this is also built with CMake, so the build system is
    # also likely different.
    compiler-rt/
      build/

    # Output folder for LLVM if it is compiled for this target
    llvm/

      # build folder (e.g. the platform-specific build system). Like with
      # compiler-rt, this is compiled with CMake
      build/

      # Installation of LLVM. Note that we run the equivalent of 'make install'
      # for LLVM, to setup these folders.
      bin/
      lib/
      include/
      share/
      ...

    # Output folder for all documentation of this target. This is what's filled
    # in whenever the `doc` step is run.
    doc/

    # Output for all compiletest-based test suites
    test/
      ui/
      debuginfo/
      ...

    # Location where the stage0 Cargo and Rust compiler are unpacked. This
    # directory is purely an extracted and overlaid tarball of these two (done
    # by the bootstrap Python script). In theory, the build system does not
    # modify anything under this directory afterwards.
    stage0/

    # These to-build directories are the cargo output directories for builds of
    # the standard library, the test system, the compiler, and various tools,
    # respectively. Internally, these may also
    # have other target directories, which represent artifacts being compiled
    # from the host to the specified target.
    #
    # Essentially, each of these directories is filled in by one `cargo`
    # invocation. The build system instruments calling Cargo in the right order
    # with the right variables to ensure that these are filled in correctly.
    stageN-std/
    stageN-test/
    stageN-rustc/
    stageN-tools/

    # This is a special case of the above directories, **not** filled in via
    # Cargo but rather the build system itself. The stage0 compiler already has
    # a set of target libraries for its own host triple (in its own sysroot)
    # inside of stage0/. When we run the stage0 compiler to bootstrap more
    # things, however, we don't want to use any of these libraries (as those are
    # the ones that we're building). So essentially, when the stage1 compiler is
    # being compiled (e.g. after libstd has been built), *this* is used as the
    # sysroot for the stage0 compiler being run.
    #
    # Basically, this directory is just a temporary artifact used to configure the
    # stage0 compiler to ensure that the libstd that we just built is used to
    # compile the stage1 compiler.
    stage0-sysroot/lib/

    # These output directories are intended to be standalone working
    # implementations of the compiler (corresponding to each stage). The build
    # system will link (using hard links) output from stageN-{std,rustc} into
    # each of these directories.
    #
    # In theory these are working rustc sysroot directories, meaning there is
    # no extra build output in these directories.
    stage1/
    stage2/
    stage3/

Extending bootstrap

When you use bootstrap, you'll call it through the entry point script (x, x.ps1, or 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. bootstrap.py is what gets run by entry point script. It takes care of downloading the stage0 compiler, which will then build the bootstrap binary written in Rust.

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 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 have to add arguments that are explicitly ignored, to be read by the other.

Some general areas that you may be interested in modifying are:

  • Adding a new build tool? Take a look at bootstrap/src/core/build_steps/tool.rs for examples of other tools.
  • Adding a new compiler crate? Look no further! Adding crates can be done by adding a new directory with Cargo.toml, followed by configuring all Cargo.toml files accordingly.
  • Adding a new dependency from crates.io? This should just work inside the compiler artifacts stage (everything other than libtest and libstd).
  • Adding a new configuration option? You'll want to modify bootstrap/src/core/config/flags.rs for command line flags and then bootstrap/src/core/config/config.rs to copy the flags to the Config struct.
  • Adding a sanity check? Take a look at bootstrap/src/core/sanity.rs.

If you make a major change on bootstrap configuration, please add a new entry to CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

A 'major change' includes

  • A new option or
  • A change in the default options.

Changes that do not affect contributors to the compiler or users building rustc from source don't need an update to CONFIG_CHANGE_HISTORY.

If you have any questions, feel free to reach out on the #t-infra/bootstrap channel at Rust Bootstrap Zulip server. When you encounter bugs, please file issues on the Rust issue tracker.

Changelog

Because we do not release bootstrap with versions, we also do not maintain CHANGELOG files. To review the changes made to bootstrap, simply run git log --no-merges --oneline -- src/bootstrap.