Skip to content

Commit 7846610

Browse files
committedDec 7, 2016
Auto merge of #37817 - alexcrichton:rustbuild-default, r=brson
mk: Switch rustbuild to the default build system This commit switches the default build system for Rust from the makefiles to rustbuild. The rustbuild build system has been in development for almost a year now and has become quite mature over time. This commit is an implementation of the proposal on [internals] which slates deletion of the makefiles on 2017-02-02. [internals]: https://internals.rust-lang.org/t/proposal-for-promoting-rustbuild-to-official-status/4368 This commit also updates various documentation in `README.md`, `CONTRIBUTING.md`, `src/bootstrap/README.md`, and throughout the source code of rustbuild itself.
2 parents 5938eba + 0e272de commit 7846610

File tree

29 files changed

+757
-298
lines changed

29 files changed

+757
-298
lines changed
 

‎.travis.yml

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
language: rust
1+
language: minimal
22
sudo: required
33
dist: trusty
44
services:
@@ -20,7 +20,7 @@ matrix:
2020
- env: IMAGE=x86_64-gnu-cargotest
2121
- env: IMAGE=x86_64-gnu-debug
2222
- env: IMAGE=x86_64-gnu-nopt
23-
- env: IMAGE=x86_64-gnu-rustbuild
23+
- env: IMAGE=x86_64-gnu-make
2424
- env: IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1
2525
- env: IMAGE=x86_64-musl
2626

@@ -39,7 +39,7 @@ matrix:
3939
install: brew install ccache
4040
- env: >
4141
RUST_CHECK_TARGET=check
42-
RUST_CONFIGURE_ARGS=--target=x86_64-apple-darwin --enable-rustbuild
42+
RUST_CONFIGURE_ARGS=--target=x86_64-apple-darwin --disable-rustbuild
4343
SRC=.
4444
os: osx
4545
install: brew install ccache
@@ -51,17 +51,16 @@ matrix:
5151
install: brew install ccache
5252
5353
script:
54-
- if [ -z "$ALLOW_PR" ] && [ "$TRAVIS_BRANCH" != "auto" ]; then
55-
echo skipping, not a full build;
56-
elif [ -z "$ENABLE_AUTO" ] then
57-
echo skipping, not quite ready yet
58-
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
59-
git submodule update --init;
60-
src/ci/run.sh;
61-
else
62-
git submodule update --init;
63-
src/ci/docker/run.sh $IMAGE;
64-
fi
54+
- >
55+
if [ "$ALLOW_PR" = "" ] && [ "$TRAVIS_BRANCH" != "auto" ]; then
56+
echo skipping, not a full build;
57+
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
58+
git submodule update --init;
59+
src/ci/run.sh;
60+
else
61+
git submodule update --init;
62+
src/ci/docker/run.sh $IMAGE;
63+
fi
6564
6665
# Save tagged docker images we created and load them if they're available
6766
before_cache:

‎CONTRIBUTING.md

+111-40
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,17 @@ benchmarks, generate documentation, install a fresh build of Rust, and more.
8686
It's your best friend when working on Rust, allowing you to compile & test
8787
your contributions before submission.
8888

89-
All the configuration for the build system lives in [the `mk` directory][mkdir]
90-
in the project root. It can be hard to follow in places, as it uses some
91-
advanced Make features which make for some challenging reading. If you have
92-
questions on the build system internals, try asking in
93-
[`#rust-internals`][pound-rust-internals].
89+
The build system lives in [the `src/bootstrap` directory][bootstrap] in the
90+
project root. Our build system is itself written in Rust and is based on Cargo
91+
to actually build all the compiler's crates. If you have questions on the build
92+
system internals, try asking in [`#rust-internals`][pound-rust-internals].
9493

95-
[mkdir]: https://github.com/rust-lang/rust/tree/master/mk/
94+
[bootstrap]: https://github.com/rust-lang/rust/tree/master/src/bootstrap/
95+
96+
> **Note**: the build system was recently rewritten from a jungle of makefiles
97+
> to the current incarnation you'll see in `src/bootstrap`. If you experience
98+
> bugs you can temporarily revert back to the makefiles with
99+
> `--disable-rustbuild` passed to `./configure`.
96100
97101
### Configuration
98102

@@ -119,42 +123,111 @@ configuration used later in the build process. Some options to note:
119123

120124
To see a full list of options, run `./configure --help`.
121125

122-
### Useful Targets
123-
124-
Some common make targets are:
125-
126-
- `make tips` - show useful targets, variables and other tips for working with
127-
the build system.
128-
- `make rustc-stage1` - build up to (and including) the first stage. For most
129-
cases we don't need to build the stage2 compiler, so we can save time by not
130-
building it. The stage1 compiler is a fully functioning compiler and
131-
(probably) will be enough to determine if your change works as expected.
132-
- `make $host/stage1/bin/rustc` - Where $host is a target triple like x86_64-unknown-linux-gnu.
133-
This will build just rustc, without libstd. This is the fastest way to recompile after
134-
you changed only rustc source code. Note however that the resulting rustc binary
135-
won't have a stdlib to link against by default. You can build libstd once with
136-
`make rustc-stage1`, rustc will pick it up afterwards. libstd is only guaranteed to
137-
work if recompiled, so if there are any issues recompile it.
138-
- `make check` - build the full compiler & run all tests (takes a while). This
126+
### Building
127+
128+
Although the `./configure` script will generate a `Makefile`, this is actually
129+
just a thin veneer over the actual build system driver, `x.py`. This file, at
130+
the root of the repository, is used to build, test, and document various parts
131+
of the compiler. You can execute it as:
132+
133+
```sh
134+
python x.py build
135+
```
136+
137+
On some systems you can also use the shorter version:
138+
139+
```sh
140+
./x.py build
141+
```
142+
143+
To learn more about the driver and top-level targets, you can execute:
144+
145+
```sh
146+
python x.py --help
147+
```
148+
149+
The general format for the driver script is:
150+
151+
```sh
152+
python x.py <command> [<directory>]
153+
```
154+
155+
Some example commands are `build`, `test`, and `doc`. These will build, test,
156+
and document the specified directory. The second argument, `<directory>`, is
157+
optional and defaults to working over the entire compiler. If specified,
158+
however, only that specific directory will be built. For example:
159+
160+
```sh
161+
# build the entire compiler
162+
python x.py build
163+
164+
# build all documentation
165+
python x.py doc
166+
167+
# run all test suites
168+
python x.py test
169+
170+
# build only the standard library
171+
python x.py build src/libstd
172+
173+
# test only one particular test suite
174+
python x.py test src/test/rustdoc
175+
176+
# build only the stage0 libcore library
177+
python x.py build src/libcore --stage 0
178+
```
179+
180+
You can explore the build system throught the various `--help` pages for each
181+
subcommand. For example to learn more about a command you can run:
182+
183+
```
184+
python x.py build --help
185+
```
186+
187+
To learn about all possible rules you can execute, run:
188+
189+
```
190+
python x.py build --help --verbose
191+
```
192+
193+
### Useful commands
194+
195+
Some common invocations of `x.py` are:
196+
197+
- `x.py build --help` - show the help message and explain the subcommand
198+
- `x.py build src/libtest --stage 1` - build up to (and including) the first
199+
stage. For most cases we don't need to build the stage2 compiler, so we can
200+
save time by not building it. The stage1 compiler is a fully functioning
201+
compiler and (probably) will be enough to determine if your change works as
202+
expected.
203+
- `x.py build src/rustc --stage 1` - This will build just rustc, without libstd.
204+
This is the fastest way to recompile after you changed only rustc source code.
205+
Note however that the resulting rustc binary won't have a stdlib to link
206+
against by default. You can build libstd once with `x.py build src/libstd`,
207+
but it is is only guaranteed to work if recompiled, so if there are any issues
208+
recompile it.
209+
- `x.py test` - build the full compiler & run all tests (takes a while). This
139210
is what gets run by the continuous integration system against your pull
140211
request. You should run this before submitting to make sure your tests pass
141212
& everything builds in the correct manner.
142-
- `make check-stage1-std NO_REBUILD=1` - test the standard library without
143-
rebuilding the entire compiler
144-
- `make check TESTNAME=<substring-of-test-name>` - Run a matching set of tests.
213+
- `x.py test src/libstd --stage 1` - test the standard library without
214+
recompiling stage 2.
215+
- `x.py test src/test/run-pass --filter TESTNAME` - Run a matching set of tests.
145216
- `TESTNAME` should be a substring of the tests to match against e.g. it could
146217
be the fully qualified test name, or just a part of it.
147218
`TESTNAME=collections::hash::map::test_map::test_capacity_not_less_than_len`
148219
or `TESTNAME=test_capacity_not_less_than_len`.
149-
- `make check-stage1-rpass TESTNAME=<substring-of-test-name>` - Run a single
150-
rpass test with the stage1 compiler (this will be quicker than running the
151-
command above as we only build the stage1 compiler, not the entire thing).
152-
You can also leave off the `-rpass` to run all stage1 test types.
153-
- `make check-stage1-coretest` - Run stage1 tests in `libcore`.
154-
- `make tidy` - Check that the source code is in compliance with Rust's style
155-
guidelines. There is no official document describing Rust's full guidelines
156-
as of yet, but basic rules like 4 spaces for indentation and no more than 99
157-
characters in a single line should be kept in mind when writing code.
220+
- `x.py test src/test/run-pass --stage 1 --filter <substring-of-test-name>` -
221+
Run a single rpass test with the stage1 compiler (this will be quicker than
222+
running the command above as we only build the stage1 compiler, not the entire
223+
thing). You can also leave off the directory argument to run all stage1 test
224+
types.
225+
- `x.py test src/libcore --stage 1` - Run stage1 tests in `libcore`.
226+
- `x.py test src/tools/tidy` - Check that the source code is in compliance with
227+
Rust's style guidelines. There is no official document describing Rust's full
228+
guidelines as of yet, but basic rules like 4 spaces for indentation and no
229+
more than 99 characters in a single line should be kept in mind when writing
230+
code.
158231

159232
## Pull Requests
160233

@@ -172,19 +245,17 @@ amount of time you have to wait. You need to have built the compiler at least
172245
once before running these will work, but that’s only one full build rather than
173246
one each time.
174247

175-
$ make -j8 rustc-stage1 && make check-stage1
248+
$ python x.py test --stage 1
176249

177250
is one such example, which builds just `rustc`, and then runs the tests. If
178251
you’re adding something to the standard library, try
179252

180-
$ make -j8 check-stage1-std NO_REBUILD=1
181-
182-
This will not rebuild the compiler, but will run the tests.
253+
$ python x.py test src/libstd --stage 1
183254

184255
Please make sure your pull request is in compliance with Rust's style
185256
guidelines by running
186257

187-
$ make tidy
258+
$ python x.py test src/tools/tidy
188259

189260
Make this check before every pull request (and every new commit in a pull
190261
request) ; you can add [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)

‎README.md

+13-33
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ Read ["Installing Rust"] from [The Book].
3636

3737
```sh
3838
$ ./configure
39-
$ make && make install
39+
$ make && sudo make install
4040
```
4141

42-
> ***Note:*** You may need to use `sudo make install` if you do not
43-
> normally have permission to modify the destination directory. The
44-
> install locations can be adjusted by passing a `--prefix` argument
45-
> to `configure`. Various other options are also supported – pass
42+
> ***Note:*** Install locations can be adjusted by passing a `--prefix`
43+
> argument to `configure`. Various other options are also supported – pass
4644
> `--help` for more information on them.
4745

48-
When complete, `make install` will place several programs into
46+
When complete, `sudo make install` will place several programs into
4947
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
5048
API-documentation tool. This install does not include [Cargo],
5149
Rust's package manager, which you may also want to build.
@@ -108,30 +106,22 @@ MSVC builds of Rust additionally require an installation of Visual Studio 2013
108106
(or later) so `rustc` can use its linker. Make sure to check the “C++ tools”
109107
option.
110108

111-
With these dependencies installed, the build takes two steps:
109+
With these dependencies installed, you can build the compiler in a `cmd.exe`
110+
shell with:
112111

113112
```sh
114-
$ ./configure
115-
$ make && make install
113+
> python x.py build
116114
```
117115

118-
#### MSVC with rustbuild
119-
120-
The old build system, based on makefiles, is currently being rewritten into a
121-
Rust-based build system called rustbuild. This can be used to bootstrap the
122-
compiler on MSVC without needing to install MSYS or MinGW. All you need are
123-
[Python 2](https://www.python.org/downloads/),
124-
[CMake](https://cmake.org/download/), and
125-
[Git](https://git-scm.com/downloads) in your PATH (make sure you do not use the
126-
ones from MSYS if you have it installed). You'll also need Visual Studio 2013 or
127-
newer with the C++ tools. Then all you need to do is to kick off rustbuild.
116+
If you're running inside of an msys shell, however, you can run:
128117

129-
```
130-
python x.py build
118+
```sh
119+
$ ./configure --build=x86_64-pc-windows-msvc
120+
$ make && make install
131121
```
132122

133-
Currently rustbuild only works with some known versions of Visual Studio. If you
134-
have a more recent version installed that a part of rustbuild doesn't understand
123+
Currently building Rust only works with some known versions of Visual Studio. If
124+
you have a more recent version installed the build system doesn't understand
135125
then you may need to force rustbuild to use an older version. This can be done
136126
by manually calling the appropriate vcvars file before running the bootstrap.
137127

@@ -149,16 +139,6 @@ $ ./configure
149139
$ make docs
150140
```
151141

152-
Building the documentation requires building the compiler, so the above
153-
details will apply. Once you have the compiler built, you can
154-
155-
```sh
156-
$ make docs NO_REBUILD=1
157-
```
158-
159-
To make sure you don’t re-build the compiler because you made a change
160-
to some documentation.
161-
162142
The generated documentation will appear in a top-level `doc` directory,
163143
created by the `make` rule.
164144

0 commit comments

Comments
 (0)
Please sign in to comment.