2015-11-19 15:20:12 -08:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
//! Implementation of rustbuild, the Rust build system.
|
2016-05-02 15:16:15 -07:00
|
|
|
//!
|
2016-07-05 21:58:20 -07:00
|
|
|
//! This module, and its descendants, are the implementation of the Rust build
|
|
|
|
//! system. Most of this build system is backed by Cargo but the outer layer
|
|
|
|
//! here serves as the ability to orchestrate calling Cargo, sequencing Cargo
|
2016-11-16 12:31:19 -08:00
|
|
|
//! builds, building artifacts like LLVM, etc. The goals of rustbuild are:
|
2016-07-05 21:58:20 -07:00
|
|
|
//!
|
2016-11-16 12:31:19 -08:00
|
|
|
//! * To be an easily understandable, easily extensible, and maintainable build
|
|
|
|
//! system.
|
|
|
|
//! * Leverage standard tools in the Rust ecosystem to build the compiler, aka
|
|
|
|
//! crates.io and Cargo.
|
|
|
|
//! * A standard interface to build across all platforms, including MSVC
|
|
|
|
//!
|
|
|
|
//! ## Architecture
|
|
|
|
//!
|
2017-07-03 18:20:46 -06:00
|
|
|
//! The build system defers most of the complicated logic managing invocations
|
|
|
|
//! of rustc and rustdoc to Cargo itself. However, moving through various stages
|
|
|
|
//! and copying artifacts is still necessary for it to do. Each time rustbuild
|
|
|
|
//! is invoked, it will iterate through the list of predefined steps and execute
|
|
|
|
//! each serially in turn if it matches the paths passed or is a default rule.
|
|
|
|
//! For each step rustbuild relies on the step internally being incremental and
|
2016-11-16 12:31:19 -08:00
|
|
|
//! parallel. Note, though, that the `-j` parameter to rustbuild gets forwarded
|
|
|
|
//! to appropriate test harnesses and such.
|
|
|
|
//!
|
|
|
|
//! Most of the "meaty" steps that matter are backed by Cargo, which does indeed
|
|
|
|
//! have its own parallelism and incremental management. Later steps, like
|
|
|
|
//! tests, aren't incremental and simply run the entire suite currently.
|
2017-07-03 18:20:46 -06:00
|
|
|
//! However, compiletest itself tries to avoid running tests when the artifacts
|
|
|
|
//! that are involved (mainly the compiler) haven't changed.
|
2016-11-16 12:31:19 -08:00
|
|
|
//!
|
|
|
|
//! When you execute `x.py build`, the steps which are executed are:
|
|
|
|
//!
|
|
|
|
//! * First, the python script is run. This will automatically download the
|
2017-07-03 18:20:46 -06:00
|
|
|
//! stage0 rustc and cargo according to `src/stage0.txt`, or use the cached
|
2016-11-16 12:31:19 -08:00
|
|
|
//! versions if they're available. These are then used to compile rustbuild
|
|
|
|
//! itself (using Cargo). Finally, control is then transferred to rustbuild.
|
|
|
|
//!
|
|
|
|
//! * Rustbuild takes over, performs sanity checks, probes the environment,
|
2017-07-03 18:20:46 -06:00
|
|
|
//! reads configuration, and starts executing steps as it reads the command
|
|
|
|
//! line arguments (paths) or going through the default rules.
|
|
|
|
//!
|
|
|
|
//! The build output will be something like the following:
|
|
|
|
//!
|
|
|
|
//! Building stage0 std artifacts
|
|
|
|
//! Copying stage0 std
|
|
|
|
//! Building stage0 test artifacts
|
|
|
|
//! Copying stage0 test
|
|
|
|
//! Building stage0 compiler artifacts
|
|
|
|
//! Copying stage0 rustc
|
|
|
|
//! Assembling stage1 compiler
|
|
|
|
//! Building stage1 std artifacts
|
|
|
|
//! Copying stage1 std
|
|
|
|
//! Building stage1 test artifacts
|
|
|
|
//! Copying stage1 test
|
|
|
|
//! Building stage1 compiler artifacts
|
|
|
|
//! Copying stage1 rustc
|
|
|
|
//! Assembling stage2 compiler
|
|
|
|
//! Uplifting stage1 std
|
|
|
|
//! Uplifting stage1 test
|
|
|
|
//! Uplifting stage1 rustc
|
|
|
|
//!
|
|
|
|
//! Let's disect that a little:
|
|
|
|
//!
|
|
|
|
//! ## Building stage0 {std,test,compiler} artifacts
|
|
|
|
//!
|
|
|
|
//! These steps use the provided (downloaded, usually) compiler to compile the
|
|
|
|
//! local Rust source into libraries we can use.
|
|
|
|
//!
|
|
|
|
//! ## Copying stage0 {std,test,rustc}
|
|
|
|
//!
|
|
|
|
//! This copies the build output from Cargo into
|
|
|
|
//! `build/$HOST/stage0-sysroot/lib/rustlib/$ARCH/lib`. FIXME: This step's
|
|
|
|
//! documentation should be expanded -- the information already here may be
|
|
|
|
//! incorrect.
|
|
|
|
//!
|
|
|
|
//! ## Assembling stage1 compiler
|
|
|
|
//!
|
|
|
|
//! This copies the libraries we built in "building stage0 ... artifacts" into
|
|
|
|
//! the stage1 compiler's lib directory. These are the host libraries that the
|
|
|
|
//! compiler itself uses to run. These aren't actually used by artifacts the new
|
|
|
|
//! compiler generates. This step also copies the rustc and rustdoc binaries we
|
|
|
|
//! generated into build/$HOST/stage/bin.
|
|
|
|
//!
|
|
|
|
//! The stage1/bin/rustc is a fully functional compiler, but it doesn't yet have
|
|
|
|
//! any libraries to link built binaries or libraries to. The next 3 steps will
|
|
|
|
//! provide those libraries for it; they are mostly equivalent to constructing
|
|
|
|
//! the stage1/bin compiler so we don't go through them individually.
|
|
|
|
//!
|
2017-07-20 17:51:07 -06:00
|
|
|
//! ## Uplifting stage1 {std,test,rustc}
|
2017-07-03 18:20:46 -06:00
|
|
|
//!
|
|
|
|
//! This step copies the libraries from the stage1 compiler sysroot into the
|
|
|
|
//! stage2 compiler. This is done to avoid rebuilding the compiler; libraries
|
|
|
|
//! we'd build in this step should be identical (in function, if not necessarily
|
|
|
|
//! identical on disk) so there's no need to recompile the compiler again. Note
|
|
|
|
//! that if you want to, you can enable the full-bootstrap option to change this
|
|
|
|
//! behavior.
|
2016-11-16 12:31:19 -08:00
|
|
|
//!
|
|
|
|
//! Each step is driven by a separate Cargo project and rustbuild orchestrates
|
|
|
|
//! copying files between steps and otherwise preparing for Cargo to run.
|
|
|
|
//!
|
|
|
|
//! ## Further information
|
|
|
|
//!
|
|
|
|
//! More documentation can be found in each respective module below, and you can
|
|
|
|
//! also check out the `src/bootstrap/README.md` file for more information.
|
2016-07-05 21:58:20 -07:00
|
|
|
|
2018-02-15 18:31:17 -07:00
|
|
|
#![deny(warnings)]
|
Change Step to be invoked with a path when in default mode.
Previously, a Step would be able to tell on its own when it was invoked
"by-default" (that is, `./x.py test` was called instead of `./x.py test
some/path`). This commit replaces that functionality, invoking each Step
with each of the paths it has specified as "should be invoked by."
For example, if a step calls `path("src/tools/cargo")` and
`path("src/doc/cargo")` then it's make_run will be called twice, with
"src/tools/cargo" and "src/doc/cargo." This makes it so that default
handling logic is in builder, instead of spread across various Steps.
However, this meant that some Step specifications needed to be updated,
since for example `rustdoc` can be built by `./x.py build
src/librustdoc` or `./x.py build src/tools/rustdoc`. A `PathSet`
abstraction is added that handles this: now, each Step can not only list
`path(...)` but also `paths(&[a, b, ...])` which will make it so that we
don't invoke it with each of the individual paths, instead invoking it
with the first path in the list (though this shouldn't be depended on).
Future work likely consists of implementing a better/easier way for a
given Step to work with "any" crate in-tree, especially those that want
to run tests, build, or check crates in the std, test, or rustc crate
trees. Currently this is rather painful to do as most of the logic is
duplicated across should_run and make_run. It seems likely this can be
abstracted away into builder somehow.
2018-02-11 09:51:58 -07:00
|
|
|
#![feature(core_intrinsics)]
|
2018-02-09 18:53:41 +01:00
|
|
|
#![feature(slice_concat_ext)]
|
2016-12-20 09:38:13 -08:00
|
|
|
|
2017-02-01 00:27:51 +03:00
|
|
|
#[macro_use]
|
2016-07-05 21:58:20 -07:00
|
|
|
extern crate build_helper;
|
2017-07-05 10:46:41 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
2017-07-13 18:48:44 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2017-07-05 10:46:41 -06:00
|
|
|
extern crate serde_json;
|
2016-07-05 21:58:20 -07:00
|
|
|
extern crate cmake;
|
|
|
|
extern crate filetime;
|
2017-09-22 21:34:27 -07:00
|
|
|
extern crate cc;
|
2016-07-05 21:58:20 -07:00
|
|
|
extern crate getopts;
|
|
|
|
extern crate num_cpus;
|
|
|
|
extern crate toml;
|
2018-02-05 11:39:54 +03:00
|
|
|
extern crate time;
|
2016-05-02 15:16:15 -07:00
|
|
|
|
Add tests to rustbuild
In order to run tests, previous commits have cfg'd out various parts of
rustbuild. Generally speaking, these are filesystem-related operations
and process-spawning related parts. Then, rustbuild is run "as normal"
and the various steps that where run are retrieved from the cache and
checked against the expected results.
Note that this means that the current implementation primarily tests
"what" we build, but doesn't actually test that what we build *will*
build. In other words, it doesn't do any form of dependency verification
for any crate. This is possible to implement, but is considered future
work.
This implementation strives to cfg out as little code as possible; it
also does not currently test anywhere near all of rustbuild. The current
tests are also not checked for "correctness," rather, they simply
represent what we do as of this commit, which may be wrong.
Test cases are drawn from the old implementation of rustbuild, though
the expected results may vary.
2018-03-10 07:03:06 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate pretty_assertions;
|
|
|
|
|
2017-03-23 22:57:29 +01:00
|
|
|
#[cfg(unix)]
|
|
|
|
extern crate libc;
|
|
|
|
|
2018-01-12 12:53:51 -08:00
|
|
|
use std::cell::{RefCell, Cell};
|
2017-07-05 10:46:41 -06:00
|
|
|
use std::collections::{HashSet, HashMap};
|
2015-11-19 15:20:12 -08:00
|
|
|
use std::env;
|
2016-07-05 21:58:20 -07:00
|
|
|
use std::fs::{self, File};
|
2017-03-06 06:55:24 -08:00
|
|
|
use std::io::Read;
|
2017-05-13 14:21:35 +09:00
|
|
|
use std::path::{PathBuf, Path};
|
2017-09-18 21:21:24 +02:00
|
|
|
use std::process::{self, Command};
|
2017-07-29 22:12:53 -06:00
|
|
|
use std::slice;
|
2016-07-05 21:58:20 -07:00
|
|
|
|
2017-12-07 05:06:48 +08:00
|
|
|
use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime};
|
2016-07-05 21:58:20 -07:00
|
|
|
|
2017-07-05 11:21:33 -06:00
|
|
|
use util::{exe, libdir, OutputFolder, CiEnv};
|
2016-07-05 21:58:20 -07:00
|
|
|
|
2017-09-22 21:34:27 -07:00
|
|
|
mod cc_detect;
|
2016-07-05 21:58:20 -07:00
|
|
|
mod channel;
|
|
|
|
mod check;
|
2018-01-15 10:44:00 -07:00
|
|
|
mod test;
|
2016-07-05 21:58:20 -07:00
|
|
|
mod clean;
|
|
|
|
mod compile;
|
2016-10-21 13:18:09 -07:00
|
|
|
mod metadata;
|
2016-07-05 21:58:20 -07:00
|
|
|
mod config;
|
|
|
|
mod dist;
|
|
|
|
mod doc;
|
|
|
|
mod flags;
|
2016-08-12 23:38:17 -07:00
|
|
|
mod install;
|
2016-07-05 21:58:20 -07:00
|
|
|
mod native;
|
|
|
|
mod sanity;
|
|
|
|
pub mod util;
|
2017-07-05 10:20:20 -06:00
|
|
|
mod builder;
|
2017-07-05 10:46:41 -06:00
|
|
|
mod cache;
|
|
|
|
mod tool;
|
2017-08-30 18:59:26 +02:00
|
|
|
mod toolstate;
|
2016-07-05 21:58:20 -07:00
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
mod job;
|
|
|
|
|
2017-03-23 22:57:29 +01:00
|
|
|
#[cfg(unix)]
|
2016-07-05 21:58:20 -07:00
|
|
|
mod job {
|
2017-03-23 22:57:29 +01:00
|
|
|
use libc;
|
|
|
|
|
|
|
|
pub unsafe fn setup(build: &mut ::Build) {
|
|
|
|
if build.config.low_priority {
|
2017-05-18 22:24:34 -05:00
|
|
|
libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
|
2017-03-23 22:57:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(any(unix, windows)))]
|
2016-07-05 21:58:20 -07:00
|
|
|
mod job {
|
2017-03-23 22:57:29 +01:00
|
|
|
pub unsafe fn setup(_build: &mut ::Build) {
|
|
|
|
}
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub use config::Config;
|
2017-07-29 22:12:53 -06:00
|
|
|
use flags::Subcommand;
|
2017-07-13 18:48:44 -06:00
|
|
|
use cache::{Interned, INTERNER};
|
2017-11-30 18:18:47 +08:00
|
|
|
use toolstate::ToolState;
|
2016-07-05 21:58:20 -07:00
|
|
|
|
|
|
|
/// A structure representing a Rust compiler.
|
|
|
|
///
|
|
|
|
/// Each compiler has a `stage` that it is associated with and a `host` that
|
|
|
|
/// corresponds to the platform the compiler runs on. This structure is used as
|
|
|
|
/// a parameter to many methods below.
|
2018-03-10 07:01:06 -07:00
|
|
|
#[derive(Eq, PartialOrd, Ord, PartialEq, Clone, Copy, Hash, Debug)]
|
2017-07-13 18:48:44 -06:00
|
|
|
pub struct Compiler {
|
2016-07-05 21:58:20 -07:00
|
|
|
stage: u32,
|
2017-07-13 18:48:44 -06:00
|
|
|
host: Interned<String>,
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Global configuration for the build system.
|
|
|
|
///
|
|
|
|
/// This structure transitively contains all configuration for the build system.
|
|
|
|
/// All filesystem-encoded configuration is in `config`, all flags are in
|
|
|
|
/// `flags`, and then parsed or probed information is listed in the keys below.
|
|
|
|
///
|
|
|
|
/// This structure is a parameter of almost all methods in the build system,
|
|
|
|
/// although most functions are implemented as free functions rather than
|
|
|
|
/// methods specifically on this structure itself (to make it easier to
|
|
|
|
/// organize).
|
|
|
|
pub struct Build {
|
|
|
|
// User-specified configuration via config.toml
|
|
|
|
config: Config,
|
|
|
|
|
|
|
|
// Derived properties from the above two configurations
|
|
|
|
src: PathBuf,
|
|
|
|
out: PathBuf,
|
2017-02-15 15:57:06 -08:00
|
|
|
rust_info: channel::GitInfo,
|
|
|
|
cargo_info: channel::GitInfo,
|
2017-04-10 11:22:38 -07:00
|
|
|
rls_info: channel::GitInfo,
|
2017-11-10 15:09:39 +13:00
|
|
|
rustfmt_info: channel::GitInfo,
|
2016-07-14 19:39:55 +02:00
|
|
|
local_rebuild: bool,
|
2017-06-27 13:37:24 -06:00
|
|
|
fail_fast: bool,
|
2018-02-17 15:45:39 +01:00
|
|
|
doc_tests: bool,
|
2017-06-27 13:49:21 -06:00
|
|
|
verbosity: usize,
|
2016-07-05 21:58:20 -07:00
|
|
|
|
2017-06-27 15:52:46 -06:00
|
|
|
// Targets for which to build.
|
2017-07-13 18:48:44 -06:00
|
|
|
build: Interned<String>,
|
|
|
|
hosts: Vec<Interned<String>>,
|
|
|
|
targets: Vec<Interned<String>>,
|
2017-06-27 15:52:46 -06:00
|
|
|
|
2017-06-27 13:32:04 -06:00
|
|
|
// Stage 0 (downloaded) compiler and cargo or their local rust equivalents.
|
|
|
|
initial_rustc: PathBuf,
|
|
|
|
initial_cargo: PathBuf,
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
// Probed tools at runtime
|
|
|
|
lldb_version: Option<String>,
|
|
|
|
lldb_python_dir: Option<String>,
|
|
|
|
|
|
|
|
// Runtime state filled in later on
|
2017-10-10 23:06:22 +03:00
|
|
|
// C/C++ compilers and archiver for all targets
|
|
|
|
cc: HashMap<Interned<String>, cc::Tool>,
|
2017-09-22 21:34:27 -07:00
|
|
|
cxx: HashMap<Interned<String>, cc::Tool>,
|
2017-10-10 23:06:22 +03:00
|
|
|
ar: HashMap<Interned<String>, PathBuf>,
|
|
|
|
// Misc
|
2017-07-13 18:48:44 -06:00
|
|
|
crates: HashMap<Interned<String>, Crate>,
|
2016-11-16 12:31:19 -08:00
|
|
|
is_sudo: bool,
|
2017-05-18 00:33:20 +08:00
|
|
|
ci_env: CiEnv,
|
2017-09-18 21:21:24 +02:00
|
|
|
delayed_failures: RefCell<Vec<String>>,
|
2018-01-12 12:53:51 -08:00
|
|
|
prerelease_version: Cell<Option<u32>>,
|
2018-03-15 10:58:02 -07:00
|
|
|
tool_artifacts: RefCell<HashMap<
|
|
|
|
Interned<String>,
|
|
|
|
HashMap<String, (&'static str, PathBuf, Vec<String>)>
|
|
|
|
>>,
|
2016-10-21 13:18:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Crate {
|
2017-07-13 18:48:44 -06:00
|
|
|
name: Interned<String>,
|
2017-02-15 15:57:06 -08:00
|
|
|
version: String,
|
2017-07-13 18:48:44 -06:00
|
|
|
deps: Vec<Interned<String>>,
|
2016-10-21 13:18:09 -07:00
|
|
|
path: PathBuf,
|
|
|
|
doc_step: String,
|
|
|
|
build_step: String,
|
|
|
|
test_step: String,
|
2016-11-25 22:13:59 +01:00
|
|
|
bench_step: String,
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
Change Step to be invoked with a path when in default mode.
Previously, a Step would be able to tell on its own when it was invoked
"by-default" (that is, `./x.py test` was called instead of `./x.py test
some/path`). This commit replaces that functionality, invoking each Step
with each of the paths it has specified as "should be invoked by."
For example, if a step calls `path("src/tools/cargo")` and
`path("src/doc/cargo")` then it's make_run will be called twice, with
"src/tools/cargo" and "src/doc/cargo." This makes it so that default
handling logic is in builder, instead of spread across various Steps.
However, this meant that some Step specifications needed to be updated,
since for example `rustdoc` can be built by `./x.py build
src/librustdoc` or `./x.py build src/tools/rustdoc`. A `PathSet`
abstraction is added that handles this: now, each Step can not only list
`path(...)` but also `paths(&[a, b, ...])` which will make it so that we
don't invoke it with each of the individual paths, instead invoking it
with the first path in the list (though this shouldn't be depended on).
Future work likely consists of implementing a better/easier way for a
given Step to work with "any" crate in-tree, especially those that want
to run tests, build, or check crates in the std, test, or rustc crate
trees. Currently this is rather painful to do as most of the logic is
duplicated across should_run and make_run. It seems likely this can be
abstracted away into builder somehow.
2018-02-11 09:51:58 -07:00
|
|
|
impl Crate {
|
|
|
|
fn is_local(&self, build: &Build) -> bool {
|
|
|
|
self.path.starts_with(&build.config.src) &&
|
|
|
|
!self.path.to_string_lossy().ends_with("_shim")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn local_path(&self, build: &Build) -> PathBuf {
|
|
|
|
assert!(self.is_local(build));
|
|
|
|
self.path.strip_prefix(&build.config.src).unwrap().into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
/// The various "modes" of invoking Cargo.
|
|
|
|
///
|
|
|
|
/// These entries currently correspond to the various output directories of the
|
|
|
|
/// build system, with each mod generating output in a different directory.
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
|
2016-07-05 21:58:20 -07:00
|
|
|
pub enum Mode {
|
2017-06-27 13:24:37 -06:00
|
|
|
/// Build the standard library, placing output in the "stageN-std" directory.
|
2016-07-05 21:58:20 -07:00
|
|
|
Libstd,
|
|
|
|
|
2017-06-27 13:24:37 -06:00
|
|
|
/// Build libtest, placing output in the "stageN-test" directory.
|
2016-07-05 21:58:20 -07:00
|
|
|
Libtest,
|
|
|
|
|
2017-06-27 13:24:37 -06:00
|
|
|
/// Build librustc and compiler libraries, placing output in the "stageN-rustc" directory.
|
2016-07-05 21:58:20 -07:00
|
|
|
Librustc,
|
|
|
|
|
2017-06-27 13:24:37 -06:00
|
|
|
/// Build some tool, placing output in the "stageN-tools" directory.
|
2016-07-05 21:58:20 -07:00
|
|
|
Tool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Build {
|
|
|
|
/// Creates a new set of build configuration from the `flags` on the command
|
|
|
|
/// line and the filesystem `config`.
|
|
|
|
///
|
|
|
|
/// By default all build output will be placed in the current directory.
|
2017-07-29 22:12:53 -06:00
|
|
|
pub fn new(config: Config) -> Build {
|
|
|
|
let src = config.src.clone();
|
2018-03-09 18:14:35 -07:00
|
|
|
let out = config.out.clone();
|
2016-07-05 21:58:20 -07:00
|
|
|
|
2016-11-16 12:31:19 -08:00
|
|
|
let is_sudo = match env::var_os("SUDO_USER") {
|
|
|
|
Some(sudo_user) => {
|
|
|
|
match env::var_os("USER") {
|
|
|
|
Some(user) => user != sudo_user,
|
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => false,
|
|
|
|
};
|
2017-08-03 10:53:56 -06:00
|
|
|
let rust_info = channel::GitInfo::new(&config, &src);
|
|
|
|
let cargo_info = channel::GitInfo::new(&config, &src.join("src/tools/cargo"));
|
|
|
|
let rls_info = channel::GitInfo::new(&config, &src.join("src/tools/rls"));
|
2017-11-10 15:09:39 +13:00
|
|
|
let rustfmt_info = channel::GitInfo::new(&config, &src.join("src/tools/rustfmt"));
|
2016-11-16 12:31:19 -08:00
|
|
|
|
2018-03-09 19:19:59 -07:00
|
|
|
let mut build = Build {
|
2017-06-27 13:32:04 -06:00
|
|
|
initial_rustc: config.initial_rustc.clone(),
|
|
|
|
initial_cargo: config.initial_cargo.clone(),
|
|
|
|
local_rebuild: config.local_rebuild,
|
2017-07-29 22:12:53 -06:00
|
|
|
fail_fast: config.cmd.fail_fast(),
|
2018-02-17 15:45:39 +01:00
|
|
|
doc_tests: config.cmd.doc_tests(),
|
2017-07-29 22:12:53 -06:00
|
|
|
verbosity: config.verbose,
|
2017-06-27 13:32:04 -06:00
|
|
|
|
2017-07-29 22:12:53 -06:00
|
|
|
build: config.build,
|
|
|
|
hosts: config.hosts.clone(),
|
|
|
|
targets: config.targets.clone(),
|
2017-06-27 15:52:46 -06:00
|
|
|
|
2017-08-06 22:54:09 -07:00
|
|
|
config,
|
|
|
|
src,
|
|
|
|
out,
|
2016-07-05 21:58:20 -07:00
|
|
|
|
2017-08-06 22:54:09 -07:00
|
|
|
rust_info,
|
|
|
|
cargo_info,
|
|
|
|
rls_info,
|
2017-11-10 15:09:39 +13:00
|
|
|
rustfmt_info,
|
2016-07-05 21:58:20 -07:00
|
|
|
cc: HashMap::new(),
|
|
|
|
cxx: HashMap::new(),
|
2017-10-10 23:06:22 +03:00
|
|
|
ar: HashMap::new(),
|
2016-10-21 13:18:09 -07:00
|
|
|
crates: HashMap::new(),
|
2016-07-05 21:58:20 -07:00
|
|
|
lldb_version: None,
|
|
|
|
lldb_python_dir: None,
|
2017-08-06 22:54:09 -07:00
|
|
|
is_sudo,
|
2017-05-18 00:33:20 +08:00
|
|
|
ci_env: CiEnv::current(),
|
2017-09-18 21:21:24 +02:00
|
|
|
delayed_failures: RefCell::new(Vec::new()),
|
2018-01-12 12:53:51 -08:00
|
|
|
prerelease_version: Cell::new(None),
|
2018-03-15 10:58:02 -07:00
|
|
|
tool_artifacts: Default::default(),
|
2018-03-09 19:19:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
build.verbose("finding compilers");
|
|
|
|
cc_detect::find(&mut build);
|
|
|
|
build.verbose("running sanity check");
|
|
|
|
sanity::check(&mut build);
|
2018-03-15 17:29:53 -06:00
|
|
|
|
|
|
|
// If local-rust is the same major.minor as the current version, then force a
|
|
|
|
// local-rebuild
|
|
|
|
let local_version_verbose = output(
|
|
|
|
Command::new(&build.initial_rustc).arg("--version").arg("--verbose"));
|
|
|
|
let local_release = local_version_verbose
|
|
|
|
.lines().filter(|x| x.starts_with("release:"))
|
|
|
|
.next().unwrap().trim_left_matches("release:").trim();
|
|
|
|
let my_version = channel::CFG_RELEASE_NUM;
|
|
|
|
if local_release.split('.').take(2).eq(my_version.split('.').take(2)) {
|
|
|
|
build.verbose(&format!("auto-detected local-rebuild {}", local_release));
|
|
|
|
build.local_rebuild = true;
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
2018-03-15 17:29:53 -06:00
|
|
|
|
2018-03-09 19:19:59 -07:00
|
|
|
build.verbose("learning about cargo");
|
|
|
|
metadata::build(&mut build);
|
|
|
|
|
|
|
|
build
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
2017-07-29 22:12:53 -06:00
|
|
|
pub fn build_triple(&self) -> &[Interned<String>] {
|
|
|
|
unsafe {
|
|
|
|
slice::from_raw_parts(&self.build, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
/// Executes the entire build, as configured by the flags and configuration.
|
|
|
|
pub fn build(&mut self) {
|
|
|
|
unsafe {
|
2017-03-23 22:57:29 +01:00
|
|
|
job::setup(self);
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 18:14:19 +01:00
|
|
|
if let Subcommand::Clean { all } = self.config.cmd {
|
|
|
|
return clean::clean(self, all);
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
2018-03-09 19:05:06 -07:00
|
|
|
let builder = builder::Builder::new(&self);
|
|
|
|
if let Some(path) = builder.paths.get(0) {
|
|
|
|
if path == Path::new("nonexistent/path/to/trigger/cargo/metadata") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
builder.execute_cli();
|
2017-09-18 21:21:24 +02:00
|
|
|
|
|
|
|
// Check for postponed failures from `test --no-fail-fast`.
|
|
|
|
let failures = self.delayed_failures.borrow();
|
|
|
|
if failures.len() > 0 {
|
|
|
|
println!("\n{} command(s) did not execute successfully:\n", failures.len());
|
|
|
|
for failure in failures.iter() {
|
|
|
|
println!(" - {}\n", failure);
|
|
|
|
}
|
|
|
|
process::exit(1);
|
|
|
|
}
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Clear out `dir` if `input` is newer.
|
|
|
|
///
|
|
|
|
/// After this executes, it will also ensure that `dir` exists.
|
2017-10-16 11:40:47 -06:00
|
|
|
fn clear_if_dirty(&self, dir: &Path, input: &Path) -> bool {
|
2016-07-05 21:58:20 -07:00
|
|
|
let stamp = dir.join(".stamp");
|
2017-10-16 11:40:47 -06:00
|
|
|
let mut cleared = false;
|
2016-07-05 21:58:20 -07:00
|
|
|
if mtime(&stamp) < mtime(input) {
|
|
|
|
self.verbose(&format!("Dirty - {}", dir.display()));
|
|
|
|
let _ = fs::remove_dir_all(dir);
|
2017-10-16 11:40:47 -06:00
|
|
|
cleared = true;
|
2016-09-12 21:46:35 -07:00
|
|
|
} else if stamp.exists() {
|
2017-10-16 11:40:47 -06:00
|
|
|
return cleared;
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
t!(fs::create_dir_all(dir));
|
|
|
|
t!(File::create(stamp));
|
2017-10-16 11:40:47 -06:00
|
|
|
cleared
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the space-separated set of activated features for the standard
|
|
|
|
/// library.
|
|
|
|
fn std_features(&self) -> String {
|
2017-02-15 17:00:41 -05:00
|
|
|
let mut features = "panic-unwind".to_string();
|
2016-12-29 23:28:11 -05:00
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
if self.config.debug_jemalloc {
|
|
|
|
features.push_str(" debug-jemalloc");
|
|
|
|
}
|
|
|
|
if self.config.use_jemalloc {
|
|
|
|
features.push_str(" jemalloc");
|
|
|
|
}
|
2016-07-26 15:21:25 -05:00
|
|
|
if self.config.backtrace {
|
|
|
|
features.push_str(" backtrace");
|
|
|
|
}
|
2017-02-13 09:57:50 +00:00
|
|
|
if self.config.profiler {
|
|
|
|
features.push_str(" profiler");
|
|
|
|
}
|
2018-01-11 17:51:49 +00:00
|
|
|
if self.config.wasm_syscall {
|
|
|
|
features.push_str(" wasm_syscall");
|
|
|
|
}
|
2017-06-27 09:51:26 -06:00
|
|
|
features
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the space-separated set of activated features for the compiler.
|
|
|
|
fn rustc_features(&self) -> String {
|
|
|
|
let mut features = String::new();
|
|
|
|
if self.config.use_jemalloc {
|
|
|
|
features.push_str(" jemalloc");
|
|
|
|
}
|
2017-06-27 09:51:26 -06:00
|
|
|
features
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Component directory that Cargo will produce output into (e.g.
|
|
|
|
/// release/debug)
|
|
|
|
fn cargo_dir(&self) -> &'static str {
|
|
|
|
if self.config.rust_optimize {"release"} else {"debug"}
|
|
|
|
}
|
|
|
|
|
2017-10-16 11:40:47 -06:00
|
|
|
fn tools_dir(&self, compiler: Compiler) -> PathBuf {
|
|
|
|
let out = self.out.join(&*compiler.host).join(format!("stage{}-tools-bin", compiler.stage));
|
|
|
|
t!(fs::create_dir_all(&out));
|
|
|
|
out
|
|
|
|
}
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
/// Returns the root directory for all output generated in a particular
|
|
|
|
/// stage when running with a particular host compiler.
|
|
|
|
///
|
|
|
|
/// The mode indicates what the root directory is for.
|
2017-07-05 10:46:41 -06:00
|
|
|
fn stage_out(&self, compiler: Compiler, mode: Mode) -> PathBuf {
|
2016-07-05 21:58:20 -07:00
|
|
|
let suffix = match mode {
|
|
|
|
Mode::Libstd => "-std",
|
|
|
|
Mode::Libtest => "-test",
|
|
|
|
Mode::Tool => "-tools",
|
|
|
|
Mode::Librustc => "-rustc",
|
|
|
|
};
|
2017-07-13 18:48:44 -06:00
|
|
|
self.out.join(&*compiler.host)
|
2016-07-05 21:58:20 -07:00
|
|
|
.join(format!("stage{}{}", compiler.stage, suffix))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the root output directory for all Cargo output in a given stage,
|
2017-08-15 21:45:21 +02:00
|
|
|
/// running a particular compiler, whether or not we're building the
|
2016-07-05 21:58:20 -07:00
|
|
|
/// standard library, and targeting the specified architecture.
|
|
|
|
fn cargo_out(&self,
|
2017-07-05 10:46:41 -06:00
|
|
|
compiler: Compiler,
|
2016-07-05 21:58:20 -07:00
|
|
|
mode: Mode,
|
2017-07-13 18:48:44 -06:00
|
|
|
target: Interned<String>) -> PathBuf {
|
|
|
|
self.stage_out(compiler, mode).join(&*target).join(self.cargo_dir())
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Root output directory for LLVM compiled for `target`
|
|
|
|
///
|
|
|
|
/// Note that if LLVM is configured externally then the directory returned
|
|
|
|
/// will likely be empty.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn llvm_out(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
self.out.join(&*target).join("llvm")
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
rustc: Split Emscripten to a separate codegen backend
This commit introduces a separately compiled backend for Emscripten, avoiding
compiling the `JSBackend` target in the main LLVM codegen backend. This builds
on the foundation provided by #47671 to create a new codegen backend dedicated
solely to Emscripten, removing the `JSBackend` of the main codegen backend in
the process.
A new field was added to each target for this commit which specifies the backend
to use for translation, the default being `llvm` which is the main backend that
we use. The Emscripten targets specify an `emscripten` backend instead of the
main `llvm` one.
There's a whole bunch of consequences of this change, but I'll try to enumerate
them here:
* A *second* LLVM submodule was added in this commit. The main LLVM submodule
will soon start to drift from the Emscripten submodule, but currently they're
both at the same revision.
* Logic was added to rustbuild to *not* build the Emscripten backend by default.
This is gated behind a `--enable-emscripten` flag to the configure script. By
default users should neither check out the emscripten submodule nor compile
it.
* The `init_repo.sh` script was updated to fetch the Emscripten submodule from
GitHub the same way we do the main LLVM submodule (a tarball fetch).
* The Emscripten backend, turned off by default, is still turned on for a number
of targets on CI. We'll only be shipping an Emscripten backend with Tier 1
platforms, though. All cross-compiled platforms will not be receiving an
Emscripten backend yet.
This commit means that when you download the `rustc` package in Rustup for Tier
1 platforms you'll be receiving two trans backends, one for Emscripten and one
that's the general LLVM backend. If you never compile for Emscripten you'll
never use the Emscripten backend, so we may update this one day to only download
the Emscripten backend when you add the Emscripten target. For now though it's
just an extra 10MB gzip'd.
Closes #46819
2018-01-24 08:22:34 -08:00
|
|
|
fn emscripten_llvm_out(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
self.out.join(&*target).join("llvm-emscripten")
|
|
|
|
}
|
|
|
|
|
rust: Import LLD for linking wasm objects
This commit imports the LLD project from LLVM to serve as the default linker for
the `wasm32-unknown-unknown` target. The `binaryen` submoule is consequently
removed along with "binaryen linker" support in rustc.
Moving to LLD brings with it a number of benefits for wasm code:
* LLD is itself an actual linker, so there's no need to compile all wasm code
with LTO any more. As a result builds should be *much* speedier as LTO is no
longer forcibly enabled for all builds of the wasm target.
* LLD is quickly becoming an "official solution" for linking wasm code together.
This, I believe at least, is intended to be the main supported linker for
native code and wasm moving forward. Picking up support early on should help
ensure that we can help LLD identify bugs and otherwise prove that it works
great for all our use cases!
* Improvements to the wasm toolchain are currently primarily focused around LLVM
and LLD (from what I can tell at least), so it's in general much better to be
on this bandwagon for bugfixes and new features.
* Historical "hacks" like `wasm-gc` will soon no longer be necessary, LLD
will [natively implement][gc] `--gc-sections` (better than `wasm-gc`!) which
means a postprocessor is no longer needed to show off Rust's "small wasm
binary size".
LLD is added in a pretty standard way to rustc right now. A new rustbuild target
was defined for building LLD, and this is executed when a compiler's sysroot is
being assembled. LLD is compiled against the LLVM that we've got in tree, which
means we're currently on the `release_60` branch, but this may get upgraded in
the near future!
LLD is placed into rustc's sysroot in a `bin` directory. This is similar to
where `gcc.exe` can be found on Windows. This directory is automatically added
to `PATH` whenever rustc executes the linker, allowing us to define a `WasmLd`
linker which implements the interface that `wasm-ld`, LLD's frontend, expects.
Like Emscripten the LLD target is currently only enabled for Tier 1 platforms,
notably OSX/Windows/Linux, and will need to be installed manually for compiling
to wasm on other platforms. LLD is by default turned off in rustbuild, and
requires a `config.toml` option to be enabled to turn it on.
Finally the unstable `#![wasm_import_memory]` attribute was also removed as LLD
has a native option for controlling this.
[gc]: https://reviews.llvm.org/D42511
2017-08-26 18:30:12 -07:00
|
|
|
fn lld_out(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
self.out.join(&*target).join("lld")
|
|
|
|
}
|
|
|
|
|
2016-10-21 13:18:09 -07:00
|
|
|
/// Output directory for all documentation for a target
|
2017-07-13 18:48:44 -06:00
|
|
|
fn doc_out(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
self.out.join(&*target).join("doc")
|
2016-10-21 13:18:09 -07:00
|
|
|
}
|
|
|
|
|
2018-03-20 02:06:38 +00:00
|
|
|
/// Output directory for all documentation for a target
|
|
|
|
fn compiler_doc_out(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
self.out.join(&*target).join("compiler-doc")
|
|
|
|
}
|
|
|
|
|
2017-06-12 21:35:47 +02:00
|
|
|
/// Output directory for some generated md crate documentation for a target (temporary)
|
2017-07-13 18:48:44 -06:00
|
|
|
fn md_doc_out(&self, target: Interned<String>) -> Interned<PathBuf> {
|
|
|
|
INTERNER.intern_path(self.out.join(&*target).join("md-doc"))
|
2017-06-12 21:35:47 +02:00
|
|
|
}
|
|
|
|
|
2017-03-01 15:34:54 -08:00
|
|
|
/// Output directory for all crate documentation for a target (temporary)
|
|
|
|
///
|
|
|
|
/// The artifacts here are then copied into `doc_out` above.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn crate_doc_out(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
self.out.join(&*target).join("crate-docs")
|
2017-03-01 15:34:54 -08:00
|
|
|
}
|
|
|
|
|
2016-08-06 15:54:28 +10:00
|
|
|
/// Returns true if no custom `llvm-config` is set for the specified target.
|
|
|
|
///
|
|
|
|
/// If no custom `llvm-config` was specified then Rust's llvm will be used.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn is_rust_llvm(&self, target: Interned<String>) -> bool {
|
|
|
|
match self.config.target_config.get(&target) {
|
2016-08-06 15:54:28 +10:00
|
|
|
Some(ref c) => c.llvm_config.is_none(),
|
|
|
|
None => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
/// Returns the path to `FileCheck` binary for the specified target
|
2017-07-13 18:48:44 -06:00
|
|
|
fn llvm_filecheck(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
let target_config = self.config.target_config.get(&target);
|
2016-07-05 21:58:20 -07:00
|
|
|
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
|
2016-12-20 19:48:14 +09:00
|
|
|
let llvm_bindir = output(Command::new(s).arg("--bindir"));
|
2017-07-13 18:48:44 -06:00
|
|
|
Path::new(llvm_bindir.trim()).join(exe("FileCheck", &*target))
|
2016-07-05 21:58:20 -07:00
|
|
|
} else {
|
2017-07-13 18:48:44 -06:00
|
|
|
let base = self.llvm_out(self.config.build).join("build");
|
|
|
|
let exe = exe("FileCheck", &*target);
|
2017-02-27 23:39:16 +03:00
|
|
|
if !self.config.ninja && self.config.build.contains("msvc") {
|
2016-07-05 21:58:20 -07:00
|
|
|
base.join("Release/bin").join(exe)
|
|
|
|
} else {
|
|
|
|
base.join("bin").join(exe)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 01:57:30 +03:00
|
|
|
/// Directory for libraries built from C/C++ code and shared between stages.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn native_dir(&self, target: Interned<String>) -> PathBuf {
|
|
|
|
self.out.join(&*target).join("native")
|
2017-01-27 01:57:30 +03:00
|
|
|
}
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
/// Root output directory for rust_test_helpers library compiled for
|
|
|
|
/// `target`
|
2017-07-13 18:48:44 -06:00
|
|
|
fn test_helpers_out(&self, target: Interned<String>) -> PathBuf {
|
2017-01-27 01:57:30 +03:00
|
|
|
self.native_dir(target).join("rust-test-helpers")
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
2016-11-16 12:31:19 -08:00
|
|
|
/// Adds the `RUST_TEST_THREADS` env var if necessary
|
|
|
|
fn add_rust_test_threads(&self, cmd: &mut Command) {
|
|
|
|
if env::var_os("RUST_TEST_THREADS").is_none() {
|
|
|
|
cmd.env("RUST_TEST_THREADS", self.jobs().to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
/// Returns the libdir of the snapshot compiler.
|
|
|
|
fn rustc_snapshot_libdir(&self) -> PathBuf {
|
2017-06-27 13:32:04 -06:00
|
|
|
self.initial_rustc.parent().unwrap().parent().unwrap()
|
2016-07-05 21:58:20 -07:00
|
|
|
.join(libdir(&self.config.build))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Runs a command, printing out nice contextual information if it fails.
|
|
|
|
fn run(&self, cmd: &mut Command) {
|
2018-03-09 19:23:35 -07:00
|
|
|
if cfg!(test) { return; }
|
2017-12-07 05:06:48 +08:00
|
|
|
self.verbose(&format!("running: {:?}", cmd));
|
|
|
|
run_silent(cmd)
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:57:06 -08:00
|
|
|
/// Runs a command, printing out nice contextual information if it fails.
|
|
|
|
fn run_quiet(&self, cmd: &mut Command) {
|
2018-03-09 19:23:35 -07:00
|
|
|
if cfg!(test) { return; }
|
2017-02-15 15:57:06 -08:00
|
|
|
self.verbose(&format!("running: {:?}", cmd));
|
2017-12-07 05:06:48 +08:00
|
|
|
run_suppressed(cmd)
|
2017-02-15 15:57:06 -08:00
|
|
|
}
|
|
|
|
|
2017-12-07 05:06:48 +08:00
|
|
|
/// Runs a command, printing out nice contextual information if it fails.
|
|
|
|
/// Exits if the command failed to execute at all, otherwise returns its
|
|
|
|
/// `status.success()`.
|
|
|
|
fn try_run(&self, cmd: &mut Command) -> bool {
|
2018-03-09 19:23:35 -07:00
|
|
|
if cfg!(test) { return true; }
|
2017-06-02 09:27:44 -07:00
|
|
|
self.verbose(&format!("running: {:?}", cmd));
|
2017-12-07 05:06:48 +08:00
|
|
|
try_run_silent(cmd)
|
2017-06-02 09:27:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Runs a command, printing out nice contextual information if it fails.
|
|
|
|
/// Exits if the command failed to execute at all, otherwise returns its
|
|
|
|
/// `status.success()`.
|
|
|
|
fn try_run_quiet(&self, cmd: &mut Command) -> bool {
|
2018-03-09 19:23:35 -07:00
|
|
|
if cfg!(test) { return true; }
|
2017-06-02 09:27:44 -07:00
|
|
|
self.verbose(&format!("running: {:?}", cmd));
|
2017-12-07 05:06:48 +08:00
|
|
|
try_run_suppressed(cmd)
|
2017-06-02 09:27:44 -07:00
|
|
|
}
|
|
|
|
|
2017-06-27 13:49:21 -06:00
|
|
|
pub fn is_verbose(&self) -> bool {
|
|
|
|
self.verbosity > 0
|
|
|
|
}
|
|
|
|
|
2016-07-05 21:58:20 -07:00
|
|
|
/// Prints a message if this build is configured in verbose mode.
|
|
|
|
fn verbose(&self, msg: &str) {
|
2017-06-27 13:49:21 -06:00
|
|
|
if self.is_verbose() {
|
2016-07-05 21:58:20 -07:00
|
|
|
println!("{}", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of parallel jobs that have been configured for this
|
|
|
|
/// build.
|
|
|
|
fn jobs(&self) -> u32 {
|
2017-07-29 22:12:53 -06:00
|
|
|
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the path to the C compiler for the target specified.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn cc(&self, target: Interned<String>) -> &Path {
|
2017-10-10 23:06:22 +03:00
|
|
|
self.cc[&target].path()
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a list of flags to pass to the C compiler for the target
|
|
|
|
/// specified.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn cflags(&self, target: Interned<String>) -> Vec<String> {
|
2016-07-05 21:58:20 -07:00
|
|
|
// Filter out -O and /O (the optimization flags) that we picked up from
|
2017-09-22 21:34:27 -07:00
|
|
|
// cc-rs because the build scripts will determine that for themselves.
|
2017-10-10 23:06:22 +03:00
|
|
|
let mut base = self.cc[&target].args().iter()
|
2016-07-05 21:58:20 -07:00
|
|
|
.map(|s| s.to_string_lossy().into_owned())
|
|
|
|
.filter(|s| !s.starts_with("-O") && !s.starts_with("/O"))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
2017-03-12 14:13:35 -04:00
|
|
|
// If we're compiling on macOS then we add a few unconditional flags
|
2016-07-05 21:58:20 -07:00
|
|
|
// indicating that we want libc++ (more filled out than libstdc++) and
|
|
|
|
// we want to compile for 10.7. This way we can ensure that
|
|
|
|
// LLVM/jemalloc/etc are all properly compiled.
|
|
|
|
if target.contains("apple-darwin") {
|
|
|
|
base.push("-stdlib=libc++".into());
|
|
|
|
}
|
2017-04-17 10:24:33 +02:00
|
|
|
|
|
|
|
// Work around an apparently bad MinGW / GCC optimization,
|
|
|
|
// See: http://lists.llvm.org/pipermail/cfe-dev/2016-December/051980.html
|
|
|
|
// See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78936
|
2017-07-13 18:48:44 -06:00
|
|
|
if &*target == "i686-pc-windows-gnu" {
|
2017-04-17 10:24:33 +02:00
|
|
|
base.push("-fno-omit-frame-pointer".into());
|
|
|
|
}
|
2017-06-27 09:51:26 -06:00
|
|
|
base
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the path to the `ar` archive utility for the target specified.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn ar(&self, target: Interned<String>) -> Option<&Path> {
|
2017-10-10 23:06:22 +03:00
|
|
|
self.ar.get(&target).map(|p| &**p)
|
|
|
|
}
|
|
|
|
|
2017-06-22 11:51:32 -07:00
|
|
|
/// Returns the path to the C++ compiler for the target specified.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn cxx(&self, target: Interned<String>) -> Result<&Path, String> {
|
|
|
|
match self.cxx.get(&target) {
|
2017-06-22 11:51:32 -07:00
|
|
|
Some(p) => Ok(p.path()),
|
|
|
|
None => Err(format!(
|
|
|
|
"target `{}` is not configured as a host, only as a target",
|
|
|
|
target))
|
2016-09-12 22:43:48 -07:00
|
|
|
}
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
2018-02-10 12:22:57 +01:00
|
|
|
/// Returns the path to the linker for the given target if it needs to be overridden.
|
2017-10-15 21:39:16 +03:00
|
|
|
fn linker(&self, target: Interned<String>) -> Option<&Path> {
|
2017-10-16 03:20:01 +03:00
|
|
|
if let Some(linker) = self.config.target_config.get(&target)
|
|
|
|
.and_then(|c| c.linker.as_ref()) {
|
|
|
|
Some(linker)
|
2017-10-15 21:39:16 +03:00
|
|
|
} else if target != self.config.build &&
|
rust: Import LLD for linking wasm objects
This commit imports the LLD project from LLVM to serve as the default linker for
the `wasm32-unknown-unknown` target. The `binaryen` submoule is consequently
removed along with "binaryen linker" support in rustc.
Moving to LLD brings with it a number of benefits for wasm code:
* LLD is itself an actual linker, so there's no need to compile all wasm code
with LTO any more. As a result builds should be *much* speedier as LTO is no
longer forcibly enabled for all builds of the wasm target.
* LLD is quickly becoming an "official solution" for linking wasm code together.
This, I believe at least, is intended to be the main supported linker for
native code and wasm moving forward. Picking up support early on should help
ensure that we can help LLD identify bugs and otherwise prove that it works
great for all our use cases!
* Improvements to the wasm toolchain are currently primarily focused around LLVM
and LLD (from what I can tell at least), so it's in general much better to be
on this bandwagon for bugfixes and new features.
* Historical "hacks" like `wasm-gc` will soon no longer be necessary, LLD
will [natively implement][gc] `--gc-sections` (better than `wasm-gc`!) which
means a postprocessor is no longer needed to show off Rust's "small wasm
binary size".
LLD is added in a pretty standard way to rustc right now. A new rustbuild target
was defined for building LLD, and this is executed when a compiler's sysroot is
being assembled. LLD is compiled against the LLVM that we've got in tree, which
means we're currently on the `release_60` branch, but this may get upgraded in
the near future!
LLD is placed into rustc's sysroot in a `bin` directory. This is similar to
where `gcc.exe` can be found on Windows. This directory is automatically added
to `PATH` whenever rustc executes the linker, allowing us to define a `WasmLd`
linker which implements the interface that `wasm-ld`, LLD's frontend, expects.
Like Emscripten the LLD target is currently only enabled for Tier 1 platforms,
notably OSX/Windows/Linux, and will need to be installed manually for compiling
to wasm on other platforms. LLD is by default turned off in rustbuild, and
requires a `config.toml` option to be enabled to turn it on.
Finally the unstable `#![wasm_import_memory]` attribute was also removed as LLD
has a native option for controlling this.
[gc]: https://reviews.llvm.org/D42511
2017-08-26 18:30:12 -07:00
|
|
|
!target.contains("msvc") &&
|
|
|
|
!target.contains("emscripten") &&
|
|
|
|
!target.contains("wasm32") {
|
2017-10-15 21:39:16 +03:00
|
|
|
Some(self.cc(target))
|
|
|
|
} else {
|
|
|
|
None
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
2016-09-06 21:49:02 -05:00
|
|
|
|
2017-08-22 16:24:29 -05:00
|
|
|
/// Returns if this target should statically link the C runtime, if specified
|
|
|
|
fn crt_static(&self, target: Interned<String>) -> Option<bool> {
|
2017-08-22 16:24:29 -05:00
|
|
|
if target.contains("pc-windows-msvc") {
|
|
|
|
Some(true)
|
|
|
|
} else {
|
|
|
|
self.config.target_config.get(&target)
|
|
|
|
.and_then(|t| t.crt_static)
|
|
|
|
}
|
2017-08-22 16:24:29 -05:00
|
|
|
}
|
|
|
|
|
2016-09-06 21:49:02 -05:00
|
|
|
/// Returns the "musl root" for this `target`, if defined
|
2017-07-13 18:48:44 -06:00
|
|
|
fn musl_root(&self, target: Interned<String>) -> Option<&Path> {
|
|
|
|
self.config.target_config.get(&target)
|
2016-10-13 12:01:59 -07:00
|
|
|
.and_then(|t| t.musl_root.as_ref())
|
2016-09-06 21:49:02 -05:00
|
|
|
.or(self.config.musl_root.as_ref())
|
|
|
|
.map(|p| &**p)
|
|
|
|
}
|
2016-11-14 08:04:39 -08:00
|
|
|
|
travis: Parallelize tests on Android
Currently our slowest test suite on android, run-pass, takes over 5 times longer
than the x86_64 component (~400 -> ~2200s). Typically QEMU emulation does indeed
add overhead, but not 5x for this kind of workload. One of the slowest parts of
the Android process is that *compilation* happens serially. Tests themselves
need to run single-threaded on the emulator (due to how the test harness works)
and this forces the compiles themselves to be single threaded.
Now Travis gives us more than one core per machine, so it'd be much better if we
could take advantage of them! The emulator itself is still fundamentally
single-threaded, but we should see a nice speedup by sending binaries for it to
run much more quickly.
It turns out that we've already got all the tools to do this in-tree. The
qemu-test-{server,client} that are in use for the ARM Linux testing are a
perfect match for the Android emulator. This commit migrates the custom adb
management code in compiletest/rustbuild to the same qemu-test-{server,client}
implementation that ARM Linux uses.
This allows us to lift the parallelism restriction on the compiletest test
suites, namely run-pass. Consequently although we'll still basically run the
tests themselves in single threaded mode we'll be able to compile all of them in
parallel, keeping the pipeline much more full and using more cores for the work
at hand. Additionally the architecture here should be a bit speedier as it
should have less overhead than adb which is a whole new process on both the host
and the emulator!
Locally on an 8 core machine I've seen the run-pass test suite speed up from
taking nearly an hour to only taking 6 minutes. I don't think we'll see quite a
drastic speedup on Travis but I'm hoping this change can place the Android tests
well below 2 hours instead of just above 2 hours.
Because the client/server here are now repurposed for more than just QEMU,
they've been renamed to `remote-test-{server,client}`.
Note that this PR does not currently modify how debuginfo tests are executed on
Android. While parallelizable it wouldn't be quite as easy, so that's left to
another day. Thankfully that test suite is much smaller than the run-pass test
suite.
As a final fix I discovered that the ARM and Android test suites were actually
running all library unit tests (e.g. stdtest, coretest, etc) twice. I've
corrected that to only run tests once which should also give a nice boost in
overall cycle time here.
2017-04-26 08:52:19 -07:00
|
|
|
/// Returns whether the target will be tested using the `remote-test-client`
|
|
|
|
/// and `remote-test-server` binaries.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn remote_tested(&self, target: Interned<String>) -> bool {
|
2017-07-03 11:41:58 +02:00
|
|
|
self.qemu_rootfs(target).is_some() || target.contains("android") ||
|
|
|
|
env::var_os("TEST_DEVICE_ADDR").is_some()
|
travis: Parallelize tests on Android
Currently our slowest test suite on android, run-pass, takes over 5 times longer
than the x86_64 component (~400 -> ~2200s). Typically QEMU emulation does indeed
add overhead, but not 5x for this kind of workload. One of the slowest parts of
the Android process is that *compilation* happens serially. Tests themselves
need to run single-threaded on the emulator (due to how the test harness works)
and this forces the compiles themselves to be single threaded.
Now Travis gives us more than one core per machine, so it'd be much better if we
could take advantage of them! The emulator itself is still fundamentally
single-threaded, but we should see a nice speedup by sending binaries for it to
run much more quickly.
It turns out that we've already got all the tools to do this in-tree. The
qemu-test-{server,client} that are in use for the ARM Linux testing are a
perfect match for the Android emulator. This commit migrates the custom adb
management code in compiletest/rustbuild to the same qemu-test-{server,client}
implementation that ARM Linux uses.
This allows us to lift the parallelism restriction on the compiletest test
suites, namely run-pass. Consequently although we'll still basically run the
tests themselves in single threaded mode we'll be able to compile all of them in
parallel, keeping the pipeline much more full and using more cores for the work
at hand. Additionally the architecture here should be a bit speedier as it
should have less overhead than adb which is a whole new process on both the host
and the emulator!
Locally on an 8 core machine I've seen the run-pass test suite speed up from
taking nearly an hour to only taking 6 minutes. I don't think we'll see quite a
drastic speedup on Travis but I'm hoping this change can place the Android tests
well below 2 hours instead of just above 2 hours.
Because the client/server here are now repurposed for more than just QEMU,
they've been renamed to `remote-test-{server,client}`.
Note that this PR does not currently modify how debuginfo tests are executed on
Android. While parallelizable it wouldn't be quite as easy, so that's left to
another day. Thankfully that test suite is much smaller than the run-pass test
suite.
As a final fix I discovered that the ARM and Android test suites were actually
running all library unit tests (e.g. stdtest, coretest, etc) twice. I've
corrected that to only run tests once which should also give a nice boost in
overall cycle time here.
2017-04-26 08:52:19 -07:00
|
|
|
}
|
|
|
|
|
2017-01-28 13:38:06 -08:00
|
|
|
/// Returns the root of the "rootfs" image that this target will be using,
|
|
|
|
/// if one was configured.
|
|
|
|
///
|
|
|
|
/// If `Some` is returned then that means that tests for this target are
|
|
|
|
/// emulated with QEMU and binaries will need to be shipped to the emulator.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn qemu_rootfs(&self, target: Interned<String>) -> Option<&Path> {
|
|
|
|
self.config.target_config.get(&target)
|
2017-01-28 13:38:06 -08:00
|
|
|
.and_then(|t| t.qemu_rootfs.as_ref())
|
|
|
|
.map(|p| &**p)
|
|
|
|
}
|
|
|
|
|
2016-11-14 08:04:39 -08:00
|
|
|
/// Path to the python interpreter to use
|
|
|
|
fn python(&self) -> &Path {
|
|
|
|
self.config.python.as_ref().unwrap()
|
|
|
|
}
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
|
2018-01-02 16:21:35 -08:00
|
|
|
/// Temporary directory that extended error information is emitted to.
|
|
|
|
fn extended_error_dir(&self) -> PathBuf {
|
|
|
|
self.out.join("tmp/extended-error-metadata")
|
|
|
|
}
|
|
|
|
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
/// Tests whether the `compiler` compiling for `target` should be forced to
|
|
|
|
/// use a stage1 compiler instead.
|
|
|
|
///
|
|
|
|
/// Currently, by default, the build system does not perform a "full
|
|
|
|
/// bootstrap" by default where we compile the compiler three times.
|
|
|
|
/// Instead, we compile the compiler two times. The final stage (stage2)
|
|
|
|
/// just copies the libraries from the previous stage, which is what this
|
|
|
|
/// method detects.
|
|
|
|
///
|
|
|
|
/// Here we return `true` if:
|
|
|
|
///
|
|
|
|
/// * The build isn't performing a full bootstrap
|
|
|
|
/// * The `compiler` is in the final stage, 2
|
|
|
|
/// * We're not cross-compiling, so the artifacts are already available in
|
|
|
|
/// stage1
|
|
|
|
///
|
|
|
|
/// When all of these conditions are met the build will lift artifacts from
|
|
|
|
/// the previous stage forward.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn force_use_stage1(&self, compiler: Compiler, target: Interned<String>) -> bool {
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
!self.config.full_bootstrap &&
|
|
|
|
compiler.stage >= 2 &&
|
2017-08-28 18:32:29 -07:00
|
|
|
(self.hosts.iter().any(|h| *h == target) || target == self.build)
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
}
|
2017-02-15 15:57:06 -08:00
|
|
|
|
|
|
|
/// Returns the directory that OpenSSL artifacts are compiled into if
|
|
|
|
/// configured to do so.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn openssl_dir(&self, target: Interned<String>) -> Option<PathBuf> {
|
2017-02-15 15:57:06 -08:00
|
|
|
// OpenSSL not used on Windows
|
|
|
|
if target.contains("windows") {
|
|
|
|
None
|
|
|
|
} else if self.config.openssl_static {
|
2017-07-13 18:48:44 -06:00
|
|
|
Some(self.out.join(&*target).join("openssl"))
|
2017-02-15 15:57:06 -08:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the directory that OpenSSL artifacts are installed into if
|
|
|
|
/// configured as such.
|
2017-07-13 18:48:44 -06:00
|
|
|
fn openssl_install_dir(&self, target: Interned<String>) -> Option<PathBuf> {
|
2017-02-15 15:57:06 -08:00
|
|
|
self.openssl_dir(target).map(|p| p.join("install"))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Given `num` in the form "a.b.c" return a "release string" which
|
|
|
|
/// describes the release version number.
|
|
|
|
///
|
|
|
|
/// For example on nightly this returns "a.b.c-nightly", on beta it returns
|
|
|
|
/// "a.b.c-beta.1" and on stable it just returns "a.b.c".
|
|
|
|
fn release(&self, num: &str) -> String {
|
|
|
|
match &self.config.channel[..] {
|
|
|
|
"stable" => num.to_string(),
|
2018-01-25 16:22:58 -08:00
|
|
|
"beta" => if self.rust_info.is_git() {
|
|
|
|
format!("{}-beta.{}", num, self.beta_prerelease_version())
|
|
|
|
} else {
|
|
|
|
format!("{}-beta", num)
|
|
|
|
},
|
2017-02-15 15:57:06 -08:00
|
|
|
"nightly" => format!("{}-nightly", num),
|
|
|
|
_ => format!("{}-dev", num),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 12:53:51 -08:00
|
|
|
fn beta_prerelease_version(&self) -> u32 {
|
|
|
|
if let Some(s) = self.prerelease_version.get() {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
let beta = output(
|
|
|
|
Command::new("git")
|
|
|
|
.arg("ls-remote")
|
|
|
|
.arg("origin")
|
|
|
|
.arg("beta")
|
|
|
|
.current_dir(&self.src)
|
|
|
|
);
|
|
|
|
let beta = beta.trim().split_whitespace().next().unwrap();
|
|
|
|
let master = output(
|
|
|
|
Command::new("git")
|
|
|
|
.arg("ls-remote")
|
|
|
|
.arg("origin")
|
|
|
|
.arg("master")
|
|
|
|
.current_dir(&self.src)
|
|
|
|
);
|
|
|
|
let master = master.trim().split_whitespace().next().unwrap();
|
|
|
|
|
|
|
|
// Figure out where the current beta branch started.
|
|
|
|
let base = output(
|
|
|
|
Command::new("git")
|
|
|
|
.arg("merge-base")
|
|
|
|
.arg(beta)
|
|
|
|
.arg(master)
|
|
|
|
.current_dir(&self.src),
|
|
|
|
);
|
|
|
|
let base = base.trim();
|
|
|
|
|
|
|
|
// Next figure out how many merge commits happened since we branched off
|
|
|
|
// beta. That's our beta number!
|
|
|
|
let count = output(
|
|
|
|
Command::new("git")
|
|
|
|
.arg("rev-list")
|
|
|
|
.arg("--count")
|
|
|
|
.arg("--merges")
|
|
|
|
.arg(format!("{}...HEAD", base))
|
|
|
|
.current_dir(&self.src),
|
|
|
|
);
|
|
|
|
let n = count.trim().parse().unwrap();
|
|
|
|
self.prerelease_version.set(Some(n));
|
|
|
|
n
|
|
|
|
}
|
|
|
|
|
2017-02-15 15:57:06 -08:00
|
|
|
/// Returns the value of `release` above for Rust itself.
|
|
|
|
fn rust_release(&self) -> String {
|
|
|
|
self.release(channel::CFG_RELEASE_NUM)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the "package version" for a component given the `num` release
|
|
|
|
/// number.
|
|
|
|
///
|
|
|
|
/// The package version is typically what shows up in the names of tarballs.
|
|
|
|
/// For channels like beta/nightly it's just the channel name, otherwise
|
|
|
|
/// it's the `num` provided.
|
|
|
|
fn package_vers(&self, num: &str) -> String {
|
|
|
|
match &self.config.channel[..] {
|
|
|
|
"stable" => num.to_string(),
|
|
|
|
"beta" => "beta".to_string(),
|
|
|
|
"nightly" => "nightly".to_string(),
|
|
|
|
_ => format!("{}-dev", num),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the value of `package_vers` above for Rust itself.
|
|
|
|
fn rust_package_vers(&self) -> String {
|
|
|
|
self.package_vers(channel::CFG_RELEASE_NUM)
|
|
|
|
}
|
|
|
|
|
2017-03-13 19:49:36 -07:00
|
|
|
/// Returns the value of `package_vers` above for Cargo
|
|
|
|
fn cargo_package_vers(&self) -> String {
|
2017-03-28 08:00:46 +13:00
|
|
|
self.package_vers(&self.release_num("cargo"))
|
2017-03-13 19:49:36 -07:00
|
|
|
}
|
|
|
|
|
2017-04-27 11:49:03 +02:00
|
|
|
/// Returns the value of `package_vers` above for rls
|
|
|
|
fn rls_package_vers(&self) -> String {
|
|
|
|
self.package_vers(&self.release_num("rls"))
|
|
|
|
}
|
|
|
|
|
2017-11-10 15:09:39 +13:00
|
|
|
/// Returns the value of `package_vers` above for rustfmt
|
|
|
|
fn rustfmt_package_vers(&self) -> String {
|
|
|
|
self.package_vers(&self.release_num("rustfmt"))
|
|
|
|
}
|
|
|
|
|
2017-02-15 15:57:06 -08:00
|
|
|
/// Returns the `version` string associated with this compiler for Rust
|
|
|
|
/// itself.
|
|
|
|
///
|
|
|
|
/// Note that this is a descriptive string which includes the commit date,
|
|
|
|
/// sha, version, etc.
|
|
|
|
fn rust_version(&self) -> String {
|
|
|
|
self.rust_info.version(self, channel::CFG_RELEASE_NUM)
|
|
|
|
}
|
|
|
|
|
2017-08-31 16:37:14 +02:00
|
|
|
/// Return the full commit hash
|
|
|
|
fn rust_sha(&self) -> Option<&str> {
|
|
|
|
self.rust_info.sha()
|
|
|
|
}
|
|
|
|
|
2017-03-28 08:00:46 +13:00
|
|
|
/// Returns the `a.b.c` version that the given package is at.
|
|
|
|
fn release_num(&self, package: &str) -> String {
|
2017-03-06 06:55:24 -08:00
|
|
|
let mut toml = String::new();
|
2017-04-20 14:32:54 -07:00
|
|
|
let toml_file_name = self.src.join(&format!("src/tools/{}/Cargo.toml", package));
|
2017-03-28 08:00:46 +13:00
|
|
|
t!(t!(File::open(toml_file_name)).read_to_string(&mut toml));
|
2017-03-06 06:55:24 -08:00
|
|
|
for line in toml.lines() {
|
|
|
|
let prefix = "version = \"";
|
|
|
|
let suffix = "\"";
|
|
|
|
if line.starts_with(prefix) && line.ends_with(suffix) {
|
|
|
|
return line[prefix.len()..line.len() - suffix.len()].to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 08:00:46 +13:00
|
|
|
panic!("failed to find version in {}'s Cargo.toml", package)
|
2017-03-17 09:52:12 +13:00
|
|
|
}
|
|
|
|
|
2017-02-15 15:57:06 -08:00
|
|
|
/// Returns whether unstable features should be enabled for the compiler
|
|
|
|
/// we're building.
|
|
|
|
fn unstable_features(&self) -> bool {
|
|
|
|
match &self.config.channel[..] {
|
|
|
|
"stable" | "beta" => false,
|
|
|
|
"nightly" | _ => true,
|
|
|
|
}
|
|
|
|
}
|
2017-05-18 00:33:20 +08:00
|
|
|
|
|
|
|
/// Fold the output of the commands after this method into a group. The fold
|
|
|
|
/// ends when the returned object is dropped. Folding can only be used in
|
|
|
|
/// the Travis CI environment.
|
|
|
|
pub fn fold_output<D, F>(&self, name: F) -> Option<OutputFolder>
|
|
|
|
where D: Into<String>, F: FnOnce() -> D
|
|
|
|
{
|
|
|
|
if self.ci_env == CiEnv::Travis {
|
|
|
|
Some(OutputFolder::new(name().into()))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 10:20:20 -06:00
|
|
|
|
2017-11-30 18:18:47 +08:00
|
|
|
/// Updates the actual toolstate of a tool.
|
|
|
|
///
|
|
|
|
/// The toolstates are saved to the file specified by the key
|
|
|
|
/// `rust.save-toolstates` in `config.toml`. If unspecified, nothing will be
|
|
|
|
/// done. The file is updated immediately after this function completes.
|
|
|
|
pub fn save_toolstate(&self, tool: &str, state: ToolState) {
|
|
|
|
use std::io::{Seek, SeekFrom};
|
|
|
|
|
|
|
|
if let Some(ref path) = self.config.save_toolstates {
|
|
|
|
let mut file = t!(fs::OpenOptions::new()
|
|
|
|
.create(true)
|
|
|
|
.read(true)
|
|
|
|
.write(true)
|
|
|
|
.open(path));
|
|
|
|
|
|
|
|
let mut current_toolstates: HashMap<Box<str>, ToolState> =
|
|
|
|
serde_json::from_reader(&mut file).unwrap_or_default();
|
|
|
|
current_toolstates.insert(tool.into(), state);
|
|
|
|
t!(file.seek(SeekFrom::Start(0)));
|
|
|
|
t!(file.set_len(0));
|
|
|
|
t!(serde_json::to_writer(file, ¤t_toolstates));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Change Step to be invoked with a path when in default mode.
Previously, a Step would be able to tell on its own when it was invoked
"by-default" (that is, `./x.py test` was called instead of `./x.py test
some/path`). This commit replaces that functionality, invoking each Step
with each of the paths it has specified as "should be invoked by."
For example, if a step calls `path("src/tools/cargo")` and
`path("src/doc/cargo")` then it's make_run will be called twice, with
"src/tools/cargo" and "src/doc/cargo." This makes it so that default
handling logic is in builder, instead of spread across various Steps.
However, this meant that some Step specifications needed to be updated,
since for example `rustdoc` can be built by `./x.py build
src/librustdoc` or `./x.py build src/tools/rustdoc`. A `PathSet`
abstraction is added that handles this: now, each Step can not only list
`path(...)` but also `paths(&[a, b, ...])` which will make it so that we
don't invoke it with each of the individual paths, instead invoking it
with the first path in the list (though this shouldn't be depended on).
Future work likely consists of implementing a better/easier way for a
given Step to work with "any" crate in-tree, especially those that want
to run tests, build, or check crates in the std, test, or rustc crate
trees. Currently this is rather painful to do as most of the logic is
duplicated across should_run and make_run. It seems likely this can be
abstracted away into builder somehow.
2018-02-11 09:51:58 -07:00
|
|
|
fn in_tree_crates(&self, root: &str) -> Vec<&Crate> {
|
2017-07-05 10:20:20 -06:00
|
|
|
let mut ret = Vec::new();
|
Change Step to be invoked with a path when in default mode.
Previously, a Step would be able to tell on its own when it was invoked
"by-default" (that is, `./x.py test` was called instead of `./x.py test
some/path`). This commit replaces that functionality, invoking each Step
with each of the paths it has specified as "should be invoked by."
For example, if a step calls `path("src/tools/cargo")` and
`path("src/doc/cargo")` then it's make_run will be called twice, with
"src/tools/cargo" and "src/doc/cargo." This makes it so that default
handling logic is in builder, instead of spread across various Steps.
However, this meant that some Step specifications needed to be updated,
since for example `rustdoc` can be built by `./x.py build
src/librustdoc` or `./x.py build src/tools/rustdoc`. A `PathSet`
abstraction is added that handles this: now, each Step can not only list
`path(...)` but also `paths(&[a, b, ...])` which will make it so that we
don't invoke it with each of the individual paths, instead invoking it
with the first path in the list (though this shouldn't be depended on).
Future work likely consists of implementing a better/easier way for a
given Step to work with "any" crate in-tree, especially those that want
to run tests, build, or check crates in the std, test, or rustc crate
trees. Currently this is rather painful to do as most of the logic is
duplicated across should_run and make_run. It seems likely this can be
abstracted away into builder somehow.
2018-02-11 09:51:58 -07:00
|
|
|
let mut list = vec![INTERNER.intern_str(root)];
|
2017-07-05 10:20:20 -06:00
|
|
|
let mut visited = HashSet::new();
|
|
|
|
while let Some(krate) = list.pop() {
|
2017-07-13 18:48:44 -06:00
|
|
|
let krate = &self.crates[&krate];
|
Change Step to be invoked with a path when in default mode.
Previously, a Step would be able to tell on its own when it was invoked
"by-default" (that is, `./x.py test` was called instead of `./x.py test
some/path`). This commit replaces that functionality, invoking each Step
with each of the paths it has specified as "should be invoked by."
For example, if a step calls `path("src/tools/cargo")` and
`path("src/doc/cargo")` then it's make_run will be called twice, with
"src/tools/cargo" and "src/doc/cargo." This makes it so that default
handling logic is in builder, instead of spread across various Steps.
However, this meant that some Step specifications needed to be updated,
since for example `rustdoc` can be built by `./x.py build
src/librustdoc` or `./x.py build src/tools/rustdoc`. A `PathSet`
abstraction is added that handles this: now, each Step can not only list
`path(...)` but also `paths(&[a, b, ...])` which will make it so that we
don't invoke it with each of the individual paths, instead invoking it
with the first path in the list (though this shouldn't be depended on).
Future work likely consists of implementing a better/easier way for a
given Step to work with "any" crate in-tree, especially those that want
to run tests, build, or check crates in the std, test, or rustc crate
trees. Currently this is rather painful to do as most of the logic is
duplicated across should_run and make_run. It seems likely this can be
abstracted away into builder somehow.
2018-02-11 09:51:58 -07:00
|
|
|
if krate.is_local(self) {
|
|
|
|
ret.push(krate);
|
|
|
|
for dep in &krate.deps {
|
|
|
|
if visited.insert(dep) && dep != "build_helper" {
|
|
|
|
list.push(*dep);
|
|
|
|
}
|
2017-07-05 10:20:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret
|
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl<'a> Compiler {
|
|
|
|
pub fn with_stage(mut self, stage: u32) -> Compiler {
|
2017-07-05 10:20:20 -06:00
|
|
|
self.stage = stage;
|
|
|
|
self
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether this is a snapshot compiler for `build`'s configuration
|
2017-07-05 10:46:41 -06:00
|
|
|
pub fn is_snapshot(&self, build: &Build) -> bool {
|
2017-06-27 15:59:43 -06:00
|
|
|
self.stage == 0 && self.host == build.build
|
2016-07-05 21:58:20 -07:00
|
|
|
}
|
2016-12-31 14:29:27 +08:00
|
|
|
|
2016-12-31 14:31:08 +08:00
|
|
|
/// Returns if this compiler should be treated as a final stage one in the
|
|
|
|
/// current build session.
|
|
|
|
/// This takes into account whether we're performing a full bootstrap or
|
|
|
|
/// not; don't directly compare the stage with `2`!
|
2017-07-05 10:20:20 -06:00
|
|
|
pub fn is_final_stage(&self, build: &Build) -> bool {
|
2016-12-31 14:29:27 +08:00
|
|
|
let final_stage = if build.config.full_bootstrap { 2 } else { 1 };
|
|
|
|
self.stage >= final_stage
|
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|