Skip to content

Commit e1c7b6c

Browse files
committed
Slightly reorganize to first present the slow command then the fast commands
1 parent db004ad commit e1c7b6c

File tree

1 file changed

+74
-29
lines changed

1 file changed

+74
-29
lines changed

src/getting-started.md

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ There are no hard hardware requirements, but building the compiler is
6666
computationally expensive, so a beefier machine will help, and I wouldn't
6767
recommend trying to build on a Raspberry Pi :P
6868

69-
- x86 and ARM are both supported (TODO: confirm)
7069
- Recommended >=30GB of free disk space; otherwise, you will have to keep
7170
clearing incremental caches. More space is better, the compiler is a bit of a
7271
hog; it's a problem we are aware of.
@@ -125,34 +124,60 @@ In the top level of the repo:
125124
cp config.toml.example config.toml
126125
```
127126

128-
Then, edit `config.toml`. You will need to search for, uncomment, and update
127+
Then, edit `config.toml`. You may want to search for, uncomment, and update
129128
the following settings:
130129

131130
- `debug = true`: enables debug symbols and `debug!` logging, takes a bit longer to compile.
132131
- `incremental = true`: enables incremental compilation of the compiler itself,
133132
which can significantly speed things up. This is turned off by default
134-
because it's technically unsound; sometimes this will cause weird crashes.
135-
Also, it can consume a lot of disk space.
133+
because it's technically unsound; sometimes it will cause weird crashes.
134+
Also, it can consume a lot of disk space. This has the same effect as the
135+
`-i` or `--incremental` flags.
136136
- `llvm-config`: enables building with system LLVM. [See this chapter][sysllvm]
137137
for more info. This avoids building LLVM, which can take a while.
138138

139139
[sysllvm]: ./building/suggested.html#building-with-system-llvm
140140

141141
### `./x.py` Intro
142142

143-
`rustc` is a bootstrapping compiler because it is written in Rust. Where do you
143+
`rustc` is a _bootstrapping_ compiler because it is written in Rust. Where do you
144144
get the original compiler from? We use the current beta compiler
145145
to build the compiler. Then, we use that compiler to build itself. Thus,
146-
`rustc` has a 2-stage build.
146+
`rustc` has a 2-stage build. You can read more about bootstrapping
147+
[here][boot], but you don't need more to contribute.
148+
149+
[boot]: ./building/bootstrapping.md
147150

148151
We have a special tool `./x.py` that drives this process. It is used for
149152
compiling the compiler, the standard libraries, and `rustdoc`. It is also used
150153
for driving CI and building the final release artifacts.
151154

155+
Unfortunately, a proper 2-stage build takes a long time depending on your
156+
hardware, but it is the only correct way to build everything (e.g. it's what
157+
the CI and release processes use). **However, in most cases, you can get by
158+
without a full 2-stage build**. In the following section, we give instructions
159+
for how to do "the correct thing", but then we also give various tips to speed
160+
things up.
161+
152162
### Building and Testing `rustc`
153163

154-
For most contributions, you only need to build stage 1, which saves a lot of time.
155-
After updating `config.toml`, as mentioned above, you can use `./x.py`:
164+
To do a full 2-stage build of the whole compiler, you should run this (after
165+
updating `config.toml` as mentioned above):
166+
167+
```sh
168+
./x.py build
169+
```
170+
171+
In the process, this will also necessarily build the standard libraries, and it
172+
will build `rustdoc` (which doesn't take too long).
173+
174+
To build and test everything:
175+
176+
```sh
177+
./x.py test
178+
```
179+
180+
For most contributions, you only need to build stage 1, which saves a lot of time:
156181

157182
```shell
158183
# Build the compiler (stage 1)
@@ -170,33 +195,36 @@ does not need to be rebuilt, which is usually true, which will save some time.
170195
However, if you are changing certain parts of the compiler, this may lead to
171196
weird errors. Feel free to ask on [zulip][z] if you are running into issues.
172197

173-
To run the compiler's UI test suite (the bulk of the test suite):
198+
This runs a ton of tests and takes a long time to complete. If you are
199+
working on `rustc`, you can usually get by with only the [UI tests][uitests]. These
200+
test are mostly for the frontend of the compiler, so if you are working on LLVM
201+
or codegen, this shortcut will _not_ test your changes. You can read more about the
202+
different test suites [in this chapter][testing].
203+
204+
[uitests]: ./tests/adding.html#ui
205+
[testing]: https://rustc-dev-guide.rust-lang.org/tests/intro.html
174206

175207
```
176-
# UI tests
177208
# First build
178209
./x.py test --stage 1 src/test/ui
179210
180211
# Subsequent builds
181212
./x.py test --stage 1 src/test/ui --keep-stage 1
182213
```
183214

184-
This will build the compiler first, if needed.
185-
186-
This will be enough for most people. Notably, though, it mostly tests the
187-
compiler frontend, not codegen or debug info. You can read more about the
188-
different test suites [in this chapter][testing].
189-
190-
[testing]: https://rustc-dev-guide.rust-lang.org/tests/intro.html
191-
192-
If you only want to check that the compiler builds (without actually building
193-
it) you can run the following:
215+
While working on the compiler, it can be helpful to see if the code just
216+
compiles (similar to `cargo check`) without actually building it. You can do
217+
this with:
194218

195219
```shell
196220
./x.py check
197221
```
198222

199-
To format the code:
223+
This command is really fast (relative to the other commands). It usually
224+
completes in a couple of minutes on my laptop.
225+
226+
Finally, the CI ensures that the codebase is using consistent style. To format
227+
the code:
200228

201229
```shell
202230
# Actually format
@@ -206,15 +234,27 @@ To format the code:
206234
./x.py fmt --check
207235
```
208236

209-
You can use `RUSTC_LOG=XXX` to get debug logging. [Read more here][logging].
237+
*Note*: we don't use stable `rustfmt`; we use a pinned version with a special
238+
config, so this may result in different style from normal `rustfmt` if you have
239+
format-on-save turned on. It's a good habit to run `./x.py fmt` before every
240+
commit, as this reduces conflicts later.
241+
242+
On last thing: you can use `RUSTC_LOG=XXX` to get debug logging. [Read more
243+
here][logging]. Notice the `C` in `RUSTC_LOG`. Other than that, it uses normal
244+
[`env_logger`][envlog] syntax.
210245

246+
[envlog]: https://crates.io/crates/env_logger
211247
[logging]: ./compiler-debugging.html#getting-logging-output
212248

213249
### Building and Testing `std`/`core`/`alloc`/`test`/`proc_macro`/etc.
214250

215-
To contribute to `libstd`, you don't need to build the compiler unless you are
251+
As before, technically the proper way to build one of these libraries is to use
252+
the stage-2 compiler, which of course requires a 2-stage build, described above
253+
(`./x.py build`).
254+
255+
In practice, though, you don't need to build the compiler unless you are
216256
planning to use a recently added nightly feature. Instead, you can just build
217-
stage 0.
257+
stage 0 (i.e. which basically just uses the current beta compiler).
218258

219259
```sh
220260
./x.py build --stage 0 src/libstd
@@ -224,13 +264,16 @@ stage 0.
224264
./x.py test --stage 0 src/libstd
225265
```
226266

267+
(The same works for `src/liballoc`, `src/libcore`, etc.)
268+
227269
### Building and Testing `rustdoc`
228270

229271
`rustdoc` uses `rustc` internals (and, of course, the standard library), so you
230272
will have to build the compiler and `std` once before you can build `rustdoc`.
273+
As before, you can use `./x.py build` to do this.
231274

232-
The following command will build all of them. Stage 1 should be sufficient,
233-
even though the release version will use the full 2-stage build.
275+
However, in practice, stage 1 should be sufficient. The first time you build,
276+
the stage-1 compiler will also be built.
234277

235278
```sh
236279
# First build
@@ -240,7 +283,11 @@ even though the release version will use the full 2-stage build.
240283
./x.py build --stage 1 --keep-stage 1 src/tools/rustdoc
241284
```
242285

243-
You can also use `./x.py check` here to do a fast check build.
286+
As with the compiler, you can do a fast check build:
287+
288+
```sh
289+
./x.py check
290+
```
244291

245292
Rustdoc has two types of tests: content tests and UI tests.
246293

@@ -421,5 +468,3 @@ master.
421468
- [The compiler's documentation (rustdocs)](https://doc.rust-lang.org/nightly/nightly-rustc/)
422469
- [The Forge](https://forge.rust-lang.org/) has more documentation about various procedures.
423470
- `#contribute`, `#compiler`, and `#rustdoc` on [Discord](https://discord.gg/rust-lang).
424-
425-
TODO: am I missing any?

0 commit comments

Comments
 (0)