Skip to content

Commit dc6ed63

Browse files
committed
Added info on the build system to contributing guide
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.
1 parent c22cb53 commit dc6ed63

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

CONTRIBUTING.md

+55
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,60 @@ to do this is to invoke `rustc` like this:
7778
$ RUST_BACKTRACE=1 rustc ...
7879
```
7980

81+
## The Build System
82+
83+
The build system for Rust is complex. It covers bootstrapping the compiler,
84+
running tests, building documentation and more. Unless you are familiar with
85+
Makefiles, I wouldn't suggest trying to understand everything going on in
86+
Rust's setup - there's a lot there, and you can get lost trying to understand
87+
it all.
88+
89+
If Makefiles are your thing, though, all the configuration lives in
90+
[the `mk` directory][mkdir] in the project root.
91+
92+
[mkdir]: https://github.com/rust-lang/rust/tree/master/mk/
93+
94+
### Configuration
95+
96+
Before you can start building the compiler you need to configure the build for
97+
your system. In most cases, that will just mean using the defaults provided
98+
for Rust. Configuring involves invoking the `configure` script in the project
99+
root.
100+
101+
```
102+
./configure
103+
```
104+
105+
There are large number of options accepted by this script to alter the
106+
configuration used later in the build process. Some options to note:
107+
108+
- `--enable-debug` - Build a debug version of the compiler (disables optimizations)
109+
- `--disable-valgrind-rpass` - Don't run tests with valgrind
110+
- `--enable-clang` - Prefer clang to gcc for building dependencies (ie LLVM)
111+
- `--enable-ccache` - Invoke clang/gcc with ccache to re-use object files between builds
112+
113+
To see a full list of options, run `./configure --help`.
114+
115+
### Useful Targets
116+
117+
Some common make targets are:
118+
119+
- `make rustc-stage1` - build up to (and including) the first stage. For most
120+
cases we don't need to build the stage2 compiler, so we can save time by not
121+
building it. The stage1 compiler is a fully functioning compiler and
122+
(probably) will be enough to determine if your change works as expected.
123+
- `make check` - build the full compiler & run all tests (takes a while). This
124+
is what gets run by the continuous integration system against your pull
125+
request. You should run this before submitting to make sure your tests pass
126+
& everything builds in the correct manner.
127+
- `make check-stage1-std NO_REBUILD=1` - test the standard library without
128+
rebuilding the entire compiler
129+
- `make check TESTNAME=<path-to-test-file>.rs` - Run a single test file
130+
- `make check-stage1-rpass TESTNAME=<path-to-test-file>.rs` - Run a single
131+
rpass test with the stage1 compiler (this will be quicker than running the
132+
command above as we only build the stage1 compiler, not the entire thing).
133+
You can also leave off the `-rpass` to run all stage1 test types.
134+
80135
## Pull Requests
81136

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

0 commit comments

Comments
 (0)