Skip to content

Commit

Permalink
Get the miri test suite to run inside the rustc dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 17, 2017
1 parent 1cdd689 commit f381744
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -39,3 +39,6 @@
[submodule "src/tools/rustfmt"]
path = src/tools/rustfmt
url = https://github.com/rust-lang-nursery/rustfmt.git
[submodule "src/tools/miri"]
path = src/tools/miri
url = https://github.com/solson/miri.git
4 changes: 4 additions & 0 deletions config.toml.example
Expand Up @@ -291,6 +291,10 @@
# When creating source tarballs whether or not to create a source tarball.
#dist-src = false

# Whether to also run the Miri tests suite when running tests.
# As a side-effect also generates MIR for all libraries.
#test-miri = false

# =============================================================================
# Options for specific targets
#
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/bin/rustc.rs
Expand Up @@ -246,6 +246,12 @@ fn main() {
}
}

// When running miri tests, we need to generate MIR for all libraries
if env::var("TEST_MIRI").ok().map_or(false, |val| val == "true") && stage != "0" {
cmd.arg("-Zalways-encode-mir");
cmd.arg("-Zmir-emit-validate=1");
}

// Force all crates compiled by this compiler to (a) be unstable and (b)
// allow the `rustc_private` feature to link to other unstable crates
// also in the sysroot.
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/builder.rs
Expand Up @@ -249,11 +249,11 @@ impl<'a> Builder<'a> {
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
native::Llvm, tool::Rustfmt),
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::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri),
Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
Expand Down Expand Up @@ -475,6 +475,7 @@ impl<'a> Builder<'a> {
} else {
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
})
.env("TEST_MIRI", self.config.test_miri.to_string())
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));

if mode != Mode::Tool {
Expand Down
44 changes: 44 additions & 0 deletions src/bootstrap/check.rs
Expand Up @@ -293,6 +293,50 @@ impl Step for Rustfmt {
try_run(build, &mut cargo);
}
}
pub struct Miri {
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 {
host: run.target,
});
}

/// Runs `cargo test` for miri.
fn run(self, builder: &Builder) {
let build = builder.build;
let host = self.host;
let compiler = builder.compiler(1, host);

let 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);

try_run(build, &mut cargo);
}
}


fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
// Configure PATH to find the right rustc. NB. we have to use PATH
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/config.rs
Expand Up @@ -111,6 +111,7 @@ pub struct Config {
pub low_priority: bool,
pub channel: String,
pub quiet_tests: bool,
pub test_miri: bool,
// Fallback musl-root for all targets
pub musl_root: Option<PathBuf>,
pub prefix: Option<PathBuf>,
Expand Down Expand Up @@ -269,6 +270,7 @@ struct Rust {
debug: Option<bool>,
dist_src: Option<bool>,
quiet_tests: Option<bool>,
test_miri: Option<bool>,
}

/// TOML representation of how each build target is configured.
Expand Down Expand Up @@ -304,6 +306,7 @@ impl Config {
config.codegen_tests = true;
config.ignore_git = false;
config.rust_dist_src = true;
config.test_miri = false;

config.on_fail = flags.on_fail;
config.stage = flags.stage;
Expand Down Expand Up @@ -444,6 +447,7 @@ impl Config {
set(&mut config.channel, rust.channel.clone());
set(&mut config.rust_dist_src, rust.dist_src);
set(&mut config.quiet_tests, rust.quiet_tests);
set(&mut config.test_miri, rust.test_miri);
config.rustc_default_linker = rust.default_linker.clone();
config.rustc_default_ar = rust.default_ar.clone();
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/configure.py
Expand Up @@ -38,6 +38,7 @@ def v(*args):
o("docs", "build.docs", "build standard library documentation")
o("compiler-docs", "build.compiler-docs", "build compiler documentation")
o("optimize-tests", "rust.optimize-tests", "build tests with optimizations")
o("test-miri", "rust.test-miri", "run miri's test suite")
o("debuginfo-tests", "rust.debuginfo-tests", "build tests with debugger metadata")
o("quiet-tests", "rust.quiet-tests", "enable quieter output when running tests")
o("ccache", "llvm.ccache", "invoke gcc/clang via ccache to reuse object files between builds")
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/mk/Makefile.in
Expand Up @@ -56,6 +56,7 @@ check-aux:
src/tools/cargo \
src/tools/rls \
src/tools/rustfmt \
src/tools/miri \
src/test/pretty \
src/test/run-pass/pretty \
src/test/run-fail/pretty \
Expand Down
35 changes: 35 additions & 0 deletions src/bootstrap/tool.rs
Expand Up @@ -479,6 +479,41 @@ impl Step for Rustfmt {
}
}


#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Miri {
pub compiler: Compiler,
pub target: Interned<String>,
}

impl Step for Miri {
type Output = PathBuf;
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
let builder = run.builder;
run.path("src/tools/miri").default_condition(builder.build.config.test_miri)
}

fn make_run(run: RunConfig) {
run.builder.ensure(Miri {
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
target: run.target,
});
}

fn run(self, builder: &Builder) -> PathBuf {
builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.target,
tool: "miri",
mode: Mode::Librustc,
path: "src/tools/miri",
})
}
}

impl<'a> Builder<'a> {
/// Get a `Command` which is ready to run `tool` in `stage` built for
/// `host`.
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/x86_64-gnu-aux/Dockerfile
Expand Up @@ -17,5 +17,5 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --enable-test-miri
ENV RUST_CHECK_TARGET check-aux
1 change: 1 addition & 0 deletions src/tools/miri
Submodule miri added at ce3576
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Expand Up @@ -65,6 +65,7 @@ fn filter_dirs(path: &Path) -> bool {
"src/tools/clippy",
"src/tools/rust-installer",
"src/tools/rustfmt",
"src/tools/miri",
];
skip.iter().any(|p| path.ends_with(p))
}
Expand Down

0 comments on commit f381744

Please sign in to comment.