1
1
# Contributing to Rust
2
+ [ contributing-to-rust ] : #contributing-to-rust
2
3
3
4
Thank you for your interest in contributing to Rust! There are many ways to
4
5
contribute, and we appreciate all of them. This document is a bit long, so here's
@@ -18,18 +19,20 @@ hop on [#rust-internals][pound-rust-internals].
18
19
19
20
As a reminder, all contributors are expected to follow our [ Code of Conduct] [ coc ] .
20
21
21
- [ pound-rust-internals ] : http ://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals
22
+ [ pound-rust-internals ] : https ://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals
22
23
[ internals ] : https://internals.rust-lang.org
23
24
[ coc ] : https://www.rust-lang.org/conduct.html
24
25
25
26
## Feature Requests
27
+ [ feature-requests ] : #feature-requests
26
28
27
29
To request a change to the way that the Rust language works, please open an
28
30
issue in the [ RFCs repository] ( https://github.com/rust-lang/rfcs/issues/new )
29
31
rather than this one. New features and other significant language changes
30
32
must go through the RFC process.
31
33
32
34
## Bug Reports
35
+ [ bug-reports ] : #bug-reports
33
36
34
37
While bugs are unfortunate, they're a reality in software. We can't fix what we
35
38
don't know about, so please report liberally. If you're not sure if something
@@ -80,6 +83,7 @@ $ RUST_BACKTRACE=1 rustc ...
80
83
```
81
84
82
85
## The Build System
86
+ [ the-build-system ] : #the-build-system
83
87
84
88
Rust's build system allows you to bootstrap the compiler, run tests &
85
89
benchmarks, generate documentation, install a fresh build of Rust, and more.
@@ -94,6 +98,7 @@ system internals, try asking in [`#rust-internals`][pound-rust-internals].
94
98
[ bootstrap ] : https://github.com/rust-lang/rust/tree/master/src/bootstrap/
95
99
96
100
### Configuration
101
+ [ configuration ] : #configuration
97
102
98
103
Before you can start building the compiler you need to configure the build for
99
104
your system. In most cases, that will just mean using the defaults provided
@@ -125,6 +130,11 @@ file. If you still have a `config.mk` file in your directory - from
125
130
` ./configure ` - you may need to delete it for ` config.toml ` to work.
126
131
127
132
### Building
133
+ [ building ] : #building
134
+
135
+ Dependencies
136
+ - [ build dependencies] ( README.md#building-from-source )
137
+ - ` gdb ` 6.2.0 minimum, 7.1 or later recommended for test builds
128
138
129
139
The build system uses the ` x.py ` script to control the build process. This script
130
140
is used to build, test, and document various parts of the compiler. You can
@@ -194,6 +204,7 @@ Note: Previously `./configure` and `make` were used to build this project.
194
204
They are still available, but ` x.py ` is the recommended build system.
195
205
196
206
### Useful commands
207
+ [ useful-commands ] : #useful-commands
197
208
198
209
Some common invocations of ` x.py ` are:
199
210
@@ -234,6 +245,7 @@ Some common invocations of `x.py` are:
234
245
code.
235
246
236
247
### Using your local build
248
+ [ using-local-build ] : #using-local-build
237
249
238
250
If you use Rustup to manage your rust install, it has a feature called [ "custom
239
251
toolchains"] [ toolchain-link ] that you can use to access your newly-built compiler
@@ -262,6 +274,7 @@ stage 1. `python x.py build --stage 1 src/libstd src/tools/rustdoc` will build
262
274
rustdoc and libstd, which will allow rustdoc to be run with that toolchain.)
263
275
264
276
## Pull Requests
277
+ [ pull-requests ] : #pull-requests
265
278
266
279
Pull requests are the primary mechanism we use to change Rust. GitHub itself
267
280
has some [ great documentation] [ pull-requests ] on using the Pull Request feature.
@@ -326,32 +339,144 @@ it can be found
326
339
[ here] ( https://github.com/rust-lang/rust-wiki-backup/blob/master/Note-testsuite.md ) .
327
340
328
341
### External Dependencies
342
+ [ external-dependencies ] : #external-dependencies
329
343
330
344
Currently building Rust will also build the following external projects:
331
345
332
346
* [ clippy] ( https://github.com/rust-lang-nursery/rust-clippy )
347
+ * [ miri] ( https://github.com/solson/miri )
333
348
334
349
If your changes break one of these projects, you need to fix them by opening
335
- a pull request against the broken project. When you have opened a pull request,
336
- you can point the submodule at your pull request by calling
350
+ a pull request against the broken project asking to put the fix on a branch.
351
+ Then you can disable the tool building via ` src/tools/toolstate.toml ` .
352
+ Once the branch containing your fix is likely to be merged, you can point
353
+ the affected submodule at this branch.
354
+
355
+ Don't forget to also add your changes with
337
356
338
357
```
339
- git fetch origin pull/$id_of_your_pr/head:my_pr
340
- git checkout my_pr
358
+ git add path/to/submodule
341
359
```
342
360
343
- within the submodule's directory. Don't forget to also add your changes with
361
+ outside the submodule.
344
362
363
+ In order to prepare your PR, you can run the build locally by doing
364
+ ` ./x.py build src/tools/TOOL ` . If you will be editing the sources
365
+ there, you may wish to set ` submodules = false ` in the ` config.toml `
366
+ to prevent ` x.py ` from resetting to the original branch.
367
+
368
+ #### Breaking Tools Built With The Compiler
369
+ [ breaking-tools-built-with-the-compiler ] : #breaking-tools-built-with-the-compiler
370
+
371
+ Rust's build system builds a number of tools that make use of the
372
+ internals of the compiler. This includes clippy,
373
+ [ RLS] ( https://github.com/rust-lang-nursery/rls ) and
374
+ [ rustfmt] ( https://github.com/rust-lang-nursery/rustfmt ) . If these tools
375
+ break because of your changes, you may run into a sort of "chicken and egg"
376
+ problem. These tools rely on the latest compiler to be built so you can't update
377
+ them to reflect your changes to the compiler until those changes are merged into
378
+ the compiler. At the same time, you can't get your changes merged into the compiler
379
+ because the rust-lang/rust build won't pass until those tools build and pass their
380
+ tests.
381
+
382
+ That means that, in the default state, you can't update the compiler without first
383
+ fixing rustfmt, rls and the other tools that the compiler builds.
384
+
385
+ Luckily, a feature was [ added to Rust's build] ( https://github.com/rust-lang/rust/pull/45243 )
386
+ to make all of this easy to handle. The idea is that you mark the tools as "broken",
387
+ so that the rust-lang/rust build passes without trying to build them, then land the change
388
+ in the compiler, wait for a nightly, and go update the tools that you broke. Once you're done
389
+ and the tools are working again, you go back in the compiler and change the tools back
390
+ from "broken".
391
+
392
+ This should avoid a bunch of synchronization dances and is also much easier on contributors as
393
+ there's no need to block on rls/rustfmt/other tools changes going upstream.
394
+
395
+ Here are those same steps in detail:
396
+
397
+ 1 . (optional) First, if it doesn't exist already, create a ` config.toml ` by copying
398
+ ` config.toml.example ` in the root directory of the Rust repository.
399
+ Set ` submodules = false ` in the ` [build] ` section. This will prevent ` x.py `
400
+ from resetting to the original branch after you make your changes. If you
401
+ need to [ update any submodules to their latest versions] [ updating-submodules ] ,
402
+ see the section of this file about that for more information.
403
+ 2 . (optional) Run ` ./x.py test src/tools/rustfmt ` (substituting the submodule
404
+ that broke for ` rustfmt ` ). Fix any errors in the submodule (and possibly others).
405
+ 3 . (optional) Make commits for your changes and send them to upstream repositories as a PR.
406
+ 4 . (optional) Maintainers of these submodules will ** not** merge the PR. The PR can't be
407
+ merged because CI will be broken. You'll want to write a message on the PR referencing
408
+ your change, and how the PR should be merged once your change makes it into a nightly.
409
+ 5 . Update ` src/tools/toolstate.toml ` to indicate that the tool in question is "broken",
410
+ that will disable building it on CI. See the documentation in that file for the exact
411
+ configuration values you can use.
412
+ 6 . Commit the changes to ` src/tools/toolstate.toml ` , ** do not update submodules in your commit** ,
413
+ and then update the PR you have for rust-lang/rust.
414
+ 7 . Wait for your PR to merge.
415
+ 8 . Wait for a nightly
416
+ 9 . (optional) Help land your PR on the upstream repository now that your changes are in nightly.
417
+ 10 . (optional) Send a PR to rust-lang/rust updating the submodule, reverting ` src/tools/toolstate.toml ` back to a "building" or "testing" state.
418
+
419
+ #### Updating submodules
420
+ [ updating-submodules ] : #updating-submodules
421
+
422
+ These instructions are specific to updating ` rustfmt ` , however they may apply
423
+ to the other submodules as well. Please help by improving these instructions
424
+ if you find any discrepencies or special cases that need to be addressed.
425
+
426
+ To update the ` rustfmt ` submodule, start by running the appropriate
427
+ [ ` git submodule ` command] ( https://git-scm.com/book/en/v2/Git-Tools-Submodules ) .
428
+ For example, to update to the latest commit on the remote master branch,
429
+ you may want to run:
345
430
```
346
- git add path/to/submodule
431
+ git submodule update --remote src/tools/rustfmt
347
432
```
433
+ If you run ` ./x.py build ` now, and you are lucky, it may just work. If you see
434
+ an error message about patches that did not resolve to any crates, you will need
435
+ to complete a few more steps which are outlined with their rationale below.
348
436
349
- outside the submodule.
437
+ * (This error may change in the future to include more information.)*
438
+ ```
439
+ error: failed to resolve patches for `https://github.com/rust-lang-nursery/rustfmt`
440
+
441
+ Caused by:
442
+ patch for `rustfmt-nightly` in `https://github.com/rust-lang-nursery/rustfmt` did not resolve to any crates
443
+ failed to run: ~/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path ~/rust/src/bootstrap/Cargo.toml
444
+ ```
445
+
446
+ If you haven't used the ` [patch] `
447
+ section of ` Cargo.toml ` before, there is [ some relevant documentation about it
448
+ in the cargo docs] ( http://doc.crates.io/manifest.html#the-patch-section ) . In
449
+ addition to that, you should read the
450
+ [ Overriding dependencies] ( http://doc.crates.io/specifying-dependencies.html#overriding-dependencies )
451
+ section of the documentation as well.
452
+
453
+ Specifically, the following [ section in Overriding dependencies] ( http://doc.crates.io/specifying-dependencies.html#testing-a-bugfix ) reveals what the problem is:
454
+
455
+ > Next up we need to ensure that our lock file is updated to use this new version of uuid so our project uses the locally checked out copy instead of one from crates.io. The way [ patch] works is that it'll load the dependency at ../path/to/uuid and then whenever crates.io is queried for versions of uuid it'll also return the local version.
456
+ >
457
+ > This means that the version number of the local checkout is significant and will affect whether the patch is used. Our manifest declared uuid = "1.0" which means we'll only resolve to >= 1.0.0, < 2.0.0, and Cargo's greedy resolution algorithm also means that we'll resolve to the maximum version within that range. Typically this doesn't matter as the version of the git repository will already be greater or match the maximum version published on crates.io, but it's important to keep this in mind!
458
+
459
+ This says that when we updated the submodule, the version number in our
460
+ ` src/tools/rustfmt/Cargo.toml ` changed. The new version is different from
461
+ the version in ` Cargo.lock ` , so the build can no longer continue.
462
+
463
+ To resolve this, we need to update ` Cargo.lock ` . Luckily, cargo provides a
464
+ command to do this easily.
465
+
466
+ First, go into the ` src/ ` directory since that is where ` Cargo.toml ` is in
467
+ the rust repository. Then run, ` cargo update -p rustfmt-nightly ` to solve
468
+ the problem.
469
+
470
+ ```
471
+ $ cd src
472
+ $ cargo update -p rustfmt-nightly
473
+ ```
350
474
351
- It can also be more convenient during development to set ` submodules = false `
352
- in the ` config.toml ` to prevent ` x.py ` from resetting to the original branch .
475
+ This should change the version listed in ` src/Cargo.lock ` to the new version you updated
476
+ the submodule to. Running ` ./ x.py build ` should work now .
353
477
354
478
## Writing Documentation
479
+ [ writing-documentation ] : #writing-documentation
355
480
356
481
Documentation improvements are very welcome. The source of ` doc.rust-lang.org `
357
482
is located in ` src/doc ` in the tree, and standard API documentation is generated
@@ -382,6 +507,7 @@ reference to `doc/reference.html`. The CSS might be messed up, but you can
382
507
verify that the HTML is right.
383
508
384
509
## Issue Triage
510
+ [ issue-triage ] : #issue-triage
385
511
386
512
Sometimes, an issue will stay open, even though the bug has been fixed. And
387
513
sometimes, the original bug may go stale because something has changed in the
@@ -449,6 +575,7 @@ If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
449
575
[ rfcbot ] : https://github.com/dikaiosune/rust-dashboard/blob/master/RFCBOT.md
450
576
451
577
## Out-of-tree Contributions
578
+ [ out-of-tree-contributions ] : #out-of-tree-contributions
452
579
453
580
There are a number of other ways to contribute to Rust that don't deal with
454
581
this repository.
@@ -468,11 +595,13 @@ valuable!
468
595
[ community-library ] : https://github.com/rust-lang/rfcs/labels/A-community-library
469
596
470
597
## Helpful Links and Information
598
+ [ helpful-info ] : #helpful-info
471
599
472
600
For people new to Rust, and just starting to contribute, or even for
473
601
more seasoned developers, some useful places to look for information
474
602
are:
475
603
604
+ * [ Rust Forge] [ rustforge ] contains additional documentation, including write-ups of how to achieve common tasks
476
605
* The [ Rust Internals forum] [ rif ] , a place to ask questions and
477
606
discuss Rust's internals
478
607
* The [ generated documentation for rust's compiler] [ gdfrustc ]
488
617
[ gsearchdocs ] : https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
489
618
[ rif ] : http://internals.rust-lang.org
490
619
[ rr ] : https://doc.rust-lang.org/book/README.html
620
+ [ rustforge ] : https://forge.rust-lang.org/
491
621
[ tlgba ] : http://tomlee.co/2014/04/a-more-detailed-tour-of-the-rust-compiler/
492
622
[ ro ] : http://www.rustaceans.org/
493
623
[ rctd ] : ./src/test/COMPILER_TESTS.md
0 commit comments