Skip to content

Commit cb3680c

Browse files
committed
Rollup merge of rust-lang#31186 - gchp:contributing, r=alexcrichton
I recently wrote a blog post on contributing to the Rust compiler which gained some interest. It was mentioned in a comment on Reddit that it would be useful to integrate some of the information from that post to the official contributing guide. This is the start of my efforts to integrate what I wrote with the official guide. This commit adds information on the build system. It is not a complete guide on the build system, but it should be enough to provide a good starting place for those wishing to contribute.
2 parents b29628a + 05f7b59 commit cb3680c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

CONTRIBUTING.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ links to the major sections:
66

77
* [Feature Requests](#feature-requests)
88
* [Bug Reports](#bug-reports)
9+
* [The Build System](#the-build-system)
910
* [Pull Requests](#pull-requests)
1011
* [Writing Documentation](#writing-documentation)
1112
* [Issue Triage](#issue-triage)
@@ -77,6 +78,66 @@ to do this is to invoke `rustc` like this:
7778
$ RUST_BACKTRACE=1 rustc ...
7879
```
7980

81+
## The Build System
82+
83+
Rust's build system allows you to bootstrap the compiler, run tests &
84+
benchmarks, generate documentation, install a fresh build of Rust, and more.
85+
It's your best friend when working on Rust, allowing you to compile & test
86+
your contributions before submission.
87+
88+
All the configuration for the build system lives in [the `mk` directory][mkdir]
89+
in the project root. It can be hard to follow in places, as it uses some
90+
advanced Make features which make for some challenging reading. If you have
91+
questions on the build system internals, try asking in
92+
[`#rust-internals`][pound-rust-internals].
93+
94+
[mkdir]: https://github.com/rust-lang/rust/tree/master/mk/
95+
96+
### Configuration
97+
98+
Before you can start building the compiler you need to configure the build for
99+
your system. In most cases, that will just mean using the defaults provided
100+
for Rust. Configuring involves invoking the `configure` script in the project
101+
root.
102+
103+
```
104+
./configure
105+
```
106+
107+
There are large number of options accepted by this script to alter the
108+
configuration used later in the build process. Some options to note:
109+
110+
- `--enable-debug` - Build a debug version of the compiler (disables optimizations)
111+
- `--enable-optimize` - Enable optimizations (can be used with `--enable-debug`
112+
to make a debug build with optimizations)
113+
- `--disable-valgrind-rpass` - Don't run tests with valgrind
114+
- `--enable-clang` - Prefer clang to gcc for building dependencies (e.g., LLVM)
115+
- `--enable-ccache` - Invoke clang/gcc with ccache to re-use object files between builds
116+
- `--enable-compiler-docs` - Build compiler documentation
117+
118+
To see a full list of options, run `./configure --help`.
119+
120+
### Useful Targets
121+
122+
Some common make targets are:
123+
124+
- `make rustc-stage1` - build up to (and including) the first stage. For most
125+
cases we don't need to build the stage2 compiler, so we can save time by not
126+
building it. The stage1 compiler is a fully functioning compiler and
127+
(probably) will be enough to determine if your change works as expected.
128+
- `make check` - build the full compiler & run all tests (takes a while). This
129+
is what gets run by the continuous integration system against your pull
130+
request. You should run this before submitting to make sure your tests pass
131+
& everything builds in the correct manner.
132+
- `make check-stage1-std NO_REBUILD=1` - test the standard library without
133+
rebuilding the entire compiler
134+
- `make check TESTNAME=<path-to-test-file>.rs` - Run a single test file
135+
- `make check-stage1-rpass TESTNAME=<path-to-test-file>.rs` - Run a single
136+
rpass test with the stage1 compiler (this will be quicker than running the
137+
command above as we only build the stage1 compiler, not the entire thing).
138+
You can also leave off the `-rpass` to run all stage1 test types.
139+
- `make check-stage1-coretest` - Run stage1 tests in `libcore`.
140+
80141
## Pull Requests
81142

82143
Pull requests are the primary mechanism we use to change Rust. GitHub itself

0 commit comments

Comments
 (0)