Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete most of src/bootstrap/bin/rustc.rs #64316

Merged
merged 30 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f6c87ab
bootstrap: Add a helper for managing RUSTFLAGS
alexcrichton Aug 15, 2019
557e69b
bootstrap: Delete handling of `RUSTC_METADATA_SUFFIX`
alexcrichton Aug 15, 2019
4f35166
bootstrap: Move `RUSTC_BREAK_ON_ICE` out of shim
alexcrichton Aug 15, 2019
812117a
bootstrap: Move `-Zexternal-macro-backtrace` to builder
alexcrichton Aug 15, 2019
c36849a
bootstrap: Move `-Zdual-proc-macros` to `builder.rs`
alexcrichton Aug 15, 2019
d63e2de
bootstrap: Remove usage of `RUSTC_TARGET_LINKER`
alexcrichton Aug 15, 2019
04cb065
bootstrap: Remove need for RUSTC_SAVE_ANALYSIS
alexcrichton Aug 15, 2019
ac29809
bootstrap: Move `RUSTC_CRT_STATIC` to `builder.rs`
alexcrichton Aug 15, 2019
b82d86e
bootstrap: Handle target-specific cargo env vars
alexcrichton Sep 9, 2019
1bec962
bootstrap: Remove need for `RUSTC_RPATH` variable
alexcrichton Aug 15, 2019
3a648b6
Move handling of `-Dwarnings` to `builder.rs`
alexcrichton Sep 9, 2019
f8b19f2
Move handling of some warnings to `builder.rs`
alexcrichton Sep 9, 2019
22699d3
Move handling of internal lints to `build.rs`
alexcrichton Sep 9, 2019
2d6f3fe
Move handling of `codegen-units` to `builder.rs`
alexcrichton Sep 9, 2019
5abc4cd
Remove duplication of `RUSTC_DEBUGINFO_MAP` in rustc.rs
alexcrichton Sep 9, 2019
5cc6eb4
Move debuginfo level handling to `builder.rs`
alexcrichton Sep 9, 2019
0b6766d
Allow adding `RUSTFLAGS` after `Builder::cargo`
alexcrichton Sep 9, 2019
3d13f46
Move handling of `{MUSL,WASI}_ROOT` to `compile.rs`
alexcrichton Sep 9, 2019
a816fa1
Move handling of `RUSTC_PARALLEL_COMPILER` to `compile.rs`
alexcrichton Sep 9, 2019
b3f95f4
Move `--cfg bootstrap` out of `rustc.rs`
alexcrichton Sep 9, 2019
385470b
Move handling of `-Cprefer-dynamic` into `builder.rs`
alexcrichton Sep 9, 2019
1607871
Add some FIXME for future Cargo issues
alexcrichton Sep 9, 2019
9b34ef6
Stylistic changes
alexcrichton Sep 10, 2019
7b907de
Fix compiling libserialize tests
alexcrichton Sep 10, 2019
7342325
Add `#![deny(warnings)]` to internal tools
alexcrichton Sep 10, 2019
ff6a7c7
No need to remove target-specific RUSTFLAGS
alexcrichton Sep 11, 2019
d8253c1
Tweak libserialize allows
alexcrichton Sep 16, 2019
008ed18
rustbuild: Pass `-Zsave-analysis` during tests
alexcrichton Sep 17, 2019
b923306
Remove `--enable-extended` from cross dist builder
alexcrichton Sep 18, 2019
1a8897f
Fix rebase conflicts
alexcrichton Sep 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ version = "0.28.0"
dependencies = [
"curl",
"failure",
"http",
"percent-encoding 2.0.0",
"serde",
"serde_derive",
Expand Down
182 changes: 8 additions & 174 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,14 @@
//! never get replaced.

use std::env;
use std::ffi::OsString;
use std::io;
use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;
use std::time::Instant;

fn main() {
let mut args = env::args_os().skip(1).collect::<Vec<_>>();

// Append metadata suffix for internal crates. See the corresponding entry
// in bootstrap/lib.rs for details.
if let Ok(s) = env::var("RUSTC_METADATA_SUFFIX") {
for i in 1..args.len() {
// Dirty code for borrowing issues
let mut new = None;
if let Some(current_as_str) = args[i].to_str() {
if (&*args[i - 1] == "-C" && current_as_str.starts_with("metadata")) ||
current_as_str.starts_with("-Cmetadata") {
new = Some(format!("{}-{}", current_as_str, s));
}
}
if let Some(new) = new { args[i] = new.into(); }
}
}
let args = env::args_os().skip(1).collect::<Vec<_>>();

// Detect whether or not we're a build script depending on whether --target
// is passed (a bit janky...)
Expand Down Expand Up @@ -93,92 +76,19 @@ fn main() {
}
}

// Non-zero stages must all be treated uniformly to avoid problems when attempting to uplift
// compiler libraries and such from stage 1 to 2.
//
// FIXME: the fact that core here is excluded is due to core_arch from our stdarch submodule
// being broken on the beta compiler with bootstrap passed, so this is a temporary workaround
// (we've just snapped, so there are no cfg(bootstrap) related annotations in core).
if stage == "0" {
if crate_name != Some("core") {
cmd.arg("--cfg").arg("bootstrap");
} else {
// NOTE(eddyb) see FIXME above, except now we need annotations again in core.
cmd.arg("--cfg").arg("boostrap_stdarch_ignore_this");
}
}

// Print backtrace in case of ICE
if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() {
cmd.env("RUST_BACKTRACE", "1");
}

cmd.env("RUSTC_BREAK_ON_ICE", "1");

if let Ok(debuginfo_level) = env::var("RUSTC_DEBUGINFO_LEVEL") {
cmd.arg(format!("-Cdebuginfo={}", debuginfo_level));
}

if env::var_os("RUSTC_EXTERNAL_TOOL").is_none() {
// When extending this list, add the new lints to the RUSTFLAGS of the
// build_bootstrap function of src/bootstrap/bootstrap.py as well as
// some code doesn't go through this `rustc` wrapper.
cmd.arg("-Wrust_2018_idioms");
cmd.arg("-Wunused_lifetimes");
if use_internal_lints(crate_name) {
cmd.arg("-Zunstable-options");
cmd.arg("-Wrustc::internal");
}
if env::var_os("RUSTC_DENY_WARNINGS").is_some() {
cmd.arg("-Dwarnings");
}
}

if let Some(target) = target {
if target.is_some() {
// The stage0 compiler has a special sysroot distinct from what we
// actually downloaded, so we just always pass the `--sysroot` option,
// unless one is already set.
if !args.iter().any(|arg| arg == "--sysroot") {
cmd.arg("--sysroot").arg(&sysroot);
}

cmd.arg("-Zexternal-macro-backtrace");

// Link crates to the proc macro crate for the target, but use a host proc macro crate
// to actually run the macros
if env::var_os("RUST_DUAL_PROC_MACROS").is_some() {
cmd.arg("-Zdual-proc-macros");
}

// When we build Rust dylibs they're all intended for intermediate
// usage, so make sure we pass the -Cprefer-dynamic flag instead of
// linking all deps statically into the dylib.
if env::var_os("RUSTC_NO_PREFER_DYNAMIC").is_none() {
cmd.arg("-Cprefer-dynamic");
}

// Help the libc crate compile by assisting it in finding various
// sysroot native libraries.
if let Some(s) = env::var_os("MUSL_ROOT") {
if target.contains("musl") {
let mut root = OsString::from("native=");
root.push(&s);
root.push("/lib");
cmd.arg("-L").arg(&root);
}
}
if let Some(s) = env::var_os("WASI_ROOT") {
let mut root = OsString::from("native=");
root.push(&s);
root.push("/lib/wasm32-wasi");
cmd.arg("-L").arg(&root);
}

// Override linker if necessary.
if let Ok(target_linker) = env::var("RUSTC_TARGET_LINKER") {
cmd.arg(format!("-Clinker={}", target_linker));
}

// If we're compiling specifically the `panic_abort` crate then we pass
// the `-C panic=abort` option. Note that we do not do this for any
// other crate intentionally as this is the only crate for now that we
Expand All @@ -205,82 +115,18 @@ fn main() {

// The compiler builtins are pretty sensitive to symbols referenced in
// libcore and such, so we never compile them with debug assertions.
//
// FIXME(rust-lang/cargo#7253) we should be doing this in `builder.rs`
// with env vars instead of doing it here in this script.
if crate_name == Some("compiler_builtins") {
cmd.arg("-C").arg("debug-assertions=no");
} else {
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
}

if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
cmd.arg("-C").arg(format!("codegen-units={}", s));
}

// Emit save-analysis info.
if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {
cmd.arg("-Zsave-analysis");
cmd.env("RUST_SAVE_ANALYSIS_CONFIG",
"{\"output_file\": null,\"full_docs\": false,\
\"pub_only\": true,\"reachable_only\": false,\
\"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}");
}

// Dealing with rpath here is a little special, so let's go into some
// detail. First off, `-rpath` is a linker option on Unix platforms
// which adds to the runtime dynamic loader path when looking for
// dynamic libraries. We use this by default on Unix platforms to ensure
// that our nightlies behave the same on Windows, that is they work out
// of the box. This can be disabled, of course, but basically that's why
// we're gated on RUSTC_RPATH here.
//
// Ok, so the astute might be wondering "why isn't `-C rpath` used
// here?" and that is indeed a good question to task. This codegen
// option is the compiler's current interface to generating an rpath.
// Unfortunately it doesn't quite suffice for us. The flag currently
// takes no value as an argument, so the compiler calculates what it
// should pass to the linker as `-rpath`. This unfortunately is based on
// the **compile time** directory structure which when building with
// Cargo will be very different than the runtime directory structure.
//
// All that's a really long winded way of saying that if we use
// `-Crpath` then the executables generated have the wrong rpath of
// something like `$ORIGIN/deps` when in fact the way we distribute
// rustc requires the rpath to be `$ORIGIN/../lib`.
//
// So, all in all, to set up the correct rpath we pass the linker
// argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool
// to change a flag in a binary?
if env::var("RUSTC_RPATH") == Ok("true".to_string()) {
let rpath = if target.contains("apple") {

// Note that we need to take one extra step on macOS to also pass
// `-Wl,-instal_name,@rpath/...` to get things to work right. To
// do that we pass a weird flag to the compiler to get it to do
// so. Note that this is definitely a hack, and we should likely
// flesh out rpath support more fully in the future.
cmd.arg("-Z").arg("osx-rpath-install-name");
Some("-Wl,-rpath,@loader_path/../lib")
} else if !target.contains("windows") &&
!target.contains("wasm32") &&
!target.contains("fuchsia") {
Some("-Wl,-rpath,$ORIGIN/../lib")
} else {
None
};
if let Some(rpath) = rpath {
cmd.arg("-C").arg(format!("link-args={}", rpath));
}
}

if let Ok(s) = env::var("RUSTC_CRT_STATIC") {
alexcrichton marked this conversation as resolved.
Show resolved Hide resolved
if s == "true" {
cmd.arg("-C").arg("target-feature=+crt-static");
}
if s == "false" {
cmd.arg("-C").arg("target-feature=-crt-static");
}
}
} else {
// FIXME(rust-lang/cargo#5754) we shouldn't be using special env vars
// here, but rather Cargo should know what flags to pass rustc itself.

// Override linker if necessary.
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
cmd.arg(format!("-Clinker={}", host_linker));
Expand Down Expand Up @@ -308,10 +154,6 @@ fn main() {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}

if env::var_os("RUSTC_PARALLEL_COMPILER").is_some() {
cmd.arg("--cfg").arg("parallel_compiler");
}

if verbose > 1 {
eprintln!(
"rustc command: {:?}={:?} {:?}",
Expand Down Expand Up @@ -362,14 +204,6 @@ fn main() {
std::process::exit(code);
}

// Rustc crates for which internal lints are in effect.
fn use_internal_lints(crate_name: Option<&str>) -> bool {
crate_name.map_or(false, |crate_name| {
crate_name.starts_with("rustc") || crate_name.starts_with("syntax") ||
["arena", "fmt_macros"].contains(&crate_name)
})
}

#[cfg(unix)]
fn exec_cmd(cmd: &mut Command) -> io::Result<i32> {
use std::os::unix::process::CommandExt;
Expand Down
Loading