Skip to content

Commit 6f6f663

Browse files
committed
---
yaml --- r: 277823 b: refs/heads/try c: a4d2424 h: refs/heads/master i: 277821: a8d0594 277819: d678534 277815: 2ae4914 277807: 1ef55ce 277791: 9752f01 277759: daab45d
1 parent 99c7606 commit 6f6f663

File tree

191 files changed

+4890
-2531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+4890
-2531
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: 805666a4d283b60f9f4b979b53b3d498cd876f2e
4+
refs/heads/try: a4d2424cc304e97f553c6d8eef17a24dc2f12c01
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/Makefile.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@
5959
# * check-stage$(stage)-$(crate) - Test a crate in a specific stage
6060
# * check-stage$(stage)-{rpass,rfail,cfail,rmake,...} - Run tests in src/test/
6161
# * check-stage1-T-$(target)-H-$(host) - Run cross-compiled-tests
62-
# * tidy-basic - show file / line stats
63-
# * tidy-errors - show the highest rustc error code
64-
# * tidy-features - show the status of language and lib features
62+
# * tidy - Basic style check, show highest rustc error code and
63+
# the status of language and lib features
6564
# * rustc-stage$(stage) - Only build up to a specific stage
6665
#
6766
# Then mix in some of these environment variables to harness the

branches/try/mk/crates.mk

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ TARGET_CRATES := libc std term \
5353
getopts collections test rand \
5454
core alloc \
5555
rustc_unicode rustc_bitflags \
56-
alloc_system alloc_jemalloc
56+
alloc_system alloc_jemalloc \
57+
panic_abort panic_unwind unwind
5758
RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_driver \
5859
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
5960
rustc_data_structures rustc_platform_intrinsics \
@@ -72,10 +73,18 @@ DEPS_libc := core
7273
DEPS_rand := core
7374
DEPS_rustc_bitflags := core
7475
DEPS_rustc_unicode := core
76+
DEPS_panic_abort := libc alloc
77+
DEPS_panic_unwind := libc alloc unwind
78+
DEPS_unwind := libc
79+
80+
# FIXME(stage0): change this to just `RUSTFLAGS_panic_abort := ...`
81+
RUSTFLAGS1_panic_abort := -C panic=abort
82+
RUSTFLAGS2_panic_abort := -C panic=abort
83+
RUSTFLAGS3_panic_abort := -C panic=abort
7584

7685
DEPS_std := core libc rand alloc collections rustc_unicode \
7786
native:backtrace \
78-
alloc_system
87+
alloc_system panic_abort panic_unwind unwind
7988
DEPS_arena := std
8089
DEPS_glob := std
8190
DEPS_flate := std native:miniz
@@ -148,6 +157,9 @@ ONLY_RLIB_rustc_unicode := 1
148157
ONLY_RLIB_rustc_bitflags := 1
149158
ONLY_RLIB_alloc_system := 1
150159
ONLY_RLIB_alloc_jemalloc := 1
160+
ONLY_RLIB_panic_unwind := 1
161+
ONLY_RLIB_panic_abort := 1
162+
ONLY_RLIB_unwind := 1
151163

152164
TARGET_SPECIFIC_alloc_jemalloc := 1
153165

branches/try/mk/tests.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ DEPS_collectionstest :=
2323
$(eval $(call RUST_CRATE,collectionstest))
2424

2525
TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system libc \
26-
alloc_jemalloc,$(TARGET_CRATES)) \
26+
alloc_jemalloc panic_unwind \
27+
panic_abort,$(TARGET_CRATES)) \
2728
collectionstest coretest
2829
TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \
2930
log rand rbml serialize syntax term test

branches/try/src/bootstrap/README.md

Lines changed: 136 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Bootstrapping Rust
1+
# rustbuild - Bootstrapping Rust
22

33
This is an in-progress README which is targeted at helping to explain how Rust
44
is bootstrapped and in general some of the technical details of the build
@@ -8,20 +8,64 @@ system.
88
> intended to be the primarily used one just yet. The makefiles are currently
99
> the ones that are still "guaranteed to work" as much as possible at least.
1010
11-
## Using the new build system
11+
## Using rustbuild
1212

1313
When configuring Rust via `./configure`, pass the following to enable building
1414
via this build system:
1515

1616
```
1717
./configure --enable-rustbuild
18+
make
1819
```
1920

20-
## ...
21+
Afterwards the `Makefile` which is generated will have a few commands like
22+
`make check`, `make tidy`, etc. For finer-grained control, the
23+
`bootstrap.py` entry point can be used:
24+
25+
```
26+
python src/bootstrap/bootstrap.py
27+
```
28+
29+
This accepts a number of options like `--stage` and `--step` which can configure
30+
what's actually being done.
31+
32+
## Configuring rustbuild
33+
34+
There are currently two primary methods for configuring the rustbuild build
35+
system. First, the `./configure` options serialized in `config.mk` will be
36+
parsed and read. That is, if any `./configure` options are passed, they'll be
37+
handled naturally.
38+
39+
Next, rustbuild offers a TOML-based configuration system with a `config.toml`
40+
file in the same location as `config.mk`. An example of this configuration can
41+
be found at `src/bootstrap/config.toml.example`, and the configuration file
42+
can also be passed as `--config path/to/config.toml` if the build system is
43+
being invoked manually (via the python script).
44+
45+
## Build stages
46+
47+
The rustbuild build system goes through a few phases to actually build the
48+
compiler. What actually happens when you invoke rustbuild is:
49+
50+
1. The entry point script, `src/bootstrap/bootstrap.py` is run. This script is
51+
responsible for downloading the stage0 compiler/Cargo binaries, and it then
52+
compiles the build system itself (this folder). Finally, it then invokes the
53+
actual `boostrap` binary build system.
54+
2. In Rust, `bootstrap` will slurp up all configuration, perform a number of
55+
sanity checks (compilers exist for example), and then start building the
56+
stage0 artifacts.
57+
3. The stage0 `cargo` downloaded earlier is used to build the standard library
58+
and the compiler, and then these binaries are then copied to the `stage1`
59+
directory. That compiler is then used to generate the stage1 artifacts which
60+
are then copied to the stage2 directory, and then finally the stage2
61+
artifacts are generated using that compiler.
62+
63+
The goal of each stage is to (a) leverage Cargo as much as possible and failing
64+
that (b) leverage Rust as much as possible!
2165

2266
## Directory Layout
2367

24-
This build system houses all output under the `target` directory, which looks
68+
This build system houses all output under the `build` directory, which looks
2569
like this:
2670

2771
```
@@ -42,6 +86,12 @@ build/
4286
debug/
4387
release/
4488
89+
# Output of the dist-related steps like dist-std, dist-rustc, and dist-docs
90+
dist/
91+
92+
# Temporary directory used for various input/output as part of various stages
93+
tmp/
94+
4595
# Each remaining directory is scoped by the "host" triple of compilation at
4696
# hand.
4797
x86_64-unknown-linux-gnu/
@@ -50,7 +100,8 @@ build/
50100
# folder is under. The exact layout here will likely depend on the platform,
51101
# and this is also built with CMake so the build system is also likely
52102
# different.
53-
compiler-rt/build/
103+
compiler-rt/
104+
build/
54105
55106
# Output folder for LLVM if it is compiled for this target
56107
llvm/
@@ -67,6 +118,17 @@ build/
67118
share/
68119
...
69120
121+
# Output folder for all documentation of this target. This is what's filled
122+
# in whenever the `doc` step is run.
123+
doc/
124+
125+
# Output for all compiletest-based test suites
126+
test/
127+
run-pass/
128+
compile-fail/
129+
debuginfo/
130+
...
131+
70132
# Location where the stage0 Cargo and Rust compiler are unpacked. This
71133
# directory is purely an extracted and overlaid tarball of these two (done
72134
# by the bootstrapy python script). In theory the build system does not
@@ -82,7 +144,9 @@ build/
82144
# invocation. The build system instruments calling Cargo in the right order
83145
# with the right variables to ensure these are filled in correctly.
84146
stageN-std/
147+
stageN-test/
85148
stageN-rustc/
149+
stageN-tools/
86150
87151
# This is a special case of the above directories, **not** filled in via
88152
# Cargo but rather the build system itself. The stage0 compiler already has
@@ -96,7 +160,7 @@ build/
96160
# Basically this directory is just a temporary artifact use to configure the
97161
# stage0 compiler to ensure that the libstd we just built is used to
98162
# compile the stage1 compiler.
99-
stage0-rustc/lib/
163+
stage0-sysroot/lib/
100164
101165
# These output directories are intended to be standalone working
102166
# implementations of the compiler (corresponding to each stage). The build
@@ -108,3 +172,69 @@ build/
108172
stage2/
109173
stage3/
110174
```
175+
176+
## Cargo projects
177+
178+
The current build is unfortunately not quite as simple as `cargo build` in a
179+
directory, but rather the compiler is split into three different Cargo projects:
180+
181+
* `src/rustc/std_shim` - a project which builds and compiles libstd
182+
* `src/rustc/test_shim` - a project which builds and compiles libtest
183+
* `src/rustc` - the actual compiler itself
184+
185+
Each "project" has a corresponding Cargo.lock file with all dependencies, and
186+
this means that building the compiler involves running Cargo three times. The
187+
structure here serves two goals:
188+
189+
1. Facilitating dependencies coming from crates.io. These dependencies don't
190+
depend on `std`, so libstd is a separate project compiled ahead of time
191+
before the actual compiler builds.
192+
2. Splitting "host artifacts" from "target artifacts". That is, when building
193+
code for an arbitrary target you don't need the entire compiler, but you'll
194+
end up needing libraries like libtest that depend on std but also want to use
195+
crates.io dependencies. Hence, libtest is split out as its own project that
196+
is sequenced after `std` but before `rustc`. This project is built for all
197+
targets.
198+
199+
There is some loss in build parallelism here because libtest can be compiled in
200+
parallel with a number of rustc artifacts, but in theory the loss isn't too bad!
201+
202+
## Build tools
203+
204+
We've actually got quite a few tools that we use in the compiler's build system
205+
and for testing. To organize these, each tool is a project in `src/tools` with a
206+
corresponding `Cargo.toml`. All tools are compiled with Cargo (currently having
207+
independent `Cargo.lock` files) and do not currently explicitly depend on the
208+
compiler or standard library. Compiling each tool is sequenced after the
209+
appropriate libstd/libtest/librustc compile above.
210+
211+
## Extending rustbuild
212+
213+
So you'd like to add a feature to the rustbuild build system or just fix a bug.
214+
Great! One of the major motivational factors for moving away from `make` is that
215+
Rust is in theory much easier to read, modify, and write. If you find anything
216+
excessively confusing, please open an issue on this and we'll try to get it
217+
documented or simplified pronto.
218+
219+
First up, you'll probably want to read over the documentation above as that'll
220+
give you a high level overview of what rustbuild is doing. You also probably
221+
want to play around a bit yourself by just getting it up and running before you
222+
dive too much into the actual build system itself.
223+
224+
After that, each module in rustbuild should have enough documentation to keep
225+
you up and running. Some general areas that you may be interested in modifying
226+
are:
227+
228+
* Adding a new build tool? Take a look at `build/step.rs` for examples of other
229+
tools, as well as `build/mod.rs`.
230+
* Adding a new compiler crate? Look no further! Adding crates can be done by
231+
adding a new directory with `Cargo.toml` followed by configuring all
232+
`Cargo.toml` files accordingly.
233+
* Adding a new dependency from crates.io? We're still working on that, so hold
234+
off on that for now.
235+
* Adding a new configuration option? Take a look at `build/config.rs` or perhaps
236+
`build/flags.rs` and then modify the build elsewhere to read that option.
237+
* Adding a sanity check? Take a look at `build/sanity.rs`.
238+
239+
If you have any questions feel free to reach out on `#rust-internals` on IRC or
240+
open an issue in the bug tracker!

branches/try/src/bootstrap/bootstrap.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,46 @@
1616
import subprocess
1717
import sys
1818
import tarfile
19+
import tempfile
20+
1921

2022
def get(url, path, verbose=False):
21-
print("downloading " + url)
2223
sha_url = url + ".sha256"
23-
sha_path = path + ".sha256"
24-
for _url, _path in ((url, path), (sha_url, sha_path)):
25-
# see http://serverfault.com/questions/301128/how-to-download
26-
if sys.platform == 'win32':
27-
run(["PowerShell.exe", "/nologo", "-Command",
28-
"(New-Object System.Net.WebClient)"
29-
".DownloadFile('{}', '{}')".format(_url, _path)],
30-
verbose=verbose)
31-
else:
32-
run(["curl", "-o", _path, _url], verbose=verbose)
24+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
25+
temp_path = temp_file.name
26+
with tempfile.NamedTemporaryFile(suffix=".sha256", delete=False) as sha_file:
27+
sha_path = sha_file.name
28+
29+
try:
30+
download(sha_path, sha_url, verbose)
31+
download(temp_path, url, verbose)
32+
verify(temp_path, sha_path, verbose)
33+
print("moving " + temp_path + " to " + path)
34+
shutil.move(temp_path, path)
35+
finally:
36+
delete_if_present(sha_path)
37+
delete_if_present(temp_path)
38+
39+
40+
def delete_if_present(path):
41+
if os.path.isfile(path):
42+
print("removing " + path)
43+
os.unlink(path)
44+
45+
46+
def download(path, url, verbose):
47+
print("downloading " + url + " to " + path)
48+
# see http://serverfault.com/questions/301128/how-to-download
49+
if sys.platform == 'win32':
50+
run(["PowerShell.exe", "/nologo", "-Command",
51+
"(New-Object System.Net.WebClient)"
52+
".DownloadFile('{}', '{}')".format(url, path)],
53+
verbose=verbose)
54+
else:
55+
run(["curl", "-o", path, url], verbose=verbose)
56+
57+
58+
def verify(path, sha_path, verbose):
3359
print("verifying " + path)
3460
with open(path, "rb") as f:
3561
found = hashlib.sha256(f.read()).hexdigest()
@@ -43,6 +69,7 @@ def get(url, path, verbose=False):
4369
raise RuntimeError(err)
4470
sys.exit(err)
4571

72+
4673
def unpack(tarball, dst, verbose=False, match=None):
4774
print("extracting " + tarball)
4875
fname = os.path.basename(tarball).replace(".tar.gz", "")

branches/try/src/bootstrap/build/cc.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! C-compiler probing and detection.
12+
//!
13+
//! This module will fill out the `cc` and `cxx` maps of `Build` by looking for
14+
//! C and C++ compilers for each target configured. A compiler is found through
15+
//! a number of vectors (in order of precedence)
16+
//!
17+
//! 1. Configuration via `target.$target.cc` in `config.toml`.
18+
//! 2. Configuration via `target.$target.android-ndk` in `config.toml`, if
19+
//! applicable
20+
//! 3. Special logic to probe on OpenBSD
21+
//! 4. The `CC_$target` environment variable.
22+
//! 5. The `CC` environment variable.
23+
//! 6. "cc"
24+
//!
25+
//! Some of this logic is implemented here, but much of it is farmed out to the
26+
//! `gcc` crate itself, so we end up having the same fallbacks as there.
27+
//! Similar logic is then used to find a C++ compiler, just some s/cc/c++/ is
28+
//! used.
29+
//!
30+
//! It is intended that after this module has run no C/C++ compiler will
31+
//! ever be probed for. Instead the compilers found here will be used for
32+
//! everything.
33+
1134
use std::process::Command;
1235

1336
use build_helper::{cc2ar, output};

0 commit comments

Comments
 (0)