@@ -66,7 +66,6 @@ There are no hard hardware requirements, but building the compiler is
66
66
computationally expensive, so a beefier machine will help, and I wouldn't
67
67
recommend trying to build on a Raspberry Pi : P
68
68
69
- - x86 and ARM are both supported (TODO: confirm)
70
69
- Recommended >=30GB of free disk space; otherwise, you will have to keep
71
70
clearing incremental caches. More space is better, the compiler is a bit of a
72
71
hog; it's a problem we are aware of.
@@ -125,34 +124,60 @@ In the top level of the repo:
125
124
cp config.toml.example config.toml
126
125
```
127
126
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
129
128
the following settings:
130
129
131
130
- ` debug = true ` : enables debug symbols and ` debug! ` logging, takes a bit longer to compile.
132
131
- ` incremental = true ` : enables incremental compilation of the compiler itself,
133
132
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.
136
136
- ` llvm-config ` : enables building with system LLVM. [ See this chapter] [ sysllvm ]
137
137
for more info. This avoids building LLVM, which can take a while.
138
138
139
139
[ sysllvm ] : ./building/suggested.html#building-with-system-llvm
140
140
141
141
### ` ./x.py ` Intro
142
142
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
144
144
get the original compiler from? We use the current beta compiler
145
145
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
147
150
148
151
We have a special tool ` ./x.py ` that drives this process. It is used for
149
152
compiling the compiler, the standard libraries, and ` rustdoc ` . It is also used
150
153
for driving CI and building the final release artifacts.
151
154
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
+
152
162
### Building and Testing ` rustc `
153
163
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:
156
181
157
182
``` shell
158
183
# Build the compiler (stage 1)
@@ -170,33 +195,36 @@ does not need to be rebuilt, which is usually true, which will save some time.
170
195
However, if you are changing certain parts of the compiler, this may lead to
171
196
weird errors. Feel free to ask on [ zulip] [ z ] if you are running into issues.
172
197
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
174
206
175
207
```
176
- # UI tests
177
208
# First build
178
209
./x.py test --stage 1 src/test/ui
179
210
180
211
# Subsequent builds
181
212
./x.py test --stage 1 src/test/ui --keep-stage 1
182
213
```
183
214
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:
194
218
195
219
``` shell
196
220
./x.py check
197
221
```
198
222
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:
200
228
201
229
``` shell
202
230
# Actually format
@@ -206,15 +234,27 @@ To format the code:
206
234
./x.py fmt --check
207
235
```
208
236
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.
210
245
246
+ [ envlog ] : https://crates.io/crates/env_logger
211
247
[ logging ] : ./compiler-debugging.html#getting-logging-output
212
248
213
249
### Building and Testing ` std ` /` core ` /` alloc ` /` test ` /` proc_macro ` /etc.
214
250
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
216
256
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) .
218
258
219
259
``` sh
220
260
./x.py build --stage 0 src/libstd
@@ -224,13 +264,16 @@ stage 0.
224
264
./x.py test --stage 0 src/libstd
225
265
```
226
266
267
+ (The same works for ` src/liballoc ` , ` src/libcore ` , etc.)
268
+
227
269
### Building and Testing ` rustdoc `
228
270
229
271
` rustdoc ` uses ` rustc ` internals (and, of course, the standard library), so you
230
272
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.
231
274
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 .
234
277
235
278
``` sh
236
279
# First build
@@ -240,7 +283,11 @@ even though the release version will use the full 2-stage build.
240
283
./x.py build --stage 1 --keep-stage 1 src/tools/rustdoc
241
284
```
242
285
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
+ ```
244
291
245
292
Rustdoc has two types of tests: content tests and UI tests.
246
293
@@ -421,5 +468,3 @@ master.
421
468
- [ The compiler's documentation (rustdocs)] ( https://doc.rust-lang.org/nightly/nightly-rustc/ )
422
469
- [ The Forge] ( https://forge.rust-lang.org/ ) has more documentation about various procedures.
423
470
- ` #contribute ` , ` #compiler ` , and ` #rustdoc ` on [ Discord] ( https://discord.gg/rust-lang ) .
424
-
425
- TODO: am I missing any?
0 commit comments