Skip to content

Commit 6ee70a8

Browse files
authored
Streamline "Getting Started" (rust-lang#1279)
* Move `x.py` intro section before first use, and shorten it. * Improve `x.py setup` docs. In "Getting Started", strip it back to the bare minimum. Some of this is moved into the later section. In the later section, add notable details like config.toml.example how and `profile` works. Also make the config.toml example more concise. * Move details about the repository. Less detail in "Getting Started", more in the later sections. * Move details about the prereqs. Less detail in "Getting Started", more in the later sections.
1 parent c409629 commit 6ee70a8

File tree

3 files changed

+89
-138
lines changed

3 files changed

+89
-138
lines changed

src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md

+38-18
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,63 @@ see [the next page](./prerequisites.md).
1111

1212
## Get the source code
1313

14+
The main repository is [`rust-lang/rust`][repo]. This contains the compiler,
15+
the standard library (including `core`, `alloc`, `test`, `proc_macro`, etc),
16+
and a bunch of tools (e.g. `rustdoc`, the bootstrapping infrastructure, etc).
17+
18+
[repo]: https://github.com/rust-lang/rust
19+
1420
The very first step to work on `rustc` is to clone the repository:
1521

1622
```bash
1723
git clone https://github.com/rust-lang/rust.git
1824
cd rust
1925
```
2026

27+
There are also submodules for things like LLVM, `clippy`, `miri`, etc. The
28+
build tool will automatically clone and sync these for you. But if you want to,
29+
you can do the following:
30+
31+
```sh
32+
# first time
33+
git submodule update --init --recursive
34+
35+
# subsequent times (to pull new commits)
36+
git submodule update
37+
```
38+
2139
## Create a `config.toml`
2240

23-
To start, run `./x.py setup`. This will create a `config.toml` with reasonable defaults.
41+
To start, run `./x.py setup`. This will do some initialization and create a
42+
`config.toml` for you with reasonable defaults. These defaults are specified
43+
indirectly via the `profile` setting, which points to one of the TOML files in
44+
`src/bootstrap/defaults.`
45+
46+
Alternatively, you can write `config.toml` by hand. See `config.toml.example`
47+
for all the available settings and explanations of them. The following settings
48+
are of particular interest, and `config.toml.example` has full explanations.
2449

25-
You may also want to change some of the following settings (and possibly others, such as
50+
You may want to change some of the following settings (and possibly others, such as
2651
`llvm.ccache`):
2752

2853
```toml
2954
[llvm]
3055
# Whether to use Rust CI built LLVM instead of locally building it.
31-
download-ci-llvm = true
32-
33-
# Indicates whether the LLVM assertions are enabled or not
34-
assertions = true
56+
download-ci-llvm = true # Download a pre-built LLVM?
57+
assertions = true # LLVM assertions on?
58+
ccache = "/path/to/ccache" # Use ccache when building LLVM?
3559

3660
[rust]
37-
# Whether or not to leave debug! and trace! calls in the rust binary.
38-
# Overrides the `debug-assertions` option, if defined.
39-
#
40-
# Defaults to rust.debug-assertions value
41-
#
42-
# If you see a message from `tracing` saying
43-
# `max_level_info` is enabled and means logging won't be shown,
44-
# set this value to `true`.
45-
debug-logging = true
46-
47-
# Whether to always use incremental compilation when building rustc
48-
incremental = true
61+
debug-logging = true # Leave debug! and trace! calls in rustc?
62+
incremental = true # Build rustc with incremental compilation?
4963
```
5064

65+
If you set `download-ci-llvm = true`, in some circumstances, such as when
66+
updating the version of LLVM used by `rustc`, you may want to temporarily
67+
disable this feature. See the ["Updating LLVM" section] for more.
68+
69+
["Updating LLVM" section]: https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html?highlight=download-ci-llvm#feature-updates
70+
5171
If you have already built `rustc` and you change settings related to LLVM, then you may have to
5272
execute `rm -rf build` for subsequent configuration changes to take effect. Note that `./x.py
5373
clean` will not cause a rebuild of LLVM.

src/doc/rustc-dev-guide/src/building/prerequisites.md

+29-6
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,40 @@ see [the `rust-lang/rust` README](https://github.com/rust-lang/rust#building-on-
4343

4444
## Hardware
4545

46-
These are not so much requirements as _recommendations_:
47-
48-
* ~15GB of free disk space (~25GB or more if doing incremental builds).
49-
* \>= 8GB RAM
50-
* \>= 2 cores
51-
* Internet access
46+
You will need an internet connection to build. The bootstrapping process
47+
involves updating git submodules and downloading a beta compiler. It doesn't
48+
need to be super fast, but that can help.
49+
50+
There are no strict hardware requirements, but building the compiler is
51+
computationally expensive, so a beefier machine will help, and I wouldn't
52+
recommend trying to build on a Raspberry Pi! We recommend the following.
53+
* 30GB+ of free disk space. Otherwise, you will have to keep
54+
clearing incremental caches. More space is better, the compiler is a bit of a
55+
hog; it's a problem we are aware of.
56+
* 8GB+ RAM
57+
* 2+ cores. Having more cores really helps. 10 or 20 or more is not too many!
5258

5359
Beefier machines will lead to much faster builds. If your machine is not very
5460
powerful, a common strategy is to only use `./x.py check` on your local machine
5561
and let the CI build test your changes when you push to a PR branch.
5662

63+
Building the compiler takes more than half an hour on my moderately powerful
64+
laptop. The first time you build the compiler, LLVM will also be built unless
65+
you use CI-built LLVM ([see here][config]).
66+
67+
Like `cargo`, the build system will use as many cores as possible. Sometimes
68+
this can cause you to run low on memory. You can use `-j` to adjust the number
69+
concurrent jobs. If a full build takes more than ~45 minutes to an hour, you
70+
are probably spending most of the time swapping memory in and out; try using
71+
`-j1`.
72+
73+
If you don't have too much free disk space, you may want to turn off
74+
incremental compilation ([see here][config]). This will make compilation take
75+
longer (especially after a rebase), but will save a ton of space from the
76+
incremental caches.
77+
78+
[config]: ./how-to-build-and-run.md#create-a-configtoml
79+
5780
## `rustc` and toolchain installation
5881

5982
Follow the installation given in the [Rust book][install] to install a working

src/doc/rustc-dev-guide/src/getting-started.md

+22-114
Original file line numberDiff line numberDiff line change
@@ -44,149 +44,57 @@ just create noise, so we ask that you be mindful of the fact that the
4444

4545
## Cloning and Building
4646

47-
The main repository is [`rust-lang/rust`][repo]. This contains the compiler,
48-
the standard library (including `core`, `alloc`, `test`, `proc_macro`, etc),
49-
and a bunch of tools (e.g. `rustdoc`, the bootstrapping infrastructure, etc).
50-
51-
[repo]: https://github.com/rust-lang/rust
52-
53-
There are also a bunch of submodules for things like LLVM, `clippy`, `miri`,
54-
etc. You don't need to clone these immediately, but the build tool will
55-
automatically clone and sync them (more on this later).
56-
57-
[**Take a look at the "Suggested Workflows" chapter for some helpful
58-
advice.**][suggested]
59-
60-
[suggested]: ./building/suggested.md
61-
6247
### System Requirements
6348

64-
[**See this chapter for detailed software requirements.**](./building/prerequisites.md)
65-
Most notably, you will need Python 2 or 3 to run `x.py`.
66-
67-
There are no hard hardware requirements, but building the compiler is
68-
computationally expensive, so a beefier machine will help, and I wouldn't
69-
recommend trying to build on a Raspberry Pi :P
49+
Internet access is required.
7050

71-
- Recommended >=30GB of free disk space; otherwise, you will have to keep
72-
clearing incremental caches. More space is better, the compiler is a bit of a
73-
hog; it's a problem we are aware of.
74-
- Recommended >=8GB RAM.
75-
- Recommended >=2 cores; having more cores really helps.
76-
- You will need an internet connection to build; the bootstrapping process
77-
involves updating git submodules and downloading a beta compiler. It doesn't
78-
need to be super fast, but that can help.
51+
The most notable software requirement is that you will need Python 2 or 3, but
52+
there are various others.
7953

80-
Building the compiler takes more than half an hour on my moderately powerful
81-
laptop. The first time you build the compiler, LLVM will also be built unless
82-
you use CI-built LLVM ([see below][configsec]).
54+
The following hardware is recommended.
55+
* 30GB+ of free disk space.
56+
* 8GB+ RAM
57+
* 2+ cores
8358

84-
[configsec]: #configuring-the-compiler
59+
More powerful machines will lead to much faster builds. There are various
60+
strategies to work around lesser hardware in the following chapters.
8561

86-
Like `cargo`, the build system will use as many cores as possible. Sometimes
87-
this can cause you to run low on memory. You can use `-j` to adjust the number
88-
concurrent jobs. If a full build takes more than ~45 minutes to an hour,
89-
you are probably spending most of the time swapping memory in and out;
90-
try using `-j1`.
62+
See [this chapter][prereqs] for more details about software and hardware prerequisites.
9163

92-
On a slow machine, the build times for rustc are very painful. Consider using
93-
`./x.py check` instead of a full build and letting the automated tests run
94-
when you push to GitHub.
95-
96-
If you don't have too much free disk space, you may want to turn off
97-
incremental compilation ([see below][configsec]). This will make
98-
compilation take longer (especially after a rebase),
99-
but will save a ton of space from the incremental caches.
64+
[prereqs]: ./building/prerequisites.md
10065

10166
### Cloning
10267

10368
You can just do a normal git clone:
10469

10570
```sh
10671
git clone https://github.com/rust-lang/rust.git
72+
cd rust
10773
```
10874

109-
You don't need to clone the submodules at this time. But if you want to, you
110-
can do the following:
75+
### `x.py` Intro
11176

112-
```sh
113-
# first time
114-
git submodule update --init --recursive
77+
`rustc` is a [bootstrapping] compiler, which makes it more complex than a
78+
typical Rust program. As a result, you cannot use Cargo to build it. Instead
79+
you must use the special tool `x.py`. It is used for the things Cargo is
80+
normally used for: building, testing, creating releases, formatting, etc.
11581

116-
# subsequent times (to pull new commits)
117-
git submodule update
118-
```
82+
[bootstrapping]: ./building/bootstrapping.md
11983

12084
### Configuring the Compiler
12185

122-
The compiler has a configuration file which contains a ton of settings. We will
123-
provide some recommendations here that should work for most, but [check out
124-
this chapter for more info][config].
125-
126-
[config]: ./building/how-to-build-and-run.md#create-a-configtoml
127-
12886
In the top level of the repo:
12987

13088
```sh
13189
$ ./x.py setup
13290
```
13391

134-
This will walk you through an interactive setup for `x.py` that looks like this:
135-
136-
```
137-
$ ./x.py setup
138-
Welcome to the Rust project! What do you want to do with x.py?
139-
a) Contribute to the standard library
140-
b) Contribute to the compiler
141-
c) Contribute to the compiler, and also modify LLVM or codegen
142-
d) Install Rust from source
143-
Please choose one (a/b/c/d): a
144-
`x.py` will now use the configuration at /home/joshua/rustc2/src/bootstrap/defaults/config.toml.library
145-
To get started, try one of the following commands:
146-
- `x.py check`
147-
- `x.py build`
148-
- `x.py test library/std`
149-
- `x.py doc`
150-
For more suggestions, see https://rustc-dev-guide.rust-lang.org/building/suggested.html
151-
```
152-
153-
Note that by default, `./x.py setup` will use CI-built LLVM if available for your
154-
platform so that you don't need to build LLVM in addition to building the
155-
compiler. In some circumstances, such as when updating the version of LLVM used
156-
by `rustc`, you may want to temporarily disable this feature. See the ["Updating
157-
LLVM" section] for more.
92+
This will do some initialization and walk you through an interactive setup to
93+
create `config.toml`, the primary configuration file.
15894

159-
If you want to download LLVM from CI without running `./x.py setup`, you can set
160-
the `download-ci-llvm` option to `true` in your `config.toml`:
95+
See [this chapter][config] for more info about configuration.
16196

162-
```toml
163-
[llvm]
164-
download-ci-llvm = true
165-
```
166-
167-
["Updating LLVM" section]: https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html?highlight=download-ci-llvm#feature-updates
168-
169-
### `x.py` Intro
170-
171-
`rustc` is a _bootstrapping_ compiler, which means that it is written in Rust
172-
and thus needs to be compiled by itself. So where do you
173-
get the original compiler from? We use the current beta compiler
174-
to build a new compiler. Then, we use that compiler to build itself. Thus,
175-
`rustc` has a 2-stage build. You can read more about bootstrapping
176-
[here][boot], but you don't need to know much more to contribute.
177-
178-
[boot]: ./building/bootstrapping.md
179-
180-
We have a special tool `x.py` that drives this process. It is used for
181-
building the compiler, the standard libraries, and `rustdoc`. It is also used
182-
for driving CI and building the final release artifacts.
183-
184-
Unfortunately, a proper 2-stage build takes a long time depending on your
185-
hardware, but it is the only correct way to build everything (e.g. it's what
186-
the CI and release processes use). **However, in most cases, you can get by
187-
without a full 2-stage build**. In the following section, we give instructions
188-
for how to do "the correct thing", but then we also give various tips to speed
189-
things up.
97+
[config]: ./building/how-to-build-and-run.md#create-a-configtoml
19098

19199
### Building and Testing `rustc`
192100

0 commit comments

Comments
 (0)