Skip to content

Commit c872f47

Browse files
committed
Merge remote-tracking branch 'origin/master' into gen
2 parents b44e51c + ba65645 commit c872f47

File tree

101 files changed

+3016
-1439
lines changed

Some content is hidden

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

101 files changed

+3016
-1439
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Windows build triples are:
135135
- `i686-pc-windows-msvc`
136136
- `x86_64-pc-windows-msvc`
137137

138-
The build triple can be specified by either specifying `--build=ABI` when
138+
The build triple can be specified by either specifying `--build=<triple>` when
139139
invoking `x.py` commands, or by copying the `config.toml` file (as described
140140
in Building From Source), and modifying the `build` option under the `[build]`
141141
section.

RELEASES.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Stabilized APIs
9292
Cargo
9393
-----
9494
- [Cargo API token location moved from `~/.cargo/config` to
95-
`~/cargo/credentials`.][cargo/3978]
95+
`~/.cargo/credentials`.][cargo/3978]
9696
- [Cargo will now build `main.rs` binaries that are in sub-directories of
9797
`src/bin`.][cargo/4214] ie. Having `src/bin/server/main.rs` and
9898
`src/bin/client/main.rs` generates `target/debug/server` and `target/debug/client`
@@ -172,7 +172,6 @@ Compatibility Notes
172172
[`slice::sort_unstable`]: https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable
173173
[`ste::from_boxed_utf8_unchecked`]: https://doc.rust-lang.org/std/str/fn.from_boxed_utf8_unchecked.html
174174
[`str::as_bytes_mut`]: https://doc.rust-lang.org/std/primitive.str.html#method.as_bytes_mut
175-
[`str::as_bytes_mut`]: https://doc.rust-lang.org/std/primitive.str.html#method.as_bytes_mut
176175
[`str::from_utf8_mut`]: https://doc.rust-lang.org/std/str/fn.from_utf8_mut.html
177176
[`str::from_utf8_unchecked_mut`]: https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked_mut.html
178177
[`str::get_mut`]: https://doc.rust-lang.org/std/primitive.str.html#method.get_mut
@@ -898,6 +897,9 @@ Compatibility Notes
898897
* [Ctrl-Z returns from `Stdin.read()` when reading from the console on
899898
Windows][38274]
900899
* [Clean up semantics of `self` in an import list][38313]
900+
* Reimplemented lifetime elision. This change was almost entirely compatible
901+
with existing code, but it did close a number of small bugs and loopholes,
902+
as well as being more accepting in some other [cases][41105].
901903

902904
[37057]: https://github.com/rust-lang/rust/pull/37057
903905
[37761]: https://github.com/rust-lang/rust/pull/37761
@@ -932,6 +934,7 @@ Compatibility Notes
932934
[39048]: https://github.com/rust-lang/rust/pull/39048
933935
[39282]: https://github.com/rust-lang/rust/pull/39282
934936
[39379]: https://github.com/rust-lang/rust/pull/39379
937+
[41105]: https://github.com/rust-lang/rust/issues/41105
935938
[`<*const T>::wrapping_offset`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_offset
936939
[`<*mut T>::wrapping_offset`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_offset
937940
[`Duration::checked_add`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.checked_add

config.toml.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@
292292
# build native code.
293293
#android-ndk = "/path/to/ndk"
294294

295+
# Force static or dynamic linkage of the standard library for this target. If
296+
# this target is a host for rustc, this will also affect the linkage of the
297+
# compiler itself. This is useful for building rustc on targets that normally
298+
# only use static libraries. If unset, the target's default linkage is used.
299+
#crt-static = false
300+
295301
# The root location of the MUSL installation directory. The library directory
296302
# will also need to contain libunwind.a for an unwinding implementation. Note
297303
# that this option only makes sense for MUSL targets that produce statically

src/bootstrap/README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,19 @@ The script accepts commands, flags, and arguments to determine what to do:
7373

7474
## Configuring rustbuild
7575

76-
There are currently two primary methods for configuring the rustbuild build
77-
system. First, the `./configure` options serialized in `config.mk` will be
78-
parsed and read. That is, if any `./configure` options are passed, they'll be
79-
handled naturally.
76+
There are currently two methods for configuring the rustbuild build system.
8077

81-
Next, rustbuild offers a TOML-based configuration system with a `config.toml`
78+
First, rustbuild offers a TOML-based configuration system with a `config.toml`
8279
file in the same location as `config.mk`. An example of this configuration can
83-
be found at `config.toml.example`, and the configuration file
84-
can also be passed as `--config path/to/config.toml` if the build system is
85-
being invoked manually (via the python script).
80+
be found at `config.toml.example`, and the configuration file can also be passed
81+
as `--config path/to/config.toml` if the build system is being invoked manually
82+
(via the python script).
83+
84+
Next, the `./configure` options serialized in `config.mk` will be
85+
parsed and read. That is, if any `./configure` options are passed, they'll be
86+
handled naturally. `./configure` should almost never be used for local
87+
installations, and is primarily useful for CI. Prefer to customize behavior
88+
using `config.toml`.
8689

8790
Finally, rustbuild makes use of the [gcc-rs crate] which has [its own
8891
method][env-vars] of configuring C compilers and C flags via environment
@@ -310,17 +313,18 @@ After that, each module in rustbuild should have enough documentation to keep
310313
you up and running. Some general areas that you may be interested in modifying
311314
are:
312315

313-
* Adding a new build tool? Take a look at `bootstrap/step.rs` for examples of
316+
* Adding a new build tool? Take a look at `bootstrap/tool.rs` for examples of
314317
other tools.
315318
* Adding a new compiler crate? Look no further! Adding crates can be done by
316319
adding a new directory with `Cargo.toml` followed by configuring all
317320
`Cargo.toml` files accordingly.
318-
* Adding a new dependency from crates.io? We're still working on that, so hold
319-
off on that for now.
320-
* Adding a new configuration option? Take a look at `bootstrap/config.rs` or
321-
perhaps `bootstrap/flags.rs` and then modify the build elsewhere to read that
322-
option.
321+
* Adding a new dependency from crates.io? This should just work inside the
322+
compiler artifacts stage (everything other than libtest and libstd).
323+
* Adding a new configuration option? You'll want to modify `bootstrap/flags.rs`
324+
for command line flags and then `bootstrap/config.rs` to copy the flags to the
325+
`Config` struct.
323326
* Adding a sanity check? Take a look at `bootstrap/sanity.rs`.
324327

325-
If you have any questions feel free to reach out on `#rust-internals` on IRC or
326-
open an issue in the bug tracker!
328+
If you have any questions feel free to reach out on `#rust-infra` on IRC or ask on
329+
internals.rust-lang.org. When you encounter bugs, please file issues on the
330+
rust-lang/rust issue tracker.

src/bootstrap/bin/rustc.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,13 @@ fn main() {
237237
}
238238
}
239239

240-
if target.contains("pc-windows-msvc") {
241-
cmd.arg("-Z").arg("unstable-options");
242-
cmd.arg("-C").arg("target-feature=+crt-static");
240+
if let Ok(s) = env::var("RUSTC_CRT_STATIC") {
241+
if s == "true" {
242+
cmd.arg("-C").arg("target-feature=+crt-static");
243+
}
244+
if s == "false" {
245+
cmd.arg("-C").arg("target-feature=-crt-static");
246+
}
243247
}
244248

245249
// Force all crates compiled by this compiler to (a) be unstable and (b)

src/bootstrap/builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ impl<'a> Builder<'a> {
503503
cargo.env("RUSTC_METADATA_SUFFIX", "rustc");
504504
}
505505

506+
if let Some(x) = self.crt_static(target) {
507+
cargo.env("RUSTC_CRT_STATIC", x.to_string());
508+
}
509+
506510
// Enable usage of unstable features
507511
cargo.env("RUSTC_BOOTSTRAP", "1");
508512
self.add_rust_test_threads(&mut cargo);

src/bootstrap/compile.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ impl Step for Std {
7777
target,
7878
});
7979
println!("Uplifting stage1 std ({} -> {})", from.host, target);
80+
81+
// Even if we're not building std this stage, the new sysroot must
82+
// still contain the musl startup objects.
83+
if target.contains("musl") && !target.contains("mips") {
84+
let libdir = builder.sysroot_libdir(compiler, target);
85+
copy_musl_third_party_objects(build, target, &libdir);
86+
}
87+
8088
builder.ensure(StdLink {
8189
compiler: from,
8290
target_compiler: compiler,
@@ -89,6 +97,11 @@ impl Step for Std {
8997
println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
9098
&compiler.host, target);
9199

100+
if target.contains("musl") && !target.contains("mips") {
101+
let libdir = builder.sysroot_libdir(compiler, target);
102+
copy_musl_third_party_objects(build, target, &libdir);
103+
}
104+
92105
let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
93106
build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
94107
let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "build");
@@ -105,6 +118,20 @@ impl Step for Std {
105118
}
106119
}
107120

121+
/// Copies the crt(1,i,n).o startup objects
122+
///
123+
/// Since musl supports fully static linking, we can cross link for it even
124+
/// with a glibc-targeting toolchain, given we have the appropriate startup
125+
/// files. As those shipped with glibc won't work, copy the ones provided by
126+
/// musl so we have them on linux-gnu hosts.
127+
fn copy_musl_third_party_objects(build: &Build,
128+
target: Interned<String>,
129+
into: &Path) {
130+
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
131+
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
132+
}
133+
}
134+
108135
/// Configure cargo to compile the standard library, adding appropriate env vars
109136
/// and such.
110137
pub fn std_cargo(build: &Build,
@@ -189,10 +216,6 @@ impl Step for StdLink {
189216
let libdir = builder.sysroot_libdir(target_compiler, target);
190217
add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
191218

192-
if target.contains("musl") && !target.contains("mips") {
193-
copy_musl_third_party_objects(build, target, &libdir);
194-
}
195-
196219
if build.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
197220
// The sanitizers are only built in stage1 or above, so the dylibs will
198221
// be missing in stage0 and causes panic. See the `std()` function above
@@ -208,15 +231,6 @@ impl Step for StdLink {
208231
}
209232
}
210233

211-
/// Copies the crt(1,i,n).o startup objects
212-
///
213-
/// Only required for musl targets that statically link to libc
214-
fn copy_musl_third_party_objects(build: &Build, target: Interned<String>, into: &Path) {
215-
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
216-
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
217-
}
218-
}
219-
220234
fn copy_apple_sanitizer_dylibs(native_dir: &Path, platform: &str, into: &Path) {
221235
for &sanitizer in &["asan", "tsan"] {
222236
let filename = format!("libclang_rt.{}_{}_dynamic.dylib", sanitizer, platform);

src/bootstrap/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub struct Target {
143143
pub cc: Option<PathBuf>,
144144
pub cxx: Option<PathBuf>,
145145
pub ndk: Option<PathBuf>,
146+
pub crt_static: Option<bool>,
146147
pub musl_root: Option<PathBuf>,
147148
pub qemu_rootfs: Option<PathBuf>,
148149
}
@@ -275,6 +276,7 @@ struct TomlTarget {
275276
cc: Option<String>,
276277
cxx: Option<String>,
277278
android_ndk: Option<String>,
279+
crt_static: Option<bool>,
278280
musl_root: Option<String>,
279281
qemu_rootfs: Option<String>,
280282
}
@@ -446,6 +448,7 @@ impl Config {
446448
}
447449
target.cxx = cfg.cxx.clone().map(PathBuf::from);
448450
target.cc = cfg.cc.clone().map(PathBuf::from);
451+
target.crt_static = cfg.crt_static.clone();
449452
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
450453
target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
451454

src/bootstrap/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,16 @@ impl Build {
656656
base
657657
}
658658

659+
/// Returns if this target should statically link the C runtime, if specified
660+
fn crt_static(&self, target: Interned<String>) -> Option<bool> {
661+
if target.contains("pc-windows-msvc") {
662+
Some(true)
663+
} else {
664+
self.config.target_config.get(&target)
665+
.and_then(|t| t.crt_static)
666+
}
667+
}
668+
659669
/// Returns the "musl root" for this `target`, if defined
660670
fn musl_root(&self, target: Interned<String>) -> Option<&Path> {
661671
self.config.target_config.get(&target)

src/bootstrap/sanity.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,15 @@ pub fn check(build: &mut Build) {
151151
panic!("the iOS target is only supported on macOS");
152152
}
153153

154-
// Make sure musl-root is valid if specified
154+
// Make sure musl-root is valid
155155
if target.contains("musl") && !target.contains("mips") {
156+
// If this is a native target (host is also musl) and no musl-root is given,
157+
// fall back to the system toolchain in /usr before giving up
158+
if build.musl_root(*target).is_none() && build.config.build == *target {
159+
let target = build.config.target_config.entry(target.clone())
160+
.or_insert(Default::default());
161+
target.musl_root = Some("/usr".into());
162+
}
156163
match build.musl_root(*target) {
157164
Some(root) => {
158165
if fs::metadata(root.join("lib/libc.a")).is_err() {

0 commit comments

Comments
 (0)