@@ -19,9 +19,16 @@ hop on [#rust-internals][pound-rust-internals].
1919
2020As a reminder, all contributors are expected to follow our [ Code of Conduct] [ coc ] .
2121
22+ The [ rustc-guide] is your friend! It describes how the compiler works and how
23+ to contribute to it in more detail than this document.
24+
25+ If this is your first time contributing, the [ walkthrough] chapter of the guide
26+ can give you a good example of how a typical contribution would go.
27+
2228[ pound-rust-internals ] : https://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals
2329[ internals ] : https://internals.rust-lang.org
2430[ coc ] : https://www.rust-lang.org/conduct.html
31+ [ walkthrough ] : https://rust-lang.github.io/rustc-guide/walkthrough.html
2532
2633## Feature Requests
2734[ feature-requests ] : #feature-requests
@@ -89,222 +96,14 @@ $ RUST_BACKTRACE=1 rustc ...
8996```
9097
9198## The Build System
92- [ the-build-system ] : #the-build-system
93-
94- Rust's build system allows you to bootstrap the compiler, run tests &
95- benchmarks, generate documentation, install a fresh build of Rust, and more.
96- It's your best friend when working on Rust, allowing you to compile & test
97- your contributions before submission.
98-
99- The build system lives in [ the ` src/bootstrap ` directory] [ bootstrap ] in the
100- project root. Our build system is itself written in Rust and is based on Cargo
101- to actually build all the compiler's crates. If you have questions on the build
102- system internals, try asking in [ ` #rust-internals ` ] [ pound-rust-internals ] .
103-
104- [ bootstrap ] : https://github.com/rust-lang/rust/tree/master/src/bootstrap/
105-
106- ### Configuration
107- [ configuration ] : #configuration
108-
109- Before you can start building the compiler you need to configure the build for
110- your system. In most cases, that will just mean using the defaults provided
111- for Rust.
112-
113- To change configuration, you must copy the file ` config.toml.example `
114- to ` config.toml ` in the directory from which you will be running the build, and
115- change the settings provided.
116-
117- There are large number of options provided in this config file that will alter the
118- configuration used in the build process. Some options to note:
119-
120- #### ` [llvm] ` :
121- - ` assertions = true ` = This enables LLVM assertions, which makes LLVM misuse cause an assertion failure instead of weird misbehavior. This also slows down the compiler's runtime by ~ 20%.
122- - ` ccache = true ` - Use ccache when building llvm
123-
124- #### ` [build] ` :
125- - ` compiler-docs = true ` - Build compiler documentation
126-
127- #### ` [rust] ` :
128- - ` debuginfo = true ` - Build a compiler with debuginfo. Makes building rustc slower, but then you can use a debugger to debug ` rustc ` .
129- - ` debuginfo-lines = true ` - An alternative to ` debuginfo = true ` that doesn't let you use a debugger, but doesn't make building rustc slower and still gives you line numbers in backtraces.
130- - ` debuginfo-tools = true ` - Build the extended tools with debuginfo.
131- - ` debug-assertions = true ` - Makes the log output of ` debug! ` work.
132- - ` optimize = false ` - Disable optimizations to speed up compilation of stage1 rust, but makes the stage1 compiler x100 slower.
133-
134- For more options, the ` config.toml ` file contains commented out defaults, with
135- descriptions of what each option will do.
136-
137- Note: Previously the ` ./configure ` script was used to configure this
138- project. It can still be used, but it's recommended to use a ` config.toml `
139- file. If you still have a ` config.mk ` file in your directory - from
140- ` ./configure ` - you may need to delete it for ` config.toml ` to work.
141-
142- ### Building
143- [ building ] : #building
144-
145- A default configuration requires around 3.5 GB of disk space, whereas building a debug configuration may require more than 30 GB.
14699
147- Dependencies
148- - [ build dependencies] ( README.md#building-from-source )
149- - ` gdb ` 6.2.0 minimum, 7.1 or later recommended for test builds
100+ For info on how to configure and build the compiler, please see [ this
101+ chapter] [ rustcguidebuild ] of the rustc-guide. This chapter contains info for
102+ contributions to the compiler and the standard library. It also lists some
103+ really useful commands to the build system (` ./x.py ` ), which could save you a
104+ lot of time.
150105
151- The build system uses the ` x.py ` script to control the build process. This script
152- is used to build, test, and document various parts of the compiler. You can
153- execute it as:
154-
155- ``` sh
156- python x.py build
157- ```
158-
159- On some systems you can also use the shorter version:
160-
161- ``` sh
162- ./x.py build
163- ```
164-
165- To learn more about the driver and top-level targets, you can execute:
166-
167- ``` sh
168- python x.py --help
169- ```
170-
171- The general format for the driver script is:
172-
173- ``` sh
174- python x.py < command> [< directory> ]
175- ```
176-
177- Some example commands are ` build ` , ` test ` , and ` doc ` . These will build, test,
178- and document the specified directory. The second argument, ` <directory> ` , is
179- optional and defaults to working over the entire compiler. If specified,
180- however, only that specific directory will be built. For example:
181-
182- ``` sh
183- # build the entire compiler
184- python x.py build
185-
186- # build all documentation
187- python x.py doc
188-
189- # run all test suites
190- python x.py test
191-
192- # build only the standard library
193- python x.py build src/libstd
194-
195- # test only one particular test suite
196- python x.py test src/test/rustdoc
197-
198- # build only the stage0 libcore library
199- python x.py build src/libcore --stage 0
200- ```
201-
202- You can explore the build system through the various ` --help ` pages for each
203- subcommand. For example to learn more about a command you can run:
204-
205- ```
206- python x.py build --help
207- ```
208-
209- To learn about all possible rules you can execute, run:
210-
211- ```
212- python x.py build --help --verbose
213- ```
214-
215- Note: Previously ` ./configure ` and ` make ` were used to build this project.
216- They are still available, but ` x.py ` is the recommended build system.
217-
218- ### Useful commands
219- [ useful-commands ] : #useful-commands
220-
221- Some common invocations of ` x.py ` are:
222-
223- - ` x.py build --help ` - show the help message and explain the subcommand
224- - ` x.py build src/libtest --stage 1 ` - build up to (and including) the first
225- stage. For most cases we don't need to build the stage2 compiler, so we can
226- save time by not building it. The stage1 compiler is a fully functioning
227- compiler and (probably) will be enough to determine if your change works as
228- expected.
229- - ` x.py build src/rustc --stage 1 ` - This will build just rustc, without libstd.
230- This is the fastest way to recompile after you changed only rustc source code.
231- Note however that the resulting rustc binary won't have a stdlib to link
232- against by default. You can build libstd once with ` x.py build src/libstd ` ,
233- but it is only guaranteed to work if recompiled, so if there are any issues
234- recompile it.
235- - ` x.py test ` - build the full compiler & run all tests (takes a while). This
236- is what gets run by the continuous integration system against your pull
237- request. You should run this before submitting to make sure your tests pass
238- & everything builds in the correct manner.
239- - ` x.py test src/libstd --stage 1 ` - test the standard library without
240- recompiling stage 2.
241- - ` x.py test src/test/run-pass --test-args TESTNAME ` - Run a matching set of
242- tests.
243- - ` TESTNAME ` should be a substring of the tests to match against e.g. it could
244- be the fully qualified test name, or just a part of it.
245- ` TESTNAME=collections::hash::map::test_map::test_capacity_not_less_than_len `
246- or ` TESTNAME=test_capacity_not_less_than_len ` .
247- - ` x.py test src/test/run-pass --stage 1 --test-args <substring-of-test-name> ` -
248- Run a single rpass test with the stage1 compiler (this will be quicker than
249- running the command above as we only build the stage1 compiler, not the entire
250- thing). You can also leave off the directory argument to run all stage1 test
251- types.
252- - ` x.py test src/libcore --stage 1 ` - Run stage1 tests in ` libcore ` .
253- - ` x.py test src/tools/tidy ` - Check that the source code is in compliance with
254- Rust's style guidelines. There is no official document describing Rust's full
255- guidelines as of yet, but basic rules like 4 spaces for indentation and no
256- more than 99 characters in a single line should be kept in mind when writing
257- code.
258-
259- ### Using your local build
260- [ using-local-build ] : #using-local-build
261-
262- If you use Rustup to manage your rust install, it has a feature called [ "custom
263- toolchains"] [ toolchain-link ] that you can use to access your newly-built compiler
264- without having to install it to your system or user PATH. If you've run `python
265- x.py build`, then you can add your custom rustc to a new toolchain like this:
266-
267- [ toolchain-link ] : https://github.com/rust-lang-nursery/rustup.rs#working-with-custom-toolchains-and-local-builds
268-
269- ```
270- rustup toolchain link <name> build/<host-triple>/stage2
271- ```
272-
273- Where ` <host-triple> ` is the build triple for the host (the triple of your
274- computer, by default), and ` <name> ` is the name for your custom toolchain. (If you
275- added ` --stage 1 ` to your build command, the compiler will be in the ` stage1 `
276- folder instead.) You'll only need to do this once - it will automatically point
277- to the latest build you've done.
278-
279- Once this is set up, you can use your custom toolchain just like any other. For
280- example, if you've named your toolchain ` local ` , running ` cargo +local build ` will
281- compile a project with your custom rustc, setting ` rustup override set local ` will
282- override the toolchain for your current directory, and ` cargo +local doc ` will use
283- your custom rustc and rustdoc to generate docs. (If you do this with a ` --stage 1 `
284- build, you'll need to build rustdoc specially, since it's not normally built in
285- stage 1. ` python x.py build --stage 1 src/libstd src/tools/rustdoc ` will build
286- rustdoc and libstd, which will allow rustdoc to be run with that toolchain.)
287-
288- ### Out-of-tree builds
289- [ out-of-tree-builds ] : #out-of-tree-builds
290-
291- Rust's ` x.py ` script fully supports out-of-tree builds - it looks for
292- the Rust source code from the directory ` x.py ` was found in, but it
293- reads the ` config.toml ` configuration file from the directory it's
294- run in, and places all build artifacts within a subdirectory named ` build ` .
295-
296- This means that if you want to do an out-of-tree build, you can just do it:
297- ```
298- $ cd my/build/dir
299- $ cp ~/my-config.toml config.toml # Or fill in config.toml otherwise
300- $ path/to/rust/x.py build
301- ...
302- $ # This will use the Rust source code in `path/to/rust`, but build
303- $ # artifacts will now be in ./build
304- ```
305-
306- It's absolutely fine to have multiple build directories with different
307- ` config.toml ` configurations using the same code.
106+ [ rustcguidebuild ] : https://rust-lang.github.io/rustc-guide/how-to-build-and-run.html
308107
309108## Pull Requests
310109[ pull-requests ] : #pull-requests
@@ -320,26 +119,13 @@ bring those changes into the source repository.
320119
321120Please make pull requests against the ` master ` branch.
322121
323- Compiling all of ` ./x.py test ` can take a while. When testing your pull request,
324- consider using one of the more specialized ` ./x.py ` targets to cut down on the
325- amount of time you have to wait. You need to have built the compiler at least
326- once before running these will work, but that’s only one full build rather than
327- one each time.
328-
329- $ python x.py test --stage 1
330-
331- is one such example, which builds just ` rustc ` , and then runs the tests. If
332- you’re adding something to the standard library, try
333-
334- $ python x.py test src/libstd --stage 1
335-
336122Please make sure your pull request is in compliance with Rust's style
337123guidelines by running
338124
339125 $ python x.py test src/tools/tidy
340126
341127Make this check before every pull request (and every new commit in a pull
342- request) ; you can add [ git hooks] ( https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks )
128+ request); you can add [ git hooks] ( https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks )
343129before every push to make sure you never forget to make this check.
344130
345131All pull requests are reviewed by another person. We have a bot,
@@ -532,6 +318,12 @@ to check small fixes. For example, `rustdoc src/doc/reference.md` will render
532318reference to ` doc/reference.html ` . The CSS might be messed up, but you can
533319verify that the HTML is right.
534320
321+ Additionally, contributions to the [ rustc-guide] are always welcome. Contributions
322+ can be made directly at [ the
323+ rust-lang/rustc-guide] ( https://github.com/rust-lang/rustc-guide ) repo. The issue
324+ tracker in that repo is also a great way to find things that need doing. There
325+ are issues for beginners and advanced compiler devs alike!
326+
535327## Issue Triage
536328[ issue-triage ] : #issue-triage
537329
@@ -627,7 +419,7 @@ For people new to Rust, and just starting to contribute, or even for
627419more seasoned developers, some useful places to look for information
628420are:
629421
630- * The [ rustc guide] contains information about how various parts of the compiler work
422+ * The [ rustc guide] contains information about how various parts of the compiler work and how to contribute to the compiler
631423* [ Rust Forge] [ rustforge ] contains additional documentation, including write-ups of how to achieve common tasks
632424* The [ Rust Internals forum] [ rif ] , a place to ask questions and
633425 discuss Rust's internals
0 commit comments