about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/bin/rustc.rs5
-rw-r--r--src/bootstrap/bootstrap.py1
-rw-r--r--src/bootstrap/builder.rs23
-rw-r--r--src/bootstrap/check.rs1539
-rw-r--r--src/bootstrap/compile.rs16
-rw-r--r--src/bootstrap/flags.rs23
-rw-r--r--src/bootstrap/lib.rs13
-rw-r--r--src/bootstrap/test.rs1542
8 files changed, 1675 insertions, 1487 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 37336a56d76..55d104b1826 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -125,11 +125,6 @@ fn main() {
             cmd.arg(format!("-Clinker={}", target_linker));
         }
 
-        // Pass down incremental directory, if any.
-        if let Ok(dir) = env::var("RUSTC_INCREMENTAL") {
-            cmd.arg(format!("-Zincremental={}", dir));
-        }
-
         let crate_name = args.windows(2)
             .find(|a| &*a[0] == "--crate-name")
             .unwrap();
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 93c3694bc0c..ecf9c0a7590 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -602,6 +602,7 @@ class RustBuild(object):
         env["LIBRARY_PATH"] = os.path.join(self.bin_root(), "lib") + \
             (os.pathsep + env["LIBRARY_PATH"]) \
             if "LIBRARY_PATH" in env else ""
+        env["RUSTFLAGS"] = "-Cdebuginfo=2"
         env["PATH"] = os.path.join(self.bin_root(), "bin") + \
             os.pathsep + env["PATH"]
         if not os.path.isfile(self.cargo()):
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 7655097681b..79058984b13 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -26,6 +26,7 @@ use util::{exe, libdir, add_lib_path};
 use {Build, Mode};
 use cache::{INTERNER, Interned, Cache};
 use check;
+use test;
 use flags::Subcommand;
 use doc;
 use tool;
@@ -230,6 +231,7 @@ impl<'a> ShouldRun<'a> {
 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
 pub enum Kind {
     Build,
+    Check,
     Test,
     Bench,
     Dist,
@@ -251,13 +253,13 @@ impl<'a> Builder<'a> {
                 tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
                 tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
                 native::Llvm, tool::Rustfmt, tool::Miri),
-            Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
-                check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Rustdoc,
-                check::Linkcheck, check::Cargotest, check::Cargo, check::Rls, check::Docs,
-                check::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri, check::Clippy,
-                check::RustdocJS),
-
-            Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
+            Kind::Check => describe!(check::Std, check::Test, check::Rustc),
+            Kind::Test => describe!(test::Tidy, test::Bootstrap, test::DefaultCompiletest,
+                test::HostCompiletest, test::Crate, test::CrateLibrustc, test::Rustdoc,
+                test::Linkcheck, test::Cargotest, test::Cargo, test::Rls, test::Docs,
+                test::ErrorIndex, test::Distcheck, test::Rustfmt, test::Miri, test::Clippy,
+                test::RustdocJS),
+            Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
             Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
                 doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
                 doc::Reference, doc::Rustdoc, doc::RustByExample, doc::CargoBook),
@@ -304,6 +306,7 @@ impl<'a> Builder<'a> {
     pub fn run(build: &Build) {
         let (kind, paths) = match build.config.cmd {
             Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
+            Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
             Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]),
             Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
             Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
@@ -493,13 +496,14 @@ impl<'a> Builder<'a> {
             cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
         }
 
+
         if let Some(host_linker) = self.build.linker(compiler.host) {
             cargo.env("RUSTC_HOST_LINKER", host_linker);
         }
         if let Some(target_linker) = self.build.linker(target) {
             cargo.env("RUSTC_TARGET_LINKER", target_linker);
         }
-        if cmd != "build" {
+        if cmd != "build" && cmd != "check" {
             cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(self.compiler(2, self.build.build)));
         }
 
@@ -566,8 +570,7 @@ impl<'a> Builder<'a> {
         // not guaranteeing correctness across builds if the compiler
         // is changing under your feet.`
         if self.config.incremental && compiler.stage == 0 {
-            let incr_dir = self.incremental_dir(compiler);
-            cargo.env("RUSTC_INCREMENTAL", incr_dir);
+            cargo.env("CARGO_INCREMENTAL", "1");
         }
 
         if let Some(ref on_fail) = self.config.on_fail {
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index 5faec279438..0bc82c4f9f2 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -1,4 +1,4 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -8,1535 +8,156 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-//! Implementation of the test-related targets of the build system.
-//!
-//! This file implements the various regression test suites that we execute on
-//! our CI.
+//! Implementation of compiling the compiler and standard library, in "check" mode.
 
-use std::collections::HashSet;
-use std::env;
-use std::ffi::OsString;
-use std::iter;
-use std::fmt;
-use std::fs::{self, File};
-use std::path::{PathBuf, Path};
-use std::process::Command;
-use std::io::Read;
-
-use build_helper::{self, output};
-
-use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
-use cache::{INTERNER, Interned};
-use compile;
-use dist;
-use native;
-use tool::{self, Tool};
-use util::{self, dylib_path, dylib_path_var};
-use {Build, Mode};
-use toolstate::ToolState;
-
-const ADB_TEST_DIR: &str = "/data/tmp/work";
-
-/// The two modes of the test runner; tests or benchmarks.
-#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
-pub enum TestKind {
-    /// Run `cargo test`
-    Test,
-    /// Run `cargo bench`
-    Bench,
-}
-
-impl TestKind {
-    // Return the cargo subcommand for this test kind
-    fn subcommand(self) -> &'static str {
-        match self {
-            TestKind::Test => "test",
-            TestKind::Bench => "bench",
-        }
-    }
-}
-
-impl fmt::Display for TestKind {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        f.write_str(match *self {
-            TestKind::Test => "Testing",
-            TestKind::Bench => "Benchmarking",
-        })
-    }
-}
-
-fn try_run(build: &Build, cmd: &mut Command) -> bool {
-    if !build.fail_fast {
-        if !build.try_run(cmd) {
-            let mut failures = build.delayed_failures.borrow_mut();
-            failures.push(format!("{:?}", cmd));
-            return false;
-        }
-    } else {
-        build.run(cmd);
-    }
-    true
-}
-
-fn try_run_quiet(build: &Build, cmd: &mut Command) {
-    if !build.fail_fast {
-        if !build.try_run_quiet(cmd) {
-            let mut failures = build.delayed_failures.borrow_mut();
-            failures.push(format!("{:?}", cmd));
-        }
-    } else {
-        build.run_quiet(cmd);
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Linkcheck {
-    host: Interned<String>,
-}
-
-impl Step for Linkcheck {
-    type Output = ();
-    const ONLY_HOSTS: bool = true;
-    const DEFAULT: bool = true;
-
-    /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
-    ///
-    /// This tool in `src/tools` will verify the validity of all our links in the
-    /// documentation to ensure we don't have a bunch of dead ones.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let host = self.host;
-
-        println!("Linkcheck ({})", host);
-
-        builder.default_doc(None);
-
-        let _time = util::timeit();
-        try_run(build, builder.tool_cmd(Tool::Linkchecker)
-                            .arg(build.out.join(host).join("doc")));
-    }
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        let builder = run.builder;
-        run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Linkcheck { host: run.target });
-    }
-}
+use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, add_to_sysroot};
+use builder::{RunConfig, Builder, ShouldRun, Step};
+use {Build, Compiler, Mode};
+use cache::Interned;
+use std::path::PathBuf;
 
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Cargotest {
-    stage: u32,
-    host: Interned<String>,
-}
-
-impl Step for Cargotest {
-    type Output = ();
-    const ONLY_HOSTS: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/tools/cargotest")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Cargotest {
-            stage: run.builder.top_stage,
-            host: run.target,
-        });
-    }
-
-    /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
-    ///
-    /// This tool in `src/tools` will check out a few Rust projects and run `cargo
-    /// test` to ensure that we don't regress the test suites there.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let compiler = builder.compiler(self.stage, self.host);
-        builder.ensure(compile::Rustc { compiler, target: compiler.host });
-
-        // Note that this is a short, cryptic, and not scoped directory name. This
-        // is currently to minimize the length of path on Windows where we otherwise
-        // quickly run into path name limit constraints.
-        let out_dir = build.out.join("ct");
-        t!(fs::create_dir_all(&out_dir));
-
-        let _time = util::timeit();
-        let mut cmd = builder.tool_cmd(Tool::CargoTest);
-        try_run(build, cmd.arg(&build.initial_cargo)
-                          .arg(&out_dir)
-                          .env("RUSTC", builder.rustc(compiler))
-                          .env("RUSTDOC", builder.rustdoc(compiler.host)));
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Cargo {
-    stage: u32,
-    host: Interned<String>,
-}
-
-impl Step for Cargo {
-    type Output = ();
-    const ONLY_HOSTS: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/tools/cargo")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Cargo {
-            stage: run.builder.top_stage,
-            host: run.target,
-        });
-    }
-
-    /// Runs `cargo test` for `cargo` packaged with Rust.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let compiler = builder.compiler(self.stage, self.host);
-
-        builder.ensure(tool::Cargo { compiler, target: self.host });
-        let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
-        cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
-        if !build.fail_fast {
-            cargo.arg("--no-fail-fast");
-        }
-
-        // Don't build tests dynamically, just a pain to work with
-        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
-
-        // Don't run cross-compile tests, we may not have cross-compiled libstd libs
-        // available.
-        cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
-
-        try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Rls {
-    stage: u32,
-    host: Interned<String>,
-}
-
-impl Step for Rls {
-    type Output = ();
-    const ONLY_HOSTS: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/tools/rls")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Rls {
-            stage: run.builder.top_stage,
-            host: run.target,
-        });
-    }
-
-    /// Runs `cargo test` for the rls.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let stage = self.stage;
-        let host = self.host;
-        let compiler = builder.compiler(stage, host);
-
-        builder.ensure(tool::Rls { compiler, target: self.host });
-        let mut cargo = tool::prepare_tool_cargo(builder,
-                                                 compiler,
-                                                 host,
-                                                 "test",
-                                                 "src/tools/rls");
-
-        // Don't build tests dynamically, just a pain to work with
-        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
-
-        builder.add_rustc_lib_path(compiler, &mut cargo);
-
-        if try_run(build, &mut cargo) {
-            build.save_toolstate("rls", ToolState::TestPass);
-        }
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Rustfmt {
-    stage: u32,
-    host: Interned<String>,
-}
-
-impl Step for Rustfmt {
-    type Output = ();
-    const ONLY_HOSTS: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/tools/rustfmt")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Rustfmt {
-            stage: run.builder.top_stage,
-            host: run.target,
-        });
-    }
-
-    /// Runs `cargo test` for rustfmt.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let stage = self.stage;
-        let host = self.host;
-        let compiler = builder.compiler(stage, host);
-
-        builder.ensure(tool::Rustfmt { compiler, target: self.host });
-        let mut cargo = tool::prepare_tool_cargo(builder,
-                                                 compiler,
-                                                 host,
-                                                 "test",
-                                                 "src/tools/rustfmt");
-
-        // Don't build tests dynamically, just a pain to work with
-        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
-
-        builder.add_rustc_lib_path(compiler, &mut cargo);
-
-        if try_run(build, &mut cargo) {
-            build.save_toolstate("rustfmt", ToolState::TestPass);
-        }
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Miri {
-    stage: u32,
-    host: Interned<String>,
-}
-
-impl Step for Miri {
-    type Output = ();
-    const ONLY_HOSTS: bool = true;
-    const DEFAULT: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        let test_miri = run.builder.build.config.test_miri;
-        run.path("src/tools/miri").default_condition(test_miri)
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Miri {
-            stage: run.builder.top_stage,
-            host: run.target,
-        });
-    }
-
-    /// Runs `cargo test` for miri.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let stage = self.stage;
-        let host = self.host;
-        let compiler = builder.compiler(stage, host);
-
-        if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
-            let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
-            cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
-
-            // Don't build tests dynamically, just a pain to work with
-            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
-            // miri tests need to know about the stage sysroot
-            cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
-            cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
-            cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
-            cargo.env("MIRI_PATH", miri);
-
-            builder.add_rustc_lib_path(compiler, &mut cargo);
-
-            if try_run(build, &mut cargo) {
-                build.save_toolstate("miri", ToolState::TestPass);
-            }
-        } else {
-            eprintln!("failed to test miri: could not build");
-        }
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Clippy {
-    stage: u32,
-    host: Interned<String>,
-}
-
-impl Step for Clippy {
-    type Output = ();
-    const ONLY_HOSTS: bool = true;
-    const DEFAULT: bool = false;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/tools/clippy")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Clippy {
-            stage: run.builder.top_stage,
-            host: run.target,
-        });
-    }
-
-    /// Runs `cargo test` for clippy.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let stage = self.stage;
-        let host = self.host;
-        let compiler = builder.compiler(stage, host);
-
-        if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
-            let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
-            cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
-
-            // Don't build tests dynamically, just a pain to work with
-            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
-            // clippy tests need to know about the stage sysroot
-            cargo.env("SYSROOT", builder.sysroot(compiler));
-            cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
-            cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
-            let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir());
-            cargo.env("HOST_LIBS", host_libs);
-            // clippy tests need to find the driver
-            cargo.env("CLIPPY_DRIVER_PATH", clippy);
-
-            builder.add_rustc_lib_path(compiler, &mut cargo);
-
-            if try_run(build, &mut cargo) {
-                build.save_toolstate("clippy-driver", ToolState::TestPass);
-            }
-        } else {
-            eprintln!("failed to test clippy: could not build");
-        }
-    }
-}
-
-fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
-    // Configure PATH to find the right rustc. NB. we have to use PATH
-    // and not RUSTC because the Cargo test suite has tests that will
-    // fail if rustc is not spelled `rustc`.
-    let path = builder.sysroot(compiler).join("bin");
-    let old_path = env::var_os("PATH").unwrap_or_default();
-    env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
-}
-
-#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
-pub struct RustdocJS {
-    pub host: Interned<String>,
+pub struct Std {
     pub target: Interned<String>,
 }
 
-impl Step for RustdocJS {
+impl Step for Std {
     type Output = ();
     const DEFAULT: bool = true;
-    const ONLY_HOSTS: bool = true;
 
     fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/test/rustdoc-js")
+        run.path("src/libstd").krate("std")
     }
 
     fn make_run(run: RunConfig) {
-        run.builder.ensure(RustdocJS {
-            host: run.host,
+        run.builder.ensure(Std {
             target: run.target,
         });
     }
 
     fn run(self, builder: &Builder) {
-        if let Some(ref nodejs) = builder.config.nodejs {
-            let mut command = Command::new(nodejs);
-            command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
-            builder.ensure(::doc::Std {
-                target: self.target,
-                stage: builder.top_stage,
-            });
-            builder.run(&mut command);
-        } else {
-            println!("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
-        }
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Tidy {
-    host: Interned<String>,
-}
-
-impl Step for Tidy {
-    type Output = ();
-    const DEFAULT: bool = true;
-    const ONLY_HOSTS: bool = true;
-    const ONLY_BUILD: bool = true;
-
-    /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
-    ///
-    /// This tool in `src/tools` checks up on various bits and pieces of style and
-    /// otherwise just implements a few lint-like checks that are specific to the
-    /// compiler itself.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let host = self.host;
-
-        let _folder = build.fold_output(|| "tidy");
-        println!("tidy check ({})", host);
-        let mut cmd = builder.tool_cmd(Tool::Tidy);
-        cmd.arg(build.src.join("src"));
-        if !build.config.vendor {
-            cmd.arg("--no-vendor");
-        }
-        if build.config.quiet_tests {
-            cmd.arg("--quiet");
-        }
-        try_run(build, &mut cmd);
-    }
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/tools/tidy")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Tidy {
-            host: run.builder.build.build,
-        });
-    }
-}
-
-fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
-    build.out.join(host).join("test")
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-struct Test {
-    path: &'static str,
-    mode: &'static str,
-    suite: &'static str,
-}
-
-static DEFAULT_COMPILETESTS: &[Test] = &[
-    Test { path: "src/test/ui", mode: "ui", suite: "ui" },
-    Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
-    Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
-    Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
-    Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
-    Test {
-        path: "src/test/run-pass-valgrind",
-        mode: "run-pass-valgrind",
-        suite: "run-pass-valgrind"
-    },
-    Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
-    Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
-    Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
-    Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
-
-    // What this runs varies depending on the native platform being apple
-    Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
-];
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct DefaultCompiletest {
-    compiler: Compiler,
-    target: Interned<String>,
-    mode: &'static str,
-    suite: &'static str,
-}
-
-impl Step for DefaultCompiletest {
-    type Output = ();
-    const DEFAULT: bool = true;
-
-    fn should_run(mut run: ShouldRun) -> ShouldRun {
-        for test in DEFAULT_COMPILETESTS {
-            run = run.path(test.path);
-        }
-        run
-    }
-
-    fn make_run(run: RunConfig) {
-        let compiler = run.builder.compiler(run.builder.top_stage, run.host);
-
-        let test = run.path.map(|path| {
-            DEFAULT_COMPILETESTS.iter().find(|&&test| {
-                path.ends_with(test.path)
-            }).unwrap_or_else(|| {
-                panic!("make_run in compile test to receive test path, received {:?}", path);
-            })
-        });
-
-        if let Some(test) = test {
-            run.builder.ensure(DefaultCompiletest {
-                compiler,
-                target: run.target,
-                mode: test.mode,
-                suite: test.suite,
-            });
-        } else {
-            for test in DEFAULT_COMPILETESTS {
-                run.builder.ensure(DefaultCompiletest {
-                    compiler,
-                    target: run.target,
-                    mode: test.mode,
-                    suite: test.suite
-                });
-            }
-        }
-    }
-
-    fn run(self, builder: &Builder) {
-        builder.ensure(Compiletest {
-            compiler: self.compiler,
-            target: self.target,
-            mode: self.mode,
-            suite: self.suite,
-        })
-    }
-}
-
-// Also default, but host-only.
-static HOST_COMPILETESTS: &[Test] = &[
-    Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
-    Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
-    Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
-    Test {
-        path: "src/test/compile-fail-fulldeps",
-        mode: "compile-fail",
-        suite: "compile-fail-fulldeps",
-    },
-    Test {
-        path: "src/test/incremental-fulldeps",
-        mode: "incremental",
-        suite: "incremental-fulldeps",
-    },
-    Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
-    Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
-
-    Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
-    Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
-    Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
-    Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
-    Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
-    Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
-];
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct HostCompiletest {
-    compiler: Compiler,
-    target: Interned<String>,
-    mode: &'static str,
-    suite: &'static str,
-}
-
-impl Step for HostCompiletest {
-    type Output = ();
-    const DEFAULT: bool = true;
-    const ONLY_HOSTS: bool = true;
-
-    fn should_run(mut run: ShouldRun) -> ShouldRun {
-        for test in HOST_COMPILETESTS {
-            run = run.path(test.path);
-        }
-        run
-    }
-
-    fn make_run(run: RunConfig) {
-        let compiler = run.builder.compiler(run.builder.top_stage, run.host);
-
-        let test = run.path.map(|path| {
-            HOST_COMPILETESTS.iter().find(|&&test| {
-                path.ends_with(test.path)
-            }).unwrap_or_else(|| {
-                panic!("make_run in compile test to receive test path, received {:?}", path);
-            })
-        });
-
-        if let Some(test) = test {
-            run.builder.ensure(HostCompiletest {
-                compiler,
-                target: run.target,
-                mode: test.mode,
-                suite: test.suite,
-            });
-        } else {
-            for test in HOST_COMPILETESTS {
-                if test.mode == "pretty" {
-                    continue;
-                }
-                run.builder.ensure(HostCompiletest {
-                    compiler,
-                    target: run.target,
-                    mode: test.mode,
-                    suite: test.suite
-                });
-            }
-        }
-    }
-
-    fn run(self, builder: &Builder) {
-        builder.ensure(Compiletest {
-            compiler: self.compiler,
-            target: self.target,
-            mode: self.mode,
-            suite: self.suite,
-        })
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-struct Compiletest {
-    compiler: Compiler,
-    target: Interned<String>,
-    mode: &'static str,
-    suite: &'static str,
-}
-
-impl Step for Compiletest {
-    type Output = ();
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.never()
-    }
-
-    /// Executes the `compiletest` tool to run a suite of tests.
-    ///
-    /// Compiles all tests with `compiler` for `target` with the specified
-    /// compiletest `mode` and `suite` arguments. For example `mode` can be
-    /// "run-pass" or `suite` can be something like `debuginfo`.
-    fn run(self, builder: &Builder) {
         let build = builder.build;
-        let compiler = self.compiler;
         let target = self.target;
-        let mode = self.mode;
-        let suite = self.suite;
-
-        // Skip codegen tests if they aren't enabled in configuration.
-        if !build.config.codegen_tests && suite == "codegen" {
-            return;
-        }
-
-        if suite == "debuginfo" {
-            // Skip debuginfo tests on MSVC
-            if build.build.contains("msvc") {
-                return;
-            }
-
-            if mode == "debuginfo-XXX" {
-                return if build.build.contains("apple") {
-                    builder.ensure(Compiletest {
-                        mode: "debuginfo-lldb",
-                        ..self
-                    });
-                } else {
-                    builder.ensure(Compiletest {
-                        mode: "debuginfo-gdb",
-                        ..self
-                    });
-                };
-            }
-
-            builder.ensure(dist::DebuggerScripts {
-                sysroot: builder.sysroot(compiler),
-                host: target
-            });
-        }
-
-        if suite.ends_with("fulldeps") ||
-            // FIXME: Does pretty need librustc compiled? Note that there are
-            // fulldeps test suites with mode = pretty as well.
-            mode == "pretty" ||
-            mode == "rustdoc" ||
-            mode == "run-make" {
-            builder.ensure(compile::Rustc { compiler, target });
-        }
-
-        builder.ensure(compile::Test { compiler, target });
-        builder.ensure(native::TestHelpers { target });
-        builder.ensure(RemoteCopyLibs { compiler, target });
-
-        let _folder = build.fold_output(|| format!("test_{}", suite));
-        println!("Check compiletest suite={} mode={} ({} -> {})",
-                 suite, mode, &compiler.host, target);
-        let mut cmd = builder.tool_cmd(Tool::Compiletest);
-
-        // compiletest currently has... a lot of arguments, so let's just pass all
-        // of them!
-
-        cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
-        cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
-        cmd.arg("--rustc-path").arg(builder.rustc(compiler));
-
-        // Avoid depending on rustdoc when we don't need it.
-        if mode == "rustdoc" || mode == "run-make" {
-            cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
-        }
-
-        cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
-        cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
-        cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
-        cmd.arg("--mode").arg(mode);
-        cmd.arg("--target").arg(target);
-        cmd.arg("--host").arg(&*compiler.host);
-        cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
-
-        if let Some(ref nodejs) = build.config.nodejs {
-            cmd.arg("--nodejs").arg(nodejs);
-        }
-
-        let mut flags = vec!["-Crpath".to_string()];
-        if build.config.rust_optimize_tests {
-            flags.push("-O".to_string());
-        }
-        if build.config.rust_debuginfo_tests {
-            flags.push("-g".to_string());
-        }
-        flags.push("-Zmiri -Zunstable-options".to_string());
-        flags.push(build.config.cmd.rustc_args().join(" "));
-
-        if let Some(linker) = build.linker(target) {
-            cmd.arg("--linker").arg(linker);
-        }
-
-        let hostflags = flags.clone();
-        cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
-
-        let mut targetflags = flags.clone();
-        targetflags.push(format!("-Lnative={}",
-                                 build.test_helpers_out(target).display()));
-        cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
-
-        cmd.arg("--docck-python").arg(build.python());
-
-        if build.build.ends_with("apple-darwin") {
-            // Force /usr/bin/python on macOS for LLDB tests because we're loading the
-            // LLDB plugin's compiled module which only works with the system python
-            // (namely not Homebrew-installed python)
-            cmd.arg("--lldb-python").arg("/usr/bin/python");
-        } else {
-            cmd.arg("--lldb-python").arg(build.python());
-        }
-
-        if let Some(ref gdb) = build.config.gdb {
-            cmd.arg("--gdb").arg(gdb);
-        }
-        if let Some(ref vers) = build.lldb_version {
-            cmd.arg("--lldb-version").arg(vers);
-        }
-        if let Some(ref dir) = build.lldb_python_dir {
-            cmd.arg("--lldb-python-dir").arg(dir);
-        }
-
-        cmd.args(&build.config.cmd.test_args());
-
-        if build.is_verbose() {
-            cmd.arg("--verbose");
-        }
-
-        if build.config.quiet_tests {
-            cmd.arg("--quiet");
-        }
-
-        if build.config.llvm_enabled {
-            let llvm_config = build.llvm_config(target);
-            let llvm_version = output(Command::new(&llvm_config).arg("--version"));
-            cmd.arg("--llvm-version").arg(llvm_version);
-            if !build.is_rust_llvm(target) {
-                cmd.arg("--system-llvm");
-            }
-
-            // Only pass correct values for these flags for the `run-make` suite as it
-            // requires that a C++ compiler was configured which isn't always the case.
-            if suite == "run-make" {
-                let llvm_components = output(Command::new(&llvm_config).arg("--components"));
-                let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
-                cmd.arg("--cc").arg(build.cc(target))
-                .arg("--cxx").arg(build.cxx(target).unwrap())
-                .arg("--cflags").arg(build.cflags(target).join(" "))
-                .arg("--llvm-components").arg(llvm_components.trim())
-                .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
-                if let Some(ar) = build.ar(target) {
-                    cmd.arg("--ar").arg(ar);
-                }
-            }
-        }
-        if suite == "run-make" && !build.config.llvm_enabled {
-            println!("Ignoring run-make test suite as they generally dont work without LLVM");
-            return;
-        }
+        let compiler = builder.compiler(0, build.build);
 
-        if suite != "run-make" {
-            cmd.arg("--cc").arg("")
-               .arg("--cxx").arg("")
-               .arg("--cflags").arg("")
-               .arg("--llvm-components").arg("")
-               .arg("--llvm-cxxflags").arg("");
-        }
+        let _folder = build.fold_output(|| format!("stage{}-std", compiler.stage));
+        println!("Checking std artifacts ({} -> {})", &compiler.host, target);
 
-        if build.remote_tested(target) {
-            cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
-        }
-
-        // Running a C compiler on MSVC requires a few env vars to be set, to be
-        // sure to set them here.
-        //
-        // Note that if we encounter `PATH` we make sure to append to our own `PATH`
-        // rather than stomp over it.
-        if target.contains("msvc") {
-            for &(ref k, ref v) in build.cc[&target].env() {
-                if k != "PATH" {
-                    cmd.env(k, v);
-                }
-            }
-        }
-        cmd.env("RUSTC_BOOTSTRAP", "1");
-        build.add_rust_test_threads(&mut cmd);
-
-        if build.config.sanitizers {
-            cmd.env("SANITIZER_SUPPORT", "1");
-        }
-
-        if build.config.profiler {
-            cmd.env("PROFILER_SUPPORT", "1");
-        }
-
-        cmd.arg("--adb-path").arg("adb");
-        cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
-        if target.contains("android") {
-            // Assume that cc for this target comes from the android sysroot
-            cmd.arg("--android-cross-path")
-               .arg(build.cc(target).parent().unwrap().parent().unwrap());
-        } else {
-            cmd.arg("--android-cross-path").arg("");
-        }
-
-        build.ci_env.force_coloring_in_ci(&mut cmd);
-
-        let _time = util::timeit();
-        try_run(build, &mut cmd);
+        let out_dir = build.stage_out(compiler, Mode::Libstd);
+        build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
+        let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "check");
+        std_cargo(build, &compiler, target, &mut cargo);
+        run_cargo(build,
+                  &mut cargo,
+                  &libstd_stamp(build, compiler, target),
+                  true);
+        let libdir = builder.sysroot_libdir(compiler, target);
+        add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
     }
 }
 
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Docs {
-    compiler: Compiler,
+pub struct Rustc {
+    pub target: Interned<String>,
 }
 
-impl Step for Docs {
+impl Step for Rustc {
     type Output = ();
-    const DEFAULT: bool = true;
     const ONLY_HOSTS: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/doc")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Docs {
-            compiler: run.builder.compiler(run.builder.top_stage, run.host),
-        });
-    }
-
-    /// Run `rustdoc --test` for all documentation in `src/doc`.
-    ///
-    /// This will run all tests in our markdown documentation (e.g. the book)
-    /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
-    /// `compiler`.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let compiler = self.compiler;
-
-        builder.ensure(compile::Test { compiler, target: compiler.host });
-
-        // Do a breadth-first traversal of the `src/doc` directory and just run
-        // tests for all files that end in `*.md`
-        let mut stack = vec![build.src.join("src/doc")];
-        let _time = util::timeit();
-        let _folder = build.fold_output(|| "test_docs");
-
-        while let Some(p) = stack.pop() {
-            if p.is_dir() {
-                stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
-                continue
-            }
-
-            if p.extension().and_then(|s| s.to_str()) != Some("md") {
-                continue;
-            }
-
-            // The nostarch directory in the book is for no starch, and so isn't
-            // guaranteed to build. We don't care if it doesn't build, so skip it.
-            if p.to_str().map_or(false, |p| p.contains("nostarch")) {
-                continue;
-            }
-
-            markdown_test(builder, compiler, &p);
-        }
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct ErrorIndex {
-    compiler: Compiler,
-}
-
-impl Step for ErrorIndex {
-    type Output = ();
     const DEFAULT: bool = true;
-    const ONLY_HOSTS: bool = true;
 
     fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/tools/error_index_generator")
+        run.path("src/librustc").krate("rustc-main")
     }
 
     fn make_run(run: RunConfig) {
-        run.builder.ensure(ErrorIndex {
-            compiler: run.builder.compiler(run.builder.top_stage, run.host),
-        });
-    }
-
-    /// Run the error index generator tool to execute the tests located in the error
-    /// index.
-    ///
-    /// The `error_index_generator` tool lives in `src/tools` and is used to
-    /// generate a markdown file from the error indexes of the code base which is
-    /// then passed to `rustdoc --test`.
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let compiler = self.compiler;
-
-        builder.ensure(compile::Std { compiler, target: compiler.host });
-
-        let _folder = build.fold_output(|| "test_error_index");
-        println!("Testing error-index stage{}", compiler.stage);
-
-        let dir = testdir(build, compiler.host);
-        t!(fs::create_dir_all(&dir));
-        let output = dir.join("error-index.md");
-
-        let _time = util::timeit();
-        build.run(builder.tool_cmd(Tool::ErrorIndex)
-                    .arg("markdown")
-                    .arg(&output)
-                    .env("CFG_BUILD", &build.build)
-                    .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
-
-        markdown_test(builder, compiler, &output);
-    }
-}
-
-fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
-    let build = builder.build;
-    let mut file = t!(File::open(markdown));
-    let mut contents = String::new();
-    t!(file.read_to_string(&mut contents));
-    if !contents.contains("```") {
-        return;
-    }
-
-    println!("doc tests for: {}", markdown.display());
-    let mut cmd = builder.rustdoc_cmd(compiler.host);
-    build.add_rust_test_threads(&mut cmd);
-    cmd.arg("--test");
-    cmd.arg(markdown);
-    cmd.env("RUSTC_BOOTSTRAP", "1");
-
-    let test_args = build.config.cmd.test_args().join(" ");
-    cmd.arg("--test-args").arg(test_args);
-
-    if build.config.quiet_tests {
-        try_run_quiet(build, &mut cmd);
-    } else {
-        try_run(build, &mut cmd);
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct CrateLibrustc {
-    compiler: Compiler,
-    target: Interned<String>,
-    test_kind: TestKind,
-    krate: Option<Interned<String>>,
-}
-
-impl Step for CrateLibrustc {
-    type Output = ();
-    const DEFAULT: bool = true;
-    const ONLY_HOSTS: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.krate("rustc-main")
-    }
-
-    fn make_run(run: RunConfig) {
-        let builder = run.builder;
-        let compiler = builder.compiler(builder.top_stage, run.host);
-
-        let make = |name: Option<Interned<String>>| {
-            let test_kind = if builder.kind == Kind::Test {
-                TestKind::Test
-            } else if builder.kind == Kind::Bench {
-                TestKind::Bench
-            } else {
-                panic!("unexpected builder.kind in crate: {:?}", builder.kind);
-            };
-
-            builder.ensure(CrateLibrustc {
-                compiler,
-                target: run.target,
-                test_kind,
-                krate: name,
-            });
-        };
-
-        if let Some(path) = run.path {
-            for (name, krate_path) in builder.crates("rustc-main") {
-                if path.ends_with(krate_path) {
-                    make(Some(name));
-                }
-            }
-        } else {
-            make(None);
-        }
-    }
-
-
-    fn run(self, builder: &Builder) {
-        builder.ensure(Crate {
-            compiler: self.compiler,
-            target: self.target,
-            mode: Mode::Librustc,
-            test_kind: self.test_kind,
-            krate: self.krate,
+        run.builder.ensure(Rustc {
+            target: run.target,
         });
     }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Crate {
-    compiler: Compiler,
-    target: Interned<String>,
-    mode: Mode,
-    test_kind: TestKind,
-    krate: Option<Interned<String>>,
-}
-
-impl Step for Crate {
-    type Output = ();
-    const DEFAULT: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.krate("std").krate("test")
-    }
 
-    fn make_run(run: RunConfig) {
-        let builder = run.builder;
-        let compiler = builder.compiler(builder.top_stage, run.host);
-
-        let make = |mode: Mode, name: Option<Interned<String>>| {
-            let test_kind = if builder.kind == Kind::Test {
-                TestKind::Test
-            } else if builder.kind == Kind::Bench {
-                TestKind::Bench
-            } else {
-                panic!("unexpected builder.kind in crate: {:?}", builder.kind);
-            };
-
-            builder.ensure(Crate {
-                compiler,
-                target: run.target,
-                mode,
-                test_kind,
-                krate: name,
-            });
-        };
-
-        if let Some(path) = run.path {
-            for (name, krate_path) in builder.crates("std") {
-                if path.ends_with(krate_path) {
-                    make(Mode::Libstd, Some(name));
-                }
-            }
-            for (name, krate_path) in builder.crates("test") {
-                if path.ends_with(krate_path) {
-                    make(Mode::Libtest, Some(name));
-                }
-            }
-        } else {
-            make(Mode::Libstd, None);
-            make(Mode::Libtest, None);
-        }
-    }
-
-    /// Run all unit tests plus documentation tests for an entire crate DAG defined
-    /// by a `Cargo.toml`
-    ///
-    /// This is what runs tests for crates like the standard library, compiler, etc.
-    /// It essentially is the driver for running `cargo test`.
+    /// Build the compiler.
     ///
-    /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
-    /// arguments, and those arguments are discovered from `cargo metadata`.
+    /// This will build the compiler for a particular stage of the build using
+    /// the `compiler` targeting the `target` architecture. The artifacts
+    /// created will also be linked into the sysroot directory.
     fn run(self, builder: &Builder) {
         let build = builder.build;
-        let compiler = self.compiler;
+        let compiler = builder.compiler(0, build.build);
         let target = self.target;
-        let mode = self.mode;
-        let test_kind = self.test_kind;
-        let krate = self.krate;
-
-        builder.ensure(compile::Test { compiler, target });
-        builder.ensure(RemoteCopyLibs { compiler, target });
-
-        // If we're not doing a full bootstrap but we're testing a stage2 version of
-        // libstd, then what we're actually testing is the libstd produced in
-        // stage1. Reflect that here by updating the compiler that we're working
-        // with automatically.
-        let compiler = if build.force_use_stage1(compiler, target) {
-            builder.compiler(1, compiler.host)
-        } else {
-            compiler.clone()
-        };
-
-        let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
-        let (name, root) = match mode {
-            Mode::Libstd => {
-                compile::std_cargo(build, &compiler, target, &mut cargo);
-                ("libstd", "std")
-            }
-            Mode::Libtest => {
-                compile::test_cargo(build, &compiler, target, &mut cargo);
-                ("libtest", "test")
-            }
-            Mode::Librustc => {
-                builder.ensure(compile::Rustc { compiler, target });
-                compile::rustc_cargo(build, target, &mut cargo);
-                ("librustc", "rustc-main")
-            }
-            _ => panic!("can only test libraries"),
-        };
-        let root = INTERNER.intern_string(String::from(root));
-        let _folder = build.fold_output(|| {
-            format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
-        });
-        println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
-                &compiler.host, target);
-
-        // Build up the base `cargo test` command.
-        //
-        // Pass in some standard flags then iterate over the graph we've discovered
-        // in `cargo metadata` with the maps above and figure out what `-p`
-        // arguments need to get passed.
-        if test_kind.subcommand() == "test" && !build.fail_fast {
-            cargo.arg("--no-fail-fast");
-        }
-
-        match krate {
-            Some(krate) => {
-                cargo.arg("-p").arg(krate);
-            }
-            None => {
-                let mut visited = HashSet::new();
-                let mut next = vec![root];
-                while let Some(name) = next.pop() {
-                    // Right now jemalloc and the sanitizer crates are
-                    // target-specific crate in the sense that it's not present
-                    // on all platforms. Custom skip it here for now, but if we
-                    // add more this probably wants to get more generalized.
-                    //
-                    // Also skip `build_helper` as it's not compiled normally
-                    // for target during the bootstrap and it's just meant to be
-                    // a helper crate, not tested. If it leaks through then it
-                    // ends up messing with various mtime calculations and such.
-                    if !name.contains("jemalloc") &&
-                       *name != *"build_helper" &&
-                       !(name.starts_with("rustc_") && name.ends_with("san")) &&
-                       name != "dlmalloc" {
-                        cargo.arg("-p").arg(&format!("{}:0.0.0", name));
-                    }
-                    for dep in build.crates[&name].deps.iter() {
-                        if visited.insert(dep) {
-                            next.push(*dep);
-                        }
-                    }
-                }
-            }
-        }
-
-        // The tests are going to run with the *target* libraries, so we need to
-        // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
-        //
-        // Note that to run the compiler we need to run with the *host* libraries,
-        // but our wrapper scripts arrange for that to be the case anyway.
-        let mut dylib_path = dylib_path();
-        dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
-        cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
 
-        cargo.arg("--");
-        cargo.args(&build.config.cmd.test_args());
+        let _folder = build.fold_output(|| format!("stage{}-rustc", compiler.stage));
+        println!("Checking compiler artifacts ({} -> {})", &compiler.host, target);
 
-        if build.config.quiet_tests {
-            cargo.arg("--quiet");
-        }
+        let stage_out = builder.stage_out(compiler, Mode::Librustc);
+        build.clear_if_dirty(&stage_out, &libstd_stamp(build, compiler, target));
+        build.clear_if_dirty(&stage_out, &libtest_stamp(build, compiler, target));
 
-        let _time = util::timeit();
-
-        if target.contains("emscripten") {
-            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
-                      build.config.nodejs.as_ref().expect("nodejs not configured"));
-        } else if target.starts_with("wasm32") {
-            // On the wasm32-unknown-unknown target we're using LTO which is
-            // incompatible with `-C prefer-dynamic`, so disable that here
-            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
-
-            let node = build.config.nodejs.as_ref()
-                .expect("nodejs not configured");
-            let runner = format!("{} {}/src/etc/wasm32-shim.js",
-                                 node.display(),
-                                 build.src.display());
-            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
-        } else if build.remote_tested(target) {
-            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
-                      format!("{} run",
-                              builder.tool_exe(Tool::RemoteTestClient).display()));
-        }
-        try_run(build, &mut cargo);
+        let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "check");
+        rustc_cargo(build, target, &mut cargo);
+        run_cargo(build,
+                  &mut cargo,
+                  &librustc_stamp(build, compiler, target),
+                  true);
+        let libdir = builder.sysroot_libdir(compiler, target);
+        add_to_sysroot(&libdir, &librustc_stamp(build, compiler, target));
     }
 }
 
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Rustdoc {
-    host: Interned<String>,
-    test_kind: TestKind,
+pub struct Test {
+    pub target: Interned<String>,
 }
 
-impl Step for Rustdoc {
+impl Step for Test {
     type Output = ();
     const DEFAULT: bool = true;
-    const ONLY_HOSTS: bool = true;
 
     fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/librustdoc").path("src/tools/rustdoc")
+        run.path("src/libtest").krate("test")
     }
 
     fn make_run(run: RunConfig) {
-        let builder = run.builder;
-
-        let test_kind = if builder.kind == Kind::Test {
-            TestKind::Test
-        } else if builder.kind == Kind::Bench {
-            TestKind::Bench
-        } else {
-            panic!("unexpected builder.kind in crate: {:?}", builder.kind);
-        };
-
-        builder.ensure(Rustdoc {
-            host: run.host,
-            test_kind,
+        run.builder.ensure(Test {
+            target: run.target,
         });
     }
 
     fn run(self, builder: &Builder) {
         let build = builder.build;
-        let test_kind = self.test_kind;
-
-        let compiler = builder.compiler(builder.top_stage, self.host);
-        let target = compiler.host;
-
-        let mut cargo = tool::prepare_tool_cargo(builder,
-                                                 compiler,
-                                                 target,
-                                                 test_kind.subcommand(),
-                                                 "src/tools/rustdoc");
-        let _folder = build.fold_output(|| {
-            format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
-        });
-        println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
-                &compiler.host, target);
-
-        if test_kind.subcommand() == "test" && !build.fail_fast {
-            cargo.arg("--no-fail-fast");
-        }
-
-        cargo.arg("-p").arg("rustdoc:0.0.0");
-
-        cargo.arg("--");
-        cargo.args(&build.config.cmd.test_args());
-
-        if build.config.quiet_tests {
-            cargo.arg("--quiet");
-        }
-
-        let _time = util::timeit();
+        let target = self.target;
+        let compiler = builder.compiler(0, build.build);
 
-        try_run(build, &mut cargo);
+        let _folder = build.fold_output(|| format!("stage{}-test", compiler.stage));
+        println!("Checking test artifacts ({} -> {})", &compiler.host, target);
+        let out_dir = build.stage_out(compiler, Mode::Libtest);
+        build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target));
+        let mut cargo = builder.cargo(compiler, Mode::Libtest, target, "check");
+        test_cargo(build, &compiler, target, &mut cargo);
+        run_cargo(build,
+                  &mut cargo,
+                  &libtest_stamp(build, compiler, target),
+                  true);
+        let libdir = builder.sysroot_libdir(compiler, target);
+        add_to_sysroot(&libdir, &libtest_stamp(build, compiler, target));
     }
 }
 
-fn envify(s: &str) -> String {
-    s.chars().map(|c| {
-        match c {
-            '-' => '_',
-            c => c,
-        }
-    }).flat_map(|c| c.to_uppercase()).collect()
+/// Cargo's output path for the standard library in a given stage, compiled
+/// by a particular compiler for the specified target.
+pub fn libstd_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
+    build.cargo_out(compiler, Mode::Libstd, target).join(".libstd-check.stamp")
 }
 
-/// Some test suites are run inside emulators or on remote devices, and most
-/// of our test binaries are linked dynamically which means we need to ship
-/// the standard library and such to the emulator ahead of time. This step
-/// represents this and is a dependency of all test suites.
-///
-/// Most of the time this is a noop. For some steps such as shipping data to
-/// QEMU we have to build our own tools so we've got conditional dependencies
-/// on those programs as well. Note that the remote test client is built for
-/// the build target (us) and the server is built for the target.
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct RemoteCopyLibs {
-    compiler: Compiler,
-    target: Interned<String>,
+/// Cargo's output path for libtest in a given stage, compiled by a particular
+/// compiler for the specified target.
+pub fn libtest_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
+    build.cargo_out(compiler, Mode::Libtest, target).join(".libtest-check.stamp")
 }
 
-impl Step for RemoteCopyLibs {
-    type Output = ();
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.never()
-    }
-
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let compiler = self.compiler;
-        let target = self.target;
-        if !build.remote_tested(target) {
-            return
-        }
-
-        builder.ensure(compile::Test { compiler, target });
-
-        println!("REMOTE copy libs to emulator ({})", target);
-        t!(fs::create_dir_all(build.out.join("tmp")));
-
-        let server = builder.ensure(tool::RemoteTestServer { compiler, target });
-
-        // Spawn the emulator and wait for it to come online
-        let tool = builder.tool_exe(Tool::RemoteTestClient);
-        let mut cmd = Command::new(&tool);
-        cmd.arg("spawn-emulator")
-           .arg(target)
-           .arg(&server)
-           .arg(build.out.join("tmp"));
-        if let Some(rootfs) = build.qemu_rootfs(target) {
-            cmd.arg(rootfs);
-        }
-        build.run(&mut cmd);
-
-        // Push all our dylibs to the emulator
-        for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
-            let f = t!(f);
-            let name = f.file_name().into_string().unwrap();
-            if util::is_dylib(&name) {
-                build.run(Command::new(&tool)
-                                  .arg("push")
-                                  .arg(f.path()));
-            }
-        }
-    }
+/// Cargo's output path for librustc in a given stage, compiled by a particular
+/// compiler for the specified target.
+pub fn librustc_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
+    build.cargo_out(compiler, Mode::Librustc, target).join(".librustc-check.stamp")
 }
 
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Distcheck;
-
-impl Step for Distcheck {
-    type Output = ();
-    const ONLY_BUILD: bool = true;
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("distcheck")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Distcheck);
-    }
-
-    /// Run "distcheck", a 'make check' from a tarball
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-
-        println!("Distcheck");
-        let dir = build.out.join("tmp").join("distcheck");
-        let _ = fs::remove_dir_all(&dir);
-        t!(fs::create_dir_all(&dir));
-
-        // Guarantee that these are built before we begin running.
-        builder.ensure(dist::PlainSourceTarball);
-        builder.ensure(dist::Src);
-
-        let mut cmd = Command::new("tar");
-        cmd.arg("-xzf")
-           .arg(builder.ensure(dist::PlainSourceTarball))
-           .arg("--strip-components=1")
-           .current_dir(&dir);
-        build.run(&mut cmd);
-        build.run(Command::new("./configure")
-                         .args(&build.config.configure_args)
-                         .arg("--enable-vendor")
-                         .current_dir(&dir));
-        build.run(Command::new(build_helper::make(&build.build))
-                         .arg("check")
-                         .current_dir(&dir));
-
-        // Now make sure that rust-src has all of libstd's dependencies
-        println!("Distcheck rust-src");
-        let dir = build.out.join("tmp").join("distcheck-src");
-        let _ = fs::remove_dir_all(&dir);
-        t!(fs::create_dir_all(&dir));
-
-        let mut cmd = Command::new("tar");
-        cmd.arg("-xzf")
-           .arg(builder.ensure(dist::Src))
-           .arg("--strip-components=1")
-           .current_dir(&dir);
-        build.run(&mut cmd);
-
-        let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
-        build.run(Command::new(&build.initial_cargo)
-                         .arg("generate-lockfile")
-                         .arg("--manifest-path")
-                         .arg(&toml)
-                         .current_dir(&dir));
-    }
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Bootstrap;
-
-impl Step for Bootstrap {
-    type Output = ();
-    const DEFAULT: bool = true;
-    const ONLY_HOSTS: bool = true;
-    const ONLY_BUILD: bool = true;
-
-    /// Test the build system itself
-    fn run(self, builder: &Builder) {
-        let build = builder.build;
-        let mut cmd = Command::new(&build.initial_cargo);
-        cmd.arg("test")
-           .current_dir(build.src.join("src/bootstrap"))
-           .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
-           .env("RUSTC_BOOTSTRAP", "1")
-           .env("RUSTC", &build.initial_rustc);
-        if !build.fail_fast {
-            cmd.arg("--no-fail-fast");
-        }
-        cmd.arg("--").args(&build.config.cmd.test_args());
-        try_run(build, &mut cmd);
-    }
-
-    fn should_run(run: ShouldRun) -> ShouldRun {
-        run.path("src/bootstrap")
-    }
-
-    fn make_run(run: RunConfig) {
-        run.builder.ensure(Bootstrap);
-    }
-}
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index c6adfc7ffae..21bbd82dd33 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -108,7 +108,8 @@ impl Step for Std {
         std_cargo(build, &compiler, target, &mut cargo);
         run_cargo(build,
                   &mut cargo,
-                  &libstd_stamp(build, compiler, target));
+                  &libstd_stamp(build, compiler, target),
+                  false);
 
         builder.ensure(StdLink {
             compiler: builder.compiler(compiler.stage, build.build),
@@ -360,7 +361,8 @@ impl Step for Test {
         test_cargo(build, &compiler, target, &mut cargo);
         run_cargo(build,
                   &mut cargo,
-                  &libtest_stamp(build, compiler, target));
+                  &libtest_stamp(build, compiler, target),
+                  false);
 
         builder.ensure(TestLink {
             compiler: builder.compiler(compiler.stage, build.build),
@@ -488,7 +490,8 @@ impl Step for Rustc {
         rustc_cargo(build, target, &mut cargo);
         run_cargo(build,
                   &mut cargo,
-                  &librustc_stamp(build, compiler, target));
+                  &librustc_stamp(build, compiler, target),
+                  false);
 
         builder.ensure(RustcLink {
             compiler: builder.compiler(compiler.stage, build.build),
@@ -755,7 +758,7 @@ impl Step for Assemble {
 ///
 /// For a particular stage this will link the file listed in `stamp` into the
 /// `sysroot_dst` provided.
-fn add_to_sysroot(sysroot_dst: &Path, stamp: &Path) {
+pub fn add_to_sysroot(sysroot_dst: &Path, stamp: &Path) {
     t!(fs::create_dir_all(&sysroot_dst));
     for path in read_stamp_file(stamp) {
         copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
@@ -785,7 +788,7 @@ fn stderr_isatty() -> bool {
     }
 }
 
-fn run_cargo(build: &Build, cargo: &mut Command, stamp: &Path) {
+pub fn run_cargo(build: &Build, cargo: &mut Command, stamp: &Path, is_check: bool) {
     // Instruct Cargo to give us json messages on stdout, critically leaving
     // stderr as piped so we can get those pretty colors.
     cargo.arg("--message-format").arg("json")
@@ -836,7 +839,8 @@ fn run_cargo(build: &Build, cargo: &mut Command, stamp: &Path) {
             // Skip files like executables
             if !filename.ends_with(".rlib") &&
                !filename.ends_with(".lib") &&
-               !is_dylib(&filename) {
+               !is_dylib(&filename) &&
+               !(is_check && filename.ends_with(".rmeta")) {
                 continue
             }
 
diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs
index 0816c4dfe3d..478e496078a 100644
--- a/src/bootstrap/flags.rs
+++ b/src/bootstrap/flags.rs
@@ -48,6 +48,9 @@ pub enum Subcommand {
     Build {
         paths: Vec<PathBuf>,
     },
+    Check {
+        paths: Vec<PathBuf>,
+    },
     Doc {
         paths: Vec<PathBuf>,
     },
@@ -88,6 +91,7 @@ Usage: x.py <subcommand> [options] [<paths>...]
 
 Subcommands:
     build       Compile either the compiler or libraries
+    check       Compile either the compiler or libraries, using cargo check
     test        Build and run some test suites
     bench       Build and run some benchmarks
     doc         Build documentation
@@ -128,6 +132,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
         // there on out.
         let subcommand = args.iter().find(|&s|
             (s == "build")
+            || (s == "check")
             || (s == "test")
             || (s == "bench")
             || (s == "doc")
@@ -218,6 +223,21 @@ Arguments:
     src/libtest and its dependencies.
     Once this is done, build/$ARCH/stage1 contains a usable compiler.");
             }
+            "check" => {
+                subcommand_help.push_str("\n
+Arguments:
+    This subcommand accepts a number of paths to directories to the crates
+    and/or artifacts to compile. For example:
+
+        ./x.py check src/libcore
+        ./x.py check src/libcore src/libproc_macro
+
+    If no arguments are passed then the complete artifacts are compiled: std, test, and rustc. Note
+    also that since we use `cargo check`, by default this will automatically enable incremental
+    compilation, so there's no need to pass it separately, though it won't hurt. We also completely
+    ignore the stage passed, as there's no way to compile in non-stage 0 without actually building
+    the compiler.");
+            }
             "test" => {
                 subcommand_help.push_str("\n
 Arguments:
@@ -286,6 +306,9 @@ Arguments:
             "build" => {
                 Subcommand::Build { paths: paths }
             }
+            "check" => {
+                Subcommand::Check { paths: paths }
+            }
             "test" => {
                 Subcommand::Test {
                     paths,
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 3738828a4ba..a6a5ba67723 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -150,6 +150,7 @@ use util::{exe, libdir, OutputFolder, CiEnv};
 mod cc_detect;
 mod channel;
 mod check;
+mod test;
 mod clean;
 mod compile;
 mod metadata;
@@ -449,12 +450,6 @@ impl Build {
         out
     }
 
-    /// Get the directory for incremental by-products when using the
-    /// given compiler.
-    fn incremental_dir(&self, compiler: Compiler) -> PathBuf {
-        self.out.join(&*compiler.host).join(format!("stage{}-incremental", compiler.stage))
-    }
-
     /// Returns the root directory for all output generated in a particular
     /// stage when running with a particular host compiler.
     ///
@@ -776,7 +771,11 @@ impl Build {
     fn release(&self, num: &str) -> String {
         match &self.config.channel[..] {
             "stable" => num.to_string(),
-            "beta" => format!("{}-beta.{}", num, self.beta_prerelease_version()),
+            "beta" => if self.rust_info.is_git() {
+                format!("{}-beta.{}", num, self.beta_prerelease_version())
+            } else {
+                format!("{}-beta", num)
+            },
             "nightly" => format!("{}-nightly", num),
             _ => format!("{}-dev", num),
         }
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
new file mode 100644
index 00000000000..5faec279438
--- /dev/null
+++ b/src/bootstrap/test.rs
@@ -0,0 +1,1542 @@
+// Copyright 2016 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.
+
+//! Implementation of the test-related targets of the build system.
+//!
+//! This file implements the various regression test suites that we execute on
+//! our CI.
+
+use std::collections::HashSet;
+use std::env;
+use std::ffi::OsString;
+use std::iter;
+use std::fmt;
+use std::fs::{self, File};
+use std::path::{PathBuf, Path};
+use std::process::Command;
+use std::io::Read;
+
+use build_helper::{self, output};
+
+use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
+use cache::{INTERNER, Interned};
+use compile;
+use dist;
+use native;
+use tool::{self, Tool};
+use util::{self, dylib_path, dylib_path_var};
+use {Build, Mode};
+use toolstate::ToolState;
+
+const ADB_TEST_DIR: &str = "/data/tmp/work";
+
+/// The two modes of the test runner; tests or benchmarks.
+#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
+pub enum TestKind {
+    /// Run `cargo test`
+    Test,
+    /// Run `cargo bench`
+    Bench,
+}
+
+impl TestKind {
+    // Return the cargo subcommand for this test kind
+    fn subcommand(self) -> &'static str {
+        match self {
+            TestKind::Test => "test",
+            TestKind::Bench => "bench",
+        }
+    }
+}
+
+impl fmt::Display for TestKind {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.write_str(match *self {
+            TestKind::Test => "Testing",
+            TestKind::Bench => "Benchmarking",
+        })
+    }
+}
+
+fn try_run(build: &Build, cmd: &mut Command) -> bool {
+    if !build.fail_fast {
+        if !build.try_run(cmd) {
+            let mut failures = build.delayed_failures.borrow_mut();
+            failures.push(format!("{:?}", cmd));
+            return false;
+        }
+    } else {
+        build.run(cmd);
+    }
+    true
+}
+
+fn try_run_quiet(build: &Build, cmd: &mut Command) {
+    if !build.fail_fast {
+        if !build.try_run_quiet(cmd) {
+            let mut failures = build.delayed_failures.borrow_mut();
+            failures.push(format!("{:?}", cmd));
+        }
+    } else {
+        build.run_quiet(cmd);
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Linkcheck {
+    host: Interned<String>,
+}
+
+impl Step for Linkcheck {
+    type Output = ();
+    const ONLY_HOSTS: bool = true;
+    const DEFAULT: bool = true;
+
+    /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
+    ///
+    /// This tool in `src/tools` will verify the validity of all our links in the
+    /// documentation to ensure we don't have a bunch of dead ones.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let host = self.host;
+
+        println!("Linkcheck ({})", host);
+
+        builder.default_doc(None);
+
+        let _time = util::timeit();
+        try_run(build, builder.tool_cmd(Tool::Linkchecker)
+                            .arg(build.out.join(host).join("doc")));
+    }
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        let builder = run.builder;
+        run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Linkcheck { host: run.target });
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Cargotest {
+    stage: u32,
+    host: Interned<String>,
+}
+
+impl Step for Cargotest {
+    type Output = ();
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/tools/cargotest")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Cargotest {
+            stage: run.builder.top_stage,
+            host: run.target,
+        });
+    }
+
+    /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
+    ///
+    /// This tool in `src/tools` will check out a few Rust projects and run `cargo
+    /// test` to ensure that we don't regress the test suites there.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let compiler = builder.compiler(self.stage, self.host);
+        builder.ensure(compile::Rustc { compiler, target: compiler.host });
+
+        // Note that this is a short, cryptic, and not scoped directory name. This
+        // is currently to minimize the length of path on Windows where we otherwise
+        // quickly run into path name limit constraints.
+        let out_dir = build.out.join("ct");
+        t!(fs::create_dir_all(&out_dir));
+
+        let _time = util::timeit();
+        let mut cmd = builder.tool_cmd(Tool::CargoTest);
+        try_run(build, cmd.arg(&build.initial_cargo)
+                          .arg(&out_dir)
+                          .env("RUSTC", builder.rustc(compiler))
+                          .env("RUSTDOC", builder.rustdoc(compiler.host)));
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Cargo {
+    stage: u32,
+    host: Interned<String>,
+}
+
+impl Step for Cargo {
+    type Output = ();
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/tools/cargo")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Cargo {
+            stage: run.builder.top_stage,
+            host: run.target,
+        });
+    }
+
+    /// Runs `cargo test` for `cargo` packaged with Rust.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let compiler = builder.compiler(self.stage, self.host);
+
+        builder.ensure(tool::Cargo { compiler, target: self.host });
+        let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
+        cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
+        if !build.fail_fast {
+            cargo.arg("--no-fail-fast");
+        }
+
+        // Don't build tests dynamically, just a pain to work with
+        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
+
+        // Don't run cross-compile tests, we may not have cross-compiled libstd libs
+        // available.
+        cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
+
+        try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Rls {
+    stage: u32,
+    host: Interned<String>,
+}
+
+impl Step for Rls {
+    type Output = ();
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/tools/rls")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Rls {
+            stage: run.builder.top_stage,
+            host: run.target,
+        });
+    }
+
+    /// Runs `cargo test` for the rls.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let stage = self.stage;
+        let host = self.host;
+        let compiler = builder.compiler(stage, host);
+
+        builder.ensure(tool::Rls { compiler, target: self.host });
+        let mut cargo = tool::prepare_tool_cargo(builder,
+                                                 compiler,
+                                                 host,
+                                                 "test",
+                                                 "src/tools/rls");
+
+        // Don't build tests dynamically, just a pain to work with
+        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
+
+        builder.add_rustc_lib_path(compiler, &mut cargo);
+
+        if try_run(build, &mut cargo) {
+            build.save_toolstate("rls", ToolState::TestPass);
+        }
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Rustfmt {
+    stage: u32,
+    host: Interned<String>,
+}
+
+impl Step for Rustfmt {
+    type Output = ();
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/tools/rustfmt")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Rustfmt {
+            stage: run.builder.top_stage,
+            host: run.target,
+        });
+    }
+
+    /// Runs `cargo test` for rustfmt.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let stage = self.stage;
+        let host = self.host;
+        let compiler = builder.compiler(stage, host);
+
+        builder.ensure(tool::Rustfmt { compiler, target: self.host });
+        let mut cargo = tool::prepare_tool_cargo(builder,
+                                                 compiler,
+                                                 host,
+                                                 "test",
+                                                 "src/tools/rustfmt");
+
+        // Don't build tests dynamically, just a pain to work with
+        cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
+
+        builder.add_rustc_lib_path(compiler, &mut cargo);
+
+        if try_run(build, &mut cargo) {
+            build.save_toolstate("rustfmt", ToolState::TestPass);
+        }
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Miri {
+    stage: u32,
+    host: Interned<String>,
+}
+
+impl Step for Miri {
+    type Output = ();
+    const ONLY_HOSTS: bool = true;
+    const DEFAULT: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        let test_miri = run.builder.build.config.test_miri;
+        run.path("src/tools/miri").default_condition(test_miri)
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Miri {
+            stage: run.builder.top_stage,
+            host: run.target,
+        });
+    }
+
+    /// Runs `cargo test` for miri.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let stage = self.stage;
+        let host = self.host;
+        let compiler = builder.compiler(stage, host);
+
+        if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
+            let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
+            cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
+
+            // Don't build tests dynamically, just a pain to work with
+            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
+            // miri tests need to know about the stage sysroot
+            cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
+            cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
+            cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
+            cargo.env("MIRI_PATH", miri);
+
+            builder.add_rustc_lib_path(compiler, &mut cargo);
+
+            if try_run(build, &mut cargo) {
+                build.save_toolstate("miri", ToolState::TestPass);
+            }
+        } else {
+            eprintln!("failed to test miri: could not build");
+        }
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Clippy {
+    stage: u32,
+    host: Interned<String>,
+}
+
+impl Step for Clippy {
+    type Output = ();
+    const ONLY_HOSTS: bool = true;
+    const DEFAULT: bool = false;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/tools/clippy")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Clippy {
+            stage: run.builder.top_stage,
+            host: run.target,
+        });
+    }
+
+    /// Runs `cargo test` for clippy.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let stage = self.stage;
+        let host = self.host;
+        let compiler = builder.compiler(stage, host);
+
+        if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
+            let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
+            cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
+
+            // Don't build tests dynamically, just a pain to work with
+            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
+            // clippy tests need to know about the stage sysroot
+            cargo.env("SYSROOT", builder.sysroot(compiler));
+            cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
+            cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
+            let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir());
+            cargo.env("HOST_LIBS", host_libs);
+            // clippy tests need to find the driver
+            cargo.env("CLIPPY_DRIVER_PATH", clippy);
+
+            builder.add_rustc_lib_path(compiler, &mut cargo);
+
+            if try_run(build, &mut cargo) {
+                build.save_toolstate("clippy-driver", ToolState::TestPass);
+            }
+        } else {
+            eprintln!("failed to test clippy: could not build");
+        }
+    }
+}
+
+fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
+    // Configure PATH to find the right rustc. NB. we have to use PATH
+    // and not RUSTC because the Cargo test suite has tests that will
+    // fail if rustc is not spelled `rustc`.
+    let path = builder.sysroot(compiler).join("bin");
+    let old_path = env::var_os("PATH").unwrap_or_default();
+    env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
+}
+
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct RustdocJS {
+    pub host: Interned<String>,
+    pub target: Interned<String>,
+}
+
+impl Step for RustdocJS {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/test/rustdoc-js")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(RustdocJS {
+            host: run.host,
+            target: run.target,
+        });
+    }
+
+    fn run(self, builder: &Builder) {
+        if let Some(ref nodejs) = builder.config.nodejs {
+            let mut command = Command::new(nodejs);
+            command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
+            builder.ensure(::doc::Std {
+                target: self.target,
+                stage: builder.top_stage,
+            });
+            builder.run(&mut command);
+        } else {
+            println!("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
+        }
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Tidy {
+    host: Interned<String>,
+}
+
+impl Step for Tidy {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+    const ONLY_BUILD: bool = true;
+
+    /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
+    ///
+    /// This tool in `src/tools` checks up on various bits and pieces of style and
+    /// otherwise just implements a few lint-like checks that are specific to the
+    /// compiler itself.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let host = self.host;
+
+        let _folder = build.fold_output(|| "tidy");
+        println!("tidy check ({})", host);
+        let mut cmd = builder.tool_cmd(Tool::Tidy);
+        cmd.arg(build.src.join("src"));
+        if !build.config.vendor {
+            cmd.arg("--no-vendor");
+        }
+        if build.config.quiet_tests {
+            cmd.arg("--quiet");
+        }
+        try_run(build, &mut cmd);
+    }
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/tools/tidy")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Tidy {
+            host: run.builder.build.build,
+        });
+    }
+}
+
+fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
+    build.out.join(host).join("test")
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+struct Test {
+    path: &'static str,
+    mode: &'static str,
+    suite: &'static str,
+}
+
+static DEFAULT_COMPILETESTS: &[Test] = &[
+    Test { path: "src/test/ui", mode: "ui", suite: "ui" },
+    Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
+    Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
+    Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
+    Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
+    Test {
+        path: "src/test/run-pass-valgrind",
+        mode: "run-pass-valgrind",
+        suite: "run-pass-valgrind"
+    },
+    Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
+    Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
+    Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
+    Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
+
+    // What this runs varies depending on the native platform being apple
+    Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
+];
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct DefaultCompiletest {
+    compiler: Compiler,
+    target: Interned<String>,
+    mode: &'static str,
+    suite: &'static str,
+}
+
+impl Step for DefaultCompiletest {
+    type Output = ();
+    const DEFAULT: bool = true;
+
+    fn should_run(mut run: ShouldRun) -> ShouldRun {
+        for test in DEFAULT_COMPILETESTS {
+            run = run.path(test.path);
+        }
+        run
+    }
+
+    fn make_run(run: RunConfig) {
+        let compiler = run.builder.compiler(run.builder.top_stage, run.host);
+
+        let test = run.path.map(|path| {
+            DEFAULT_COMPILETESTS.iter().find(|&&test| {
+                path.ends_with(test.path)
+            }).unwrap_or_else(|| {
+                panic!("make_run in compile test to receive test path, received {:?}", path);
+            })
+        });
+
+        if let Some(test) = test {
+            run.builder.ensure(DefaultCompiletest {
+                compiler,
+                target: run.target,
+                mode: test.mode,
+                suite: test.suite,
+            });
+        } else {
+            for test in DEFAULT_COMPILETESTS {
+                run.builder.ensure(DefaultCompiletest {
+                    compiler,
+                    target: run.target,
+                    mode: test.mode,
+                    suite: test.suite
+                });
+            }
+        }
+    }
+
+    fn run(self, builder: &Builder) {
+        builder.ensure(Compiletest {
+            compiler: self.compiler,
+            target: self.target,
+            mode: self.mode,
+            suite: self.suite,
+        })
+    }
+}
+
+// Also default, but host-only.
+static HOST_COMPILETESTS: &[Test] = &[
+    Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
+    Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
+    Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
+    Test {
+        path: "src/test/compile-fail-fulldeps",
+        mode: "compile-fail",
+        suite: "compile-fail-fulldeps",
+    },
+    Test {
+        path: "src/test/incremental-fulldeps",
+        mode: "incremental",
+        suite: "incremental-fulldeps",
+    },
+    Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
+    Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
+
+    Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
+    Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
+    Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
+    Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
+    Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
+    Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
+];
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct HostCompiletest {
+    compiler: Compiler,
+    target: Interned<String>,
+    mode: &'static str,
+    suite: &'static str,
+}
+
+impl Step for HostCompiletest {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(mut run: ShouldRun) -> ShouldRun {
+        for test in HOST_COMPILETESTS {
+            run = run.path(test.path);
+        }
+        run
+    }
+
+    fn make_run(run: RunConfig) {
+        let compiler = run.builder.compiler(run.builder.top_stage, run.host);
+
+        let test = run.path.map(|path| {
+            HOST_COMPILETESTS.iter().find(|&&test| {
+                path.ends_with(test.path)
+            }).unwrap_or_else(|| {
+                panic!("make_run in compile test to receive test path, received {:?}", path);
+            })
+        });
+
+        if let Some(test) = test {
+            run.builder.ensure(HostCompiletest {
+                compiler,
+                target: run.target,
+                mode: test.mode,
+                suite: test.suite,
+            });
+        } else {
+            for test in HOST_COMPILETESTS {
+                if test.mode == "pretty" {
+                    continue;
+                }
+                run.builder.ensure(HostCompiletest {
+                    compiler,
+                    target: run.target,
+                    mode: test.mode,
+                    suite: test.suite
+                });
+            }
+        }
+    }
+
+    fn run(self, builder: &Builder) {
+        builder.ensure(Compiletest {
+            compiler: self.compiler,
+            target: self.target,
+            mode: self.mode,
+            suite: self.suite,
+        })
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+struct Compiletest {
+    compiler: Compiler,
+    target: Interned<String>,
+    mode: &'static str,
+    suite: &'static str,
+}
+
+impl Step for Compiletest {
+    type Output = ();
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.never()
+    }
+
+    /// Executes the `compiletest` tool to run a suite of tests.
+    ///
+    /// Compiles all tests with `compiler` for `target` with the specified
+    /// compiletest `mode` and `suite` arguments. For example `mode` can be
+    /// "run-pass" or `suite` can be something like `debuginfo`.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let compiler = self.compiler;
+        let target = self.target;
+        let mode = self.mode;
+        let suite = self.suite;
+
+        // Skip codegen tests if they aren't enabled in configuration.
+        if !build.config.codegen_tests && suite == "codegen" {
+            return;
+        }
+
+        if suite == "debuginfo" {
+            // Skip debuginfo tests on MSVC
+            if build.build.contains("msvc") {
+                return;
+            }
+
+            if mode == "debuginfo-XXX" {
+                return if build.build.contains("apple") {
+                    builder.ensure(Compiletest {
+                        mode: "debuginfo-lldb",
+                        ..self
+                    });
+                } else {
+                    builder.ensure(Compiletest {
+                        mode: "debuginfo-gdb",
+                        ..self
+                    });
+                };
+            }
+
+            builder.ensure(dist::DebuggerScripts {
+                sysroot: builder.sysroot(compiler),
+                host: target
+            });
+        }
+
+        if suite.ends_with("fulldeps") ||
+            // FIXME: Does pretty need librustc compiled? Note that there are
+            // fulldeps test suites with mode = pretty as well.
+            mode == "pretty" ||
+            mode == "rustdoc" ||
+            mode == "run-make" {
+            builder.ensure(compile::Rustc { compiler, target });
+        }
+
+        builder.ensure(compile::Test { compiler, target });
+        builder.ensure(native::TestHelpers { target });
+        builder.ensure(RemoteCopyLibs { compiler, target });
+
+        let _folder = build.fold_output(|| format!("test_{}", suite));
+        println!("Check compiletest suite={} mode={} ({} -> {})",
+                 suite, mode, &compiler.host, target);
+        let mut cmd = builder.tool_cmd(Tool::Compiletest);
+
+        // compiletest currently has... a lot of arguments, so let's just pass all
+        // of them!
+
+        cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
+        cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
+        cmd.arg("--rustc-path").arg(builder.rustc(compiler));
+
+        // Avoid depending on rustdoc when we don't need it.
+        if mode == "rustdoc" || mode == "run-make" {
+            cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
+        }
+
+        cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
+        cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
+        cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
+        cmd.arg("--mode").arg(mode);
+        cmd.arg("--target").arg(target);
+        cmd.arg("--host").arg(&*compiler.host);
+        cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
+
+        if let Some(ref nodejs) = build.config.nodejs {
+            cmd.arg("--nodejs").arg(nodejs);
+        }
+
+        let mut flags = vec!["-Crpath".to_string()];
+        if build.config.rust_optimize_tests {
+            flags.push("-O".to_string());
+        }
+        if build.config.rust_debuginfo_tests {
+            flags.push("-g".to_string());
+        }
+        flags.push("-Zmiri -Zunstable-options".to_string());
+        flags.push(build.config.cmd.rustc_args().join(" "));
+
+        if let Some(linker) = build.linker(target) {
+            cmd.arg("--linker").arg(linker);
+        }
+
+        let hostflags = flags.clone();
+        cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
+
+        let mut targetflags = flags.clone();
+        targetflags.push(format!("-Lnative={}",
+                                 build.test_helpers_out(target).display()));
+        cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
+
+        cmd.arg("--docck-python").arg(build.python());
+
+        if build.build.ends_with("apple-darwin") {
+            // Force /usr/bin/python on macOS for LLDB tests because we're loading the
+            // LLDB plugin's compiled module which only works with the system python
+            // (namely not Homebrew-installed python)
+            cmd.arg("--lldb-python").arg("/usr/bin/python");
+        } else {
+            cmd.arg("--lldb-python").arg(build.python());
+        }
+
+        if let Some(ref gdb) = build.config.gdb {
+            cmd.arg("--gdb").arg(gdb);
+        }
+        if let Some(ref vers) = build.lldb_version {
+            cmd.arg("--lldb-version").arg(vers);
+        }
+        if let Some(ref dir) = build.lldb_python_dir {
+            cmd.arg("--lldb-python-dir").arg(dir);
+        }
+
+        cmd.args(&build.config.cmd.test_args());
+
+        if build.is_verbose() {
+            cmd.arg("--verbose");
+        }
+
+        if build.config.quiet_tests {
+            cmd.arg("--quiet");
+        }
+
+        if build.config.llvm_enabled {
+            let llvm_config = build.llvm_config(target);
+            let llvm_version = output(Command::new(&llvm_config).arg("--version"));
+            cmd.arg("--llvm-version").arg(llvm_version);
+            if !build.is_rust_llvm(target) {
+                cmd.arg("--system-llvm");
+            }
+
+            // Only pass correct values for these flags for the `run-make` suite as it
+            // requires that a C++ compiler was configured which isn't always the case.
+            if suite == "run-make" {
+                let llvm_components = output(Command::new(&llvm_config).arg("--components"));
+                let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
+                cmd.arg("--cc").arg(build.cc(target))
+                .arg("--cxx").arg(build.cxx(target).unwrap())
+                .arg("--cflags").arg(build.cflags(target).join(" "))
+                .arg("--llvm-components").arg(llvm_components.trim())
+                .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
+                if let Some(ar) = build.ar(target) {
+                    cmd.arg("--ar").arg(ar);
+                }
+            }
+        }
+        if suite == "run-make" && !build.config.llvm_enabled {
+            println!("Ignoring run-make test suite as they generally dont work without LLVM");
+            return;
+        }
+
+        if suite != "run-make" {
+            cmd.arg("--cc").arg("")
+               .arg("--cxx").arg("")
+               .arg("--cflags").arg("")
+               .arg("--llvm-components").arg("")
+               .arg("--llvm-cxxflags").arg("");
+        }
+
+        if build.remote_tested(target) {
+            cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
+        }
+
+        // Running a C compiler on MSVC requires a few env vars to be set, to be
+        // sure to set them here.
+        //
+        // Note that if we encounter `PATH` we make sure to append to our own `PATH`
+        // rather than stomp over it.
+        if target.contains("msvc") {
+            for &(ref k, ref v) in build.cc[&target].env() {
+                if k != "PATH" {
+                    cmd.env(k, v);
+                }
+            }
+        }
+        cmd.env("RUSTC_BOOTSTRAP", "1");
+        build.add_rust_test_threads(&mut cmd);
+
+        if build.config.sanitizers {
+            cmd.env("SANITIZER_SUPPORT", "1");
+        }
+
+        if build.config.profiler {
+            cmd.env("PROFILER_SUPPORT", "1");
+        }
+
+        cmd.arg("--adb-path").arg("adb");
+        cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
+        if target.contains("android") {
+            // Assume that cc for this target comes from the android sysroot
+            cmd.arg("--android-cross-path")
+               .arg(build.cc(target).parent().unwrap().parent().unwrap());
+        } else {
+            cmd.arg("--android-cross-path").arg("");
+        }
+
+        build.ci_env.force_coloring_in_ci(&mut cmd);
+
+        let _time = util::timeit();
+        try_run(build, &mut cmd);
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Docs {
+    compiler: Compiler,
+}
+
+impl Step for Docs {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/doc")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Docs {
+            compiler: run.builder.compiler(run.builder.top_stage, run.host),
+        });
+    }
+
+    /// Run `rustdoc --test` for all documentation in `src/doc`.
+    ///
+    /// This will run all tests in our markdown documentation (e.g. the book)
+    /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
+    /// `compiler`.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let compiler = self.compiler;
+
+        builder.ensure(compile::Test { compiler, target: compiler.host });
+
+        // Do a breadth-first traversal of the `src/doc` directory and just run
+        // tests for all files that end in `*.md`
+        let mut stack = vec![build.src.join("src/doc")];
+        let _time = util::timeit();
+        let _folder = build.fold_output(|| "test_docs");
+
+        while let Some(p) = stack.pop() {
+            if p.is_dir() {
+                stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
+                continue
+            }
+
+            if p.extension().and_then(|s| s.to_str()) != Some("md") {
+                continue;
+            }
+
+            // The nostarch directory in the book is for no starch, and so isn't
+            // guaranteed to build. We don't care if it doesn't build, so skip it.
+            if p.to_str().map_or(false, |p| p.contains("nostarch")) {
+                continue;
+            }
+
+            markdown_test(builder, compiler, &p);
+        }
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct ErrorIndex {
+    compiler: Compiler,
+}
+
+impl Step for ErrorIndex {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/tools/error_index_generator")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(ErrorIndex {
+            compiler: run.builder.compiler(run.builder.top_stage, run.host),
+        });
+    }
+
+    /// Run the error index generator tool to execute the tests located in the error
+    /// index.
+    ///
+    /// The `error_index_generator` tool lives in `src/tools` and is used to
+    /// generate a markdown file from the error indexes of the code base which is
+    /// then passed to `rustdoc --test`.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let compiler = self.compiler;
+
+        builder.ensure(compile::Std { compiler, target: compiler.host });
+
+        let _folder = build.fold_output(|| "test_error_index");
+        println!("Testing error-index stage{}", compiler.stage);
+
+        let dir = testdir(build, compiler.host);
+        t!(fs::create_dir_all(&dir));
+        let output = dir.join("error-index.md");
+
+        let _time = util::timeit();
+        build.run(builder.tool_cmd(Tool::ErrorIndex)
+                    .arg("markdown")
+                    .arg(&output)
+                    .env("CFG_BUILD", &build.build)
+                    .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
+
+        markdown_test(builder, compiler, &output);
+    }
+}
+
+fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
+    let build = builder.build;
+    let mut file = t!(File::open(markdown));
+    let mut contents = String::new();
+    t!(file.read_to_string(&mut contents));
+    if !contents.contains("```") {
+        return;
+    }
+
+    println!("doc tests for: {}", markdown.display());
+    let mut cmd = builder.rustdoc_cmd(compiler.host);
+    build.add_rust_test_threads(&mut cmd);
+    cmd.arg("--test");
+    cmd.arg(markdown);
+    cmd.env("RUSTC_BOOTSTRAP", "1");
+
+    let test_args = build.config.cmd.test_args().join(" ");
+    cmd.arg("--test-args").arg(test_args);
+
+    if build.config.quiet_tests {
+        try_run_quiet(build, &mut cmd);
+    } else {
+        try_run(build, &mut cmd);
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct CrateLibrustc {
+    compiler: Compiler,
+    target: Interned<String>,
+    test_kind: TestKind,
+    krate: Option<Interned<String>>,
+}
+
+impl Step for CrateLibrustc {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.krate("rustc-main")
+    }
+
+    fn make_run(run: RunConfig) {
+        let builder = run.builder;
+        let compiler = builder.compiler(builder.top_stage, run.host);
+
+        let make = |name: Option<Interned<String>>| {
+            let test_kind = if builder.kind == Kind::Test {
+                TestKind::Test
+            } else if builder.kind == Kind::Bench {
+                TestKind::Bench
+            } else {
+                panic!("unexpected builder.kind in crate: {:?}", builder.kind);
+            };
+
+            builder.ensure(CrateLibrustc {
+                compiler,
+                target: run.target,
+                test_kind,
+                krate: name,
+            });
+        };
+
+        if let Some(path) = run.path {
+            for (name, krate_path) in builder.crates("rustc-main") {
+                if path.ends_with(krate_path) {
+                    make(Some(name));
+                }
+            }
+        } else {
+            make(None);
+        }
+    }
+
+
+    fn run(self, builder: &Builder) {
+        builder.ensure(Crate {
+            compiler: self.compiler,
+            target: self.target,
+            mode: Mode::Librustc,
+            test_kind: self.test_kind,
+            krate: self.krate,
+        });
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Crate {
+    compiler: Compiler,
+    target: Interned<String>,
+    mode: Mode,
+    test_kind: TestKind,
+    krate: Option<Interned<String>>,
+}
+
+impl Step for Crate {
+    type Output = ();
+    const DEFAULT: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.krate("std").krate("test")
+    }
+
+    fn make_run(run: RunConfig) {
+        let builder = run.builder;
+        let compiler = builder.compiler(builder.top_stage, run.host);
+
+        let make = |mode: Mode, name: Option<Interned<String>>| {
+            let test_kind = if builder.kind == Kind::Test {
+                TestKind::Test
+            } else if builder.kind == Kind::Bench {
+                TestKind::Bench
+            } else {
+                panic!("unexpected builder.kind in crate: {:?}", builder.kind);
+            };
+
+            builder.ensure(Crate {
+                compiler,
+                target: run.target,
+                mode,
+                test_kind,
+                krate: name,
+            });
+        };
+
+        if let Some(path) = run.path {
+            for (name, krate_path) in builder.crates("std") {
+                if path.ends_with(krate_path) {
+                    make(Mode::Libstd, Some(name));
+                }
+            }
+            for (name, krate_path) in builder.crates("test") {
+                if path.ends_with(krate_path) {
+                    make(Mode::Libtest, Some(name));
+                }
+            }
+        } else {
+            make(Mode::Libstd, None);
+            make(Mode::Libtest, None);
+        }
+    }
+
+    /// Run all unit tests plus documentation tests for an entire crate DAG defined
+    /// by a `Cargo.toml`
+    ///
+    /// This is what runs tests for crates like the standard library, compiler, etc.
+    /// It essentially is the driver for running `cargo test`.
+    ///
+    /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
+    /// arguments, and those arguments are discovered from `cargo metadata`.
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let compiler = self.compiler;
+        let target = self.target;
+        let mode = self.mode;
+        let test_kind = self.test_kind;
+        let krate = self.krate;
+
+        builder.ensure(compile::Test { compiler, target });
+        builder.ensure(RemoteCopyLibs { compiler, target });
+
+        // If we're not doing a full bootstrap but we're testing a stage2 version of
+        // libstd, then what we're actually testing is the libstd produced in
+        // stage1. Reflect that here by updating the compiler that we're working
+        // with automatically.
+        let compiler = if build.force_use_stage1(compiler, target) {
+            builder.compiler(1, compiler.host)
+        } else {
+            compiler.clone()
+        };
+
+        let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
+        let (name, root) = match mode {
+            Mode::Libstd => {
+                compile::std_cargo(build, &compiler, target, &mut cargo);
+                ("libstd", "std")
+            }
+            Mode::Libtest => {
+                compile::test_cargo(build, &compiler, target, &mut cargo);
+                ("libtest", "test")
+            }
+            Mode::Librustc => {
+                builder.ensure(compile::Rustc { compiler, target });
+                compile::rustc_cargo(build, target, &mut cargo);
+                ("librustc", "rustc-main")
+            }
+            _ => panic!("can only test libraries"),
+        };
+        let root = INTERNER.intern_string(String::from(root));
+        let _folder = build.fold_output(|| {
+            format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
+        });
+        println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
+                &compiler.host, target);
+
+        // Build up the base `cargo test` command.
+        //
+        // Pass in some standard flags then iterate over the graph we've discovered
+        // in `cargo metadata` with the maps above and figure out what `-p`
+        // arguments need to get passed.
+        if test_kind.subcommand() == "test" && !build.fail_fast {
+            cargo.arg("--no-fail-fast");
+        }
+
+        match krate {
+            Some(krate) => {
+                cargo.arg("-p").arg(krate);
+            }
+            None => {
+                let mut visited = HashSet::new();
+                let mut next = vec![root];
+                while let Some(name) = next.pop() {
+                    // Right now jemalloc and the sanitizer crates are
+                    // target-specific crate in the sense that it's not present
+                    // on all platforms. Custom skip it here for now, but if we
+                    // add more this probably wants to get more generalized.
+                    //
+                    // Also skip `build_helper` as it's not compiled normally
+                    // for target during the bootstrap and it's just meant to be
+                    // a helper crate, not tested. If it leaks through then it
+                    // ends up messing with various mtime calculations and such.
+                    if !name.contains("jemalloc") &&
+                       *name != *"build_helper" &&
+                       !(name.starts_with("rustc_") && name.ends_with("san")) &&
+                       name != "dlmalloc" {
+                        cargo.arg("-p").arg(&format!("{}:0.0.0", name));
+                    }
+                    for dep in build.crates[&name].deps.iter() {
+                        if visited.insert(dep) {
+                            next.push(*dep);
+                        }
+                    }
+                }
+            }
+        }
+
+        // The tests are going to run with the *target* libraries, so we need to
+        // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
+        //
+        // Note that to run the compiler we need to run with the *host* libraries,
+        // but our wrapper scripts arrange for that to be the case anyway.
+        let mut dylib_path = dylib_path();
+        dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
+        cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
+
+        cargo.arg("--");
+        cargo.args(&build.config.cmd.test_args());
+
+        if build.config.quiet_tests {
+            cargo.arg("--quiet");
+        }
+
+        let _time = util::timeit();
+
+        if target.contains("emscripten") {
+            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
+                      build.config.nodejs.as_ref().expect("nodejs not configured"));
+        } else if target.starts_with("wasm32") {
+            // On the wasm32-unknown-unknown target we're using LTO which is
+            // incompatible with `-C prefer-dynamic`, so disable that here
+            cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
+
+            let node = build.config.nodejs.as_ref()
+                .expect("nodejs not configured");
+            let runner = format!("{} {}/src/etc/wasm32-shim.js",
+                                 node.display(),
+                                 build.src.display());
+            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
+        } else if build.remote_tested(target) {
+            cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
+                      format!("{} run",
+                              builder.tool_exe(Tool::RemoteTestClient).display()));
+        }
+        try_run(build, &mut cargo);
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Rustdoc {
+    host: Interned<String>,
+    test_kind: TestKind,
+}
+
+impl Step for Rustdoc {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/librustdoc").path("src/tools/rustdoc")
+    }
+
+    fn make_run(run: RunConfig) {
+        let builder = run.builder;
+
+        let test_kind = if builder.kind == Kind::Test {
+            TestKind::Test
+        } else if builder.kind == Kind::Bench {
+            TestKind::Bench
+        } else {
+            panic!("unexpected builder.kind in crate: {:?}", builder.kind);
+        };
+
+        builder.ensure(Rustdoc {
+            host: run.host,
+            test_kind,
+        });
+    }
+
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let test_kind = self.test_kind;
+
+        let compiler = builder.compiler(builder.top_stage, self.host);
+        let target = compiler.host;
+
+        let mut cargo = tool::prepare_tool_cargo(builder,
+                                                 compiler,
+                                                 target,
+                                                 test_kind.subcommand(),
+                                                 "src/tools/rustdoc");
+        let _folder = build.fold_output(|| {
+            format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
+        });
+        println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
+                &compiler.host, target);
+
+        if test_kind.subcommand() == "test" && !build.fail_fast {
+            cargo.arg("--no-fail-fast");
+        }
+
+        cargo.arg("-p").arg("rustdoc:0.0.0");
+
+        cargo.arg("--");
+        cargo.args(&build.config.cmd.test_args());
+
+        if build.config.quiet_tests {
+            cargo.arg("--quiet");
+        }
+
+        let _time = util::timeit();
+
+        try_run(build, &mut cargo);
+    }
+}
+
+fn envify(s: &str) -> String {
+    s.chars().map(|c| {
+        match c {
+            '-' => '_',
+            c => c,
+        }
+    }).flat_map(|c| c.to_uppercase()).collect()
+}
+
+/// Some test suites are run inside emulators or on remote devices, and most
+/// of our test binaries are linked dynamically which means we need to ship
+/// the standard library and such to the emulator ahead of time. This step
+/// represents this and is a dependency of all test suites.
+///
+/// Most of the time this is a noop. For some steps such as shipping data to
+/// QEMU we have to build our own tools so we've got conditional dependencies
+/// on those programs as well. Note that the remote test client is built for
+/// the build target (us) and the server is built for the target.
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct RemoteCopyLibs {
+    compiler: Compiler,
+    target: Interned<String>,
+}
+
+impl Step for RemoteCopyLibs {
+    type Output = ();
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.never()
+    }
+
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let compiler = self.compiler;
+        let target = self.target;
+        if !build.remote_tested(target) {
+            return
+        }
+
+        builder.ensure(compile::Test { compiler, target });
+
+        println!("REMOTE copy libs to emulator ({})", target);
+        t!(fs::create_dir_all(build.out.join("tmp")));
+
+        let server = builder.ensure(tool::RemoteTestServer { compiler, target });
+
+        // Spawn the emulator and wait for it to come online
+        let tool = builder.tool_exe(Tool::RemoteTestClient);
+        let mut cmd = Command::new(&tool);
+        cmd.arg("spawn-emulator")
+           .arg(target)
+           .arg(&server)
+           .arg(build.out.join("tmp"));
+        if let Some(rootfs) = build.qemu_rootfs(target) {
+            cmd.arg(rootfs);
+        }
+        build.run(&mut cmd);
+
+        // Push all our dylibs to the emulator
+        for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
+            let f = t!(f);
+            let name = f.file_name().into_string().unwrap();
+            if util::is_dylib(&name) {
+                build.run(Command::new(&tool)
+                                  .arg("push")
+                                  .arg(f.path()));
+            }
+        }
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Distcheck;
+
+impl Step for Distcheck {
+    type Output = ();
+    const ONLY_BUILD: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("distcheck")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Distcheck);
+    }
+
+    /// Run "distcheck", a 'make check' from a tarball
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+
+        println!("Distcheck");
+        let dir = build.out.join("tmp").join("distcheck");
+        let _ = fs::remove_dir_all(&dir);
+        t!(fs::create_dir_all(&dir));
+
+        // Guarantee that these are built before we begin running.
+        builder.ensure(dist::PlainSourceTarball);
+        builder.ensure(dist::Src);
+
+        let mut cmd = Command::new("tar");
+        cmd.arg("-xzf")
+           .arg(builder.ensure(dist::PlainSourceTarball))
+           .arg("--strip-components=1")
+           .current_dir(&dir);
+        build.run(&mut cmd);
+        build.run(Command::new("./configure")
+                         .args(&build.config.configure_args)
+                         .arg("--enable-vendor")
+                         .current_dir(&dir));
+        build.run(Command::new(build_helper::make(&build.build))
+                         .arg("check")
+                         .current_dir(&dir));
+
+        // Now make sure that rust-src has all of libstd's dependencies
+        println!("Distcheck rust-src");
+        let dir = build.out.join("tmp").join("distcheck-src");
+        let _ = fs::remove_dir_all(&dir);
+        t!(fs::create_dir_all(&dir));
+
+        let mut cmd = Command::new("tar");
+        cmd.arg("-xzf")
+           .arg(builder.ensure(dist::Src))
+           .arg("--strip-components=1")
+           .current_dir(&dir);
+        build.run(&mut cmd);
+
+        let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
+        build.run(Command::new(&build.initial_cargo)
+                         .arg("generate-lockfile")
+                         .arg("--manifest-path")
+                         .arg(&toml)
+                         .current_dir(&dir));
+    }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct Bootstrap;
+
+impl Step for Bootstrap {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+    const ONLY_BUILD: bool = true;
+
+    /// Test the build system itself
+    fn run(self, builder: &Builder) {
+        let build = builder.build;
+        let mut cmd = Command::new(&build.initial_cargo);
+        cmd.arg("test")
+           .current_dir(build.src.join("src/bootstrap"))
+           .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
+           .env("RUSTC_BOOTSTRAP", "1")
+           .env("RUSTC", &build.initial_rustc);
+        if !build.fail_fast {
+            cmd.arg("--no-fail-fast");
+        }
+        cmd.arg("--").args(&build.config.cmd.test_args());
+        try_run(build, &mut cmd);
+    }
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("src/bootstrap")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Bootstrap);
+    }
+}