Skip to content

Commit 1801a03

Browse files
nnethercotejyn514
authored andcommitted
Streamline "Getting Started" some more.
This is a follow-up to rust-lang#1279. The "Getting Started" chapter is, TBH, pretty bad when it comes to the stuff about building and testing. It has far too much detail and lots of repetition, which would be overwhelming to a newcomer. This commit removes most of it, leaving behind just quick mentions of the most common `x.py` commands: `check`, `build`, `test`, `fmt`, with links to the appropriate chapters for details. There were a few interesting details that weren't covered elsewhere, so I moved those into other chapters.
1 parent 9fca636 commit 1801a03

File tree

5 files changed

+58
-182
lines changed

5 files changed

+58
-182
lines changed

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

+10-13
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ Options:
125125
-h, --help print this help message
126126
```
127127

128-
For hacking, often building the stage 1 compiler is enough, but for
129-
final testing and release, the stage 2 compiler is used.
128+
For hacking, often building the stage 1 compiler is enough, which saves a lot
129+
of time. But for final testing and release, the stage 2 compiler is used.
130130

131131
`./x.py check` is really fast to build the rust compiler.
132132
It is, in particular, very useful when you're doing some kind of
@@ -168,28 +168,24 @@ there is a (hacky) workaround. See [the section on "recommended
168168
workflows"](./suggested.md) below.
169169

170170
Note that this whole command just gives you a subset of the full `rustc`
171-
build. The **full** `rustc` build (what you get if you say `./x.py build
171+
build. The **full** `rustc` build (what you get with `./x.py build
172172
--stage 2 compiler/rustc`) has quite a few more steps:
173173

174174
- Build `rustc` with the stage1 compiler.
175175
- The resulting compiler here is called the "stage2" compiler.
176176
- Build `std` with stage2 compiler.
177177
- Build `librustdoc` and a bunch of other things with the stage2 compiler.
178178

179-
<a name=toolchain></a>
179+
You almost never need to do this.
180180

181181
## Build specific components
182182

183-
- Build only the core library
183+
If you are working on the standard library, you probably don't need to build
184+
the compiler unless you are planning to use a recently added nightly feature.
185+
Instead, you can just build stage 0, which uses the current beta compiler.
184186

185187
```bash
186-
./x.py build --stage 0 library/core
187-
```
188-
189-
- Build only the core and `proc_macro` libraries
190-
191-
```bash
192-
./x.py build --stage 0 library/core library/proc_macro
188+
./x.py build --stage 0 library/std
193189
```
194190

195191
Sometimes you might just want to test if the part you’re working on can
@@ -245,7 +241,8 @@ in other sections:
245241
- Building things:
246242
- `./x.py build` – builds everything using the stage 1 compiler,
247243
not just up to `std`
248-
- `./x.py build --stage 2` – builds the stage2 compiler
244+
- `./x.py build --stage 2` – builds the stage2 compiler, along with `std` and
245+
`rustdoc` (which doesn't take too long)
249246
- Running tests (see the [section on running tests](../tests/running.html) for
250247
more details):
251248
- `./x.py test library/std` – runs the `#[test]` tests from `std`

src/doc/rustc-dev-guide/src/conventions.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ chapter covers [formatting](#formatting), [coding for correctness](#cc),
88
# Formatting and the tidy script
99

1010
rustc is moving towards the [Rust standard coding style][fmt].
11-
This is enforced by the "tidy" script and can be mostly
12-
automated using `./x.py fmt`.
1311

14-
As the output of [rustfmt] is not completely stable,
15-
formatting this repository using `cargo fmt` is not recommended.
12+
However, for now we don't use stable `rustfmt`; we use a pinned version with a
13+
special config, so this may result in different style from normal [`rustfmt`].
14+
Therefore, formatting this repository using `cargo fmt` is not recommended.
1615

17-
The tidy script runs automatically when you do `./x.py test` and can be run
18-
in isolation with `./x.py test tidy`.
16+
Instead, formatting should be done using `./x.py fmt`. It's a good habit to run
17+
`./x.py fmt` before every commit, as this reduces conflicts later.
18+
19+
Formatting is checked by the "tidy" script. It runs automatically when you do
20+
`./x.py test` and can be run in isolation with `./x.py test tidy`. `./x.py fmt
21+
--check` also works.
22+
23+
If you want to use format-on-save in your editor, the pinned version of
24+
`rustfmt` is built under `build/<target>/stage0/bin/rustfmt`. You'll have to
25+
pass the <!-- date: 2021-09 --> `--edition=2021` argument yourself when calling
26+
`rustfmt` directly.
1927

2028
[fmt]: https://github.com/rust-dev-tools/fmt-rfcs
21-
[rustfmt]:https://github.com/rust-lang/rustfmt
29+
[`rustfmt`]:https://github.com/rust-lang/rustfmt
2230

2331
<a name="copyright"></a>
2432

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

+14-160
Original file line numberDiff line numberDiff line change
@@ -96,174 +96,28 @@ See [this chapter][config] for more info about configuration.
9696

9797
[config]: ./building/how-to-build-and-run.md#create-a-configtoml
9898

99-
### Building and Testing `rustc`
99+
### Common `x.py` commands
100100

101-
Here is a summary of the different commands for reference, but you probably
102-
should still read the rest of the section:
101+
Here are the basic invocations of the `x.py` commands most commonly used when
102+
working on `rustc`, `std`, `rustdoc`, and other tools.
103103

104104
| Command | When to use it |
105105
| --- | --- |
106-
| `./x.py check` | Quick check to see if things compile; [rust-analyzer can run this automatically for you][rust-analyzer] |
107-
| `./x.py build --stage 0 [library/std]` | Build only the standard library, without building the compiler |
108-
| `./x.py build library/std` | Build just the 1st stage of the compiler, along with the standard library; this is faster than building stage 2 and usually good enough |
109-
| `./x.py build --keep-stage 1 library/std` | Build the 1st stage of the compiler and skips rebuilding the standard library; this is useful after you've done an ordinary stage1 build to skip compilation time, but it can cause weird problems. (Just do a regular build to resolve.) |
110-
| `./x.py test [--keep-stage 1]` | Run the test suite using the stage1 compiler |
111-
| `./x.py test --bless [--keep-stage 1]` | Run the test suite using the stage1 compiler _and_ update expected test output. |
112-
| `./x.py build --stage 2 compiler/rustc` | Do a full 2-stage build. You almost never want to do this. |
113-
| `./x.py test --stage 2` | Do a full 2-stage build and run all tests. You almost never want to do this. |
114-
115-
To do a full 2-stage build of the whole compiler, you should run this (after
116-
updating `config.toml` as mentioned above):
106+
| `./x.py check` | Quick check to see if most things compile; [rust-analyzer can run this automatically for you][rust-analyzer] |
107+
| `./x.py build` | Builds `rustc`, `std`, and `rustdoc` |
108+
| `./x.py test` | Runs all tests |
109+
| `./x.py fmt` | Formats all code |
117110

118-
```sh
119-
./x.py build --stage 2 compiler/rustc
120-
```
121-
122-
In the process, this will also necessarily build the standard libraries, and it
123-
will build `rustdoc` (which doesn't take too long).
124-
125-
To build and test everything:
126-
127-
```sh
128-
./x.py test
129-
```
130-
131-
For most contributions, you only need to build stage 1, which saves a lot of time:
132-
133-
```sh
134-
# Build the compiler (stage 1)
135-
./x.py build library/std
136-
137-
# Subsequent builds
138-
./x.py build --keep-stage 1 library/std
139-
```
140-
141-
This will take a while, especially the first time. Be wary of accidentally
142-
touching or formatting the compiler, as `x.py` will try to recompile it.
143-
144-
**NOTE**: The `--keep-stage 1` will _assume_ that the stage 0 standard library
145-
does not need to be rebuilt, which is usually true, which will save some time.
146-
However, if you are changing certain parts of the compiler, this may lead to
147-
weird errors. Feel free to ask on [zulip][z] if you are running into issues.
148-
149-
This runs a ton of tests and takes a long time to complete. If you are
150-
working on `rustc`, you can usually get by with only the [UI tests][uitests]. These
151-
test are mostly for the frontend of the compiler, so if you are working on LLVM
152-
or codegen, this shortcut will _not_ test your changes. You can read more about the
153-
different test suites [in this chapter][testing].
111+
As written, these commands are reasonable starting points. However, there are
112+
additional options and arguments for each of them that are worth learning for
113+
serious development work. In particular, `./x.py build` and `./x.py test`
114+
provide many ways to compile or test a subset of the code, which can save a lot
115+
of time.
154116

155117
[rust-analyzer]: ./building/suggested.html#configuring-rust-analyzer-for-rustc
156-
[uitests]: ./tests/adding.html#ui
157-
[testing]: https://rustc-dev-guide.rust-lang.org/tests/intro.html
158-
159-
```sh
160-
# First build
161-
./x.py test src/test/ui
162-
163-
# Subsequent builds
164-
./x.py test src/test/ui --keep-stage 1
165-
```
166-
167-
If your changes impact test output, you can use `--bless` to automatically
168-
update the `.stderr` files of the affected tests:
169-
170-
```sh
171-
./x.py test src/test/ui --keep-stage 1 --bless
172-
```
173-
174-
While working on the compiler, it can be helpful to see if the code just
175-
compiles (similar to `cargo check`) without actually building it. You can do
176-
this with:
177-
178-
```sh
179-
./x.py check
180-
```
181-
182-
This command is really fast (relative to the other commands). It usually
183-
completes in a couple of minutes on my laptop. **A common workflow when working
184-
on the compiler is to make changes and repeatedly check with `./x.py check`.
185-
Then, run the tests as shown above when you think things should work.**
186-
187-
Finally, the CI ensures that the codebase is using consistent style. To format
188-
the code:
189-
190-
```sh
191-
# Actually format
192-
./x.py fmt
193118

194-
# Just check formatting, exit with error
195-
./x.py fmt --check
196-
```
197-
198-
*Note*: we don't use stable `rustfmt`; we use a pinned version with a special
199-
config, so this may result in different style from normal `rustfmt` if you have
200-
format-on-save turned on. It's a good habit to run `./x.py fmt` before every
201-
commit, as this reduces conflicts later. The pinned version is built under
202-
`build/<target>/stage0/bin/rustfmt`, so if you want, you can use it for a
203-
single file or for format-on-save in your editor, which can be faster than `./x.py fmt`.
204-
You'll have to pass the <!-- date: 2021-09 --> `--edition=2021` argument
205-
yourself when calling `rustfmt` directly.
206-
207-
One last thing: you can use `RUSTC_LOG=XXX` to get debug logging. [Read more
208-
here][logging]. Notice the `C` in `RUSTC_LOG`. Other than that, it uses normal
209-
[`env_logger`][envlog] or `tracing` syntax.
210-
211-
[envlog]: https://crates.io/crates/env_logger
212-
[logging]: ./tracing.md
213-
214-
### Building and Testing `std`/`core`/`alloc`/`test`/`proc_macro`/etc.
215-
216-
As before, technically the proper way to build one of these libraries is to use
217-
the stage-2 compiler, which of course requires a 2-stage build, described above
218-
(`./x.py build`).
219-
220-
In practice, though, you don't need to build the compiler unless you are
221-
planning to use a recently added nightly feature. Instead, you can just build
222-
stage 0, which uses the current beta compiler.
223-
224-
```sh
225-
./x.py build --stage 0
226-
```
227-
228-
```sh
229-
./x.py test --stage 0 library/std
230-
```
231-
232-
(The same works for `library/alloc`, `library/core`, etc.)
233-
234-
### Building and Testing `rustdoc`
235-
236-
`rustdoc` uses `rustc` internals (and, of course, the standard library), so you
237-
will have to build the compiler and `std` once before you can build `rustdoc`.
238-
As before, you can use `./x.py build` to do this. The first time you build,
239-
the stage-1 compiler will also be built.
240-
241-
```sh
242-
# First build
243-
./x.py build
244-
245-
# Subsequent builds
246-
./x.py build --keep-stage 1
247-
```
248-
249-
As with the compiler, you can do a fast check build:
250-
251-
```sh
252-
./x.py check
253-
```
254-
255-
Rustdoc has two types of tests: content tests and UI tests.
256-
257-
```sh
258-
# Content tests
259-
./x.py test src/test/rustdoc
260-
261-
# UI tests
262-
./x.py test src/test/rustdoc-ui
263-
264-
# Both at once
265-
./x.py test src/test/rustdoc src/test/rustdoc-ui
266-
```
119+
See the chapters on [building](./building/how-to-build-and-run.md) and
120+
[testing](./tests/intro.md) for more details.
267121

268122
### Contributing code to other Rust projects
269123

src/doc/rustc-dev-guide/src/rustdoc.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Rustdoc overview
22

3-
Rustdoc actually uses the rustc internals directly. It lives in-tree with the
3+
`rustdoc` uses `rustc` internals (and, of course, the standard library), so you
4+
will have to build the compiler and `std` once before you can build `rustdoc`.
5+
6+
`rustdoc` lives in-tree with the
47
compiler and standard library. This chapter is about how it works.
58
For information about Rustdoc's features and how to use them, see
69
the [Rustdoc book](https://doc.rust-lang.org/nightly/rustdoc/).
@@ -39,9 +42,11 @@ does is call the `main()` that's in this crate's `lib.rs`, though.)
3942
* Run `./x.py setup tools` before getting started. This will configure `x.py`
4043
with nice settings for developing rustdoc and other tools, including
4144
downloading a copy of rustc rather than building it.
45+
* Use `./x.py check` to quickly check for compile errors.
4246
* Use `./x.py build` to make a usable
4347
rustdoc you can run on other projects.
4448
* Add `library/test` to be able to use `rustdoc --test`.
49+
* Add `--keep-stage 1` on subsequent runs to avoid rebuilding some things.
4550
* Run `rustup toolchain link stage2 build/$TARGET/stage2` to add a
4651
custom toolchain called `stage2` to your rustup environment. After
4752
running that, `cargo +stage2 doc` in any directory will build with
@@ -52,7 +57,8 @@ does is call the `main()` that's in this crate's `lib.rs`, though.)
5257
* If you want to copy those docs to a webserver, copy all of
5358
`build/$TARGET/doc`, since that's where the CSS, JS, fonts, and landing
5459
page are.
55-
* Use `./x.py test src/test/rustdoc*` to run the tests using a stage1 rustdoc.
60+
* Use `./x.py test src/test/rustdoc*` to run the tests using a stage1
61+
rustdoc.
5662
* See [Rustdoc internals] for more information about tests.
5763

5864
## Code structure

src/doc/rustc-dev-guide/src/tests/running.md

+11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ modifying rustc to see if things are generally working correctly would be the
3636
following:
3737

3838
```bash
39+
# First build
3940
./x.py test src/test/ui
41+
42+
# Subsequent builds (optional, but can save time)
43+
./x.py test src/test/ui --keep-stage 1
4044
```
4145

4246
This will run the `ui` test suite. Of course, the choice
@@ -92,6 +96,13 @@ tests for components you did not change at all.
9296
build; therefore, while the tests **usually** work fine with stage 1,
9397
there are some limitations.
9498

99+
### Run all tests using a stage 2 compiler
100+
101+
```bash
102+
./x.py test --stage 2
103+
```
104+
You almost never need to do this.
105+
95106
## Run unit tests on the compiler/library
96107

97108
You may want to run unit tests on a specific file with following:

0 commit comments

Comments
 (0)