@@ -54,12 +54,43 @@ clean` will not cause a rebuild of LLVM.
5454
5555## Building the Compiler
5656
57+ Building compiler is unfortunately not quite as simple as building other
58+ rust projects using` cargo build ` . Instead, we use ` x.py ` script for building
59+ the compiler. The main reason behind it is the bootstrap stages where you use
60+ the output of one cargo invocation as the input compiler for another. Which
61+ is not possible with ` cargo ` itself.
62+
5763Note that building will require a relatively large amount of storage space.
5864You may want to have upwards of 10 or 15 gigabytes available to build the compiler.
5965
60- Once you've created a ` config.toml ` , you are now ready to run
61- ` x.py ` . There are a lot of options here, but let's start with what is
62- probably the best "go to" command for building a local compiler:
66+ The script accepts commands, flags, and arguments to determine what to do.
67+ To see capabilities of x in an action, check the following examples:
68+
69+ ``` bash
70+ # build the whole compiler
71+ ./x.py build --stage 2
72+
73+ # build the stage1 compiler
74+ ./x.py build
75+
76+ # build stage0 libstd
77+ ./x.py build --stage 0 library/std
78+
79+ # build a particular crate in stage0
80+ ./x.py build --stage 0 library/test
81+ ```
82+
83+ If files that would normally be rebuilt from stage 0 are dirty, the rebuild can be
84+ overridden using ` --keep-stage 0 ` . Using ` --keep-stage n ` will skip all steps
85+ that belong to stage n or earlier:
86+
87+ ``` bash
88+ # build stage 1, keeping old build products for stage 0
89+ ./x.py build --keep-stage 0
90+ ```
91+
92+ Let's dive into details with probably the best "go to"
93+ command for building a local compiler:
6394
6495``` bash
6596./x.py build library
@@ -98,6 +129,24 @@ build. The **full** `rustc` build (what you get with `./x.py build
98129
99130You almost never need to do this.
100131
132+ ## Incremental builds
133+
134+ You can configure rustbuild to use incremental compilation with the
135+ ` --incremental ` flag:
136+
137+ ``` sh
138+ $ ./x.py build --incremental
139+ ```
140+
141+ The ` --incremental ` flag will store incremental compilation artifacts
142+ in ` build/<host>/stage0-incremental ` . Note that we only use incremental
143+ compilation for the stage0 -> stage1 compilation -- this is because
144+ the stage1 compiler is changing, and we don't try to cache and reuse
145+ incremental artifacts across different versions of the compiler.
146+
147+ You can always drop the ` --incremental ` to build as normal (note that
148+ you will still be using the downloaded beta as your bootstrap).
149+
101150## Build specific components
102151
103152If you are working on the standard library, you probably don't need to build
@@ -242,3 +291,53 @@ everything up then you only need to run one command!
242291
243292` rm -rf build ` works too, but then you have to rebuild LLVM, which can take
244293a long time even on fast computers.
294+
295+ ## Extending rustbuild
296+
297+ So, you'd like to add a feature to the rustbuild build system or just fix a bug.
298+ Great! One of the major motivational factors for moving away from ` make ` is that
299+ Rust is in theory much easier to read, modify, and write. If you find anything
300+ excessively confusing, please open an issue on this, and we'll try to get it
301+ documented or simplified, pronto.
302+
303+ First up, you'll probably want to read over the documentation above, as that'll
304+ give you a high level overview of what rustbuild is doing. You also probably
305+ want to play around a bit yourself by just getting it up and running before you
306+ dive too much into the actual build system itself.
307+
308+ After that, each module in rustbuild should have enough documentation to keep
309+ you up and running. Some general areas that you may be interested in modifying
310+ are:
311+
312+ * Adding a new build tool? Take a look at ` bootstrap/tool.rs ` for examples of
313+ other tools.
314+ * Adding a new compiler crate? Look no further! Adding crates can be done by
315+ adding a new directory with ` Cargo.toml ` followed by configuring all
316+ ` Cargo.toml ` files accordingly.
317+ * Adding a new dependency from crates.io? This should just work inside the
318+ compiler artifacts stage (everything other than libtest and libstd).
319+ * Adding a new configuration option? You'll want to modify ` bootstrap/flags.rs `
320+ for command line flags and then ` bootstrap/config.rs ` to copy the flags to the
321+ ` Config ` struct.
322+ * Adding a sanity check? Take a look at ` bootstrap/sanity.rs ` .
323+
324+ If you make a major change, please remember to:
325+
326+ + Update ` VERSION ` in ` src/bootstrap/main.rs ` .
327+ * Update ` changelog-seen = N ` in ` config.toml.example ` .
328+ * Add an entry in ` src/bootstrap/CHANGELOG.md ` .
329+
330+ A 'major change' includes
331+
332+ * A new option or
333+ * A change in the default options.
334+
335+ Changes that do not affect contributors to the compiler or users
336+ building rustc from source don't need an update to ` VERSION ` .
337+
338+ If you have any questions, feel free to reach out on the ` #t-infra ` channel in
339+ the [ Rust Zulip server] [ rust-zulip ] or ask on internals.rust-lang.org. When
340+ you encounter bugs, please file issues on [ Rust issue tracker] [ rust-issue-tracker ] .
341+
342+ [ rust-zulip ] : https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra
343+ [ rust-issue-tracker ] : https://github.com/rust-lang/rust/issues
0 commit comments