Skip to content

Commit f66b472

Browse files
authored
Add quickstart for how to build and run the compiler (#1951)
* Add quickstart for how to build and run the compiler The chapter is quite long, and a lot of the information is, while valuable, not very important for newcomers. I think it makes sense to have a condensed version for anyone just wanting to get started with only the most important information. * A few improvements to quickstart
1 parent f109549 commit f66b472

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Building and debugging `rustc`
99

1010
- [How to build and run the compiler](./building/how-to-build-and-run.md)
11+
- [Quickstart](./building/quickstart.md)
1112
- [Prerequisites](./building/prerequisites.md)
1213
- [Suggested Workflows](./building/suggested.md)
1314
- [Distribution artifacts](./building/build-install-distribution-artifacts.md)

src/building/how-to-build-and-run.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
The compiler is built using a tool called `x.py`. You will need to
66
have Python installed to run it.
77

8+
## Quick Start
9+
10+
For a less in-depth quick-start of getting the compiler running, see [quickstart](./quickstart.md).
11+
12+
813
## Get the source code
914

1015
The main repository is [`rust-lang/rust`][repo]. This contains the compiler,

src/building/quickstart.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Quickstart
2+
3+
This is a quickstart guide about getting the compiler running. For more information in the individual steps,
4+
see the other pages in this chapter.
5+
6+
First, clone the repository:
7+
8+
```sh
9+
git clone https://github.com/rust-lang/rust.git
10+
cd rust
11+
```
12+
13+
When building the compiler, we don't use `cargo` directly, instead we use a wrapper called "x".
14+
It is invoked with `./x`.
15+
16+
We need to create a configuration for the build. Use `./x setup` to create a good default.
17+
18+
```sh
19+
./x setup
20+
```
21+
22+
Then, we can build the compiler. Use `./x build` to build the compiler, standard library and a few tools.
23+
You can also `./x check` to just check it.
24+
All these commands can take specific components/paths as arguments, for example `./x check compiler` to just check the compiler.
25+
26+
```sh
27+
./x build
28+
```
29+
30+
> When doing a change to the compiler that does not affect the way it compiles the standard library
31+
(so for example, a change to an error message), use `--keep-stage-std 1` to avoid recompiling it.
32+
33+
After building the compiler and standard library, you now have a working compiler toolchain.
34+
You can use it with rustup by linking it.
35+
36+
```sh
37+
rustup toolchain link stage1 build/host/stage1
38+
```
39+
40+
Now you have a toolchain called `stage1` linked to your build. You can use it to test the compiler.
41+
42+
```sh
43+
rustc +stage1 testfile.rs
44+
```
45+
46+
After doing a change, you can run the compiler test suite with `./x test`.
47+
48+
`./x test` runs the full test suite, which is slow and rarely what you want.
49+
Usually, `./x test tests/ui` is what you want after a comiler change,
50+
testing all [UI tests](../tests/ui.md) that invoke the compiler on a specific test file and check the output.
51+
52+
```sh
53+
./x test tests/ui
54+
```
55+
56+
Use `--bless` if you've made a change and want to update the `.stderr` files with the new output.
57+
58+
> `./x suggest` can also be helpful for suggesting which tests to run after a change.
59+
60+
Congrats, you are now ready to make a change to the compiler! If you have more questions,
61+
[the full chapter](./how-to-build-and-run.md) might contain the answers, and if it doesn't,
62+
feel free to ask for help on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp).
63+
64+
If you use VSCode, `./x setup` will ask you if you want to set up the config. For other editors, check out [suggested workflows](./suggested.md).

0 commit comments

Comments
 (0)