Skip to content

Commit f381744

Browse files
committed
Get the miri test suite to run inside the rustc dev environment
1 parent 1cdd689 commit f381744

File tree

12 files changed

+104
-3
lines changed

12 files changed

+104
-3
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@
3939
[submodule "src/tools/rustfmt"]
4040
path = src/tools/rustfmt
4141
url = https://github.com/rust-lang-nursery/rustfmt.git
42+
[submodule "src/tools/miri"]
43+
path = src/tools/miri
44+
url = https://github.com/solson/miri.git

config.toml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@
291291
# When creating source tarballs whether or not to create a source tarball.
292292
#dist-src = false
293293

294+
# Whether to also run the Miri tests suite when running tests.
295+
# As a side-effect also generates MIR for all libraries.
296+
#test-miri = false
297+
294298
# =============================================================================
295299
# Options for specific targets
296300
#

src/bootstrap/bin/rustc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ fn main() {
246246
}
247247
}
248248

249+
// When running miri tests, we need to generate MIR for all libraries
250+
if env::var("TEST_MIRI").ok().map_or(false, |val| val == "true") && stage != "0" {
251+
cmd.arg("-Zalways-encode-mir");
252+
cmd.arg("-Zmir-emit-validate=1");
253+
}
254+
249255
// Force all crates compiled by this compiler to (a) be unstable and (b)
250256
// allow the `rustc_private` feature to link to other unstable crates
251257
// also in the sysroot.

src/bootstrap/builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ impl<'a> Builder<'a> {
249249
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
250250
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
251251
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
252-
native::Llvm, tool::Rustfmt),
252+
native::Llvm, tool::Rustfmt, tool::Miri),
253253
Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
254254
check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Rustdoc,
255255
check::Linkcheck, check::Cargotest, check::Cargo, check::Rls, check::Docs,
256-
check::ErrorIndex, check::Distcheck, check::Rustfmt),
256+
check::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri),
257257
Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
258258
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
259259
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
@@ -475,6 +475,7 @@ impl<'a> Builder<'a> {
475475
} else {
476476
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
477477
})
478+
.env("TEST_MIRI", self.config.test_miri.to_string())
478479
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
479480

480481
if mode != Mode::Tool {

src/bootstrap/check.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,50 @@ impl Step for Rustfmt {
293293
try_run(build, &mut cargo);
294294
}
295295
}
296+
pub struct Miri {
297+
host: Interned<String>,
298+
}
299+
300+
impl Step for Miri {
301+
type Output = ();
302+
const ONLY_HOSTS: bool = true;
303+
const DEFAULT: bool = true;
304+
305+
fn should_run(run: ShouldRun) -> ShouldRun {
306+
let test_miri = run.builder.build.config.test_miri;
307+
run.path("src/tools/miri").default_condition(test_miri)
308+
}
309+
310+
fn make_run(run: RunConfig) {
311+
run.builder.ensure(Miri {
312+
host: run.target,
313+
});
314+
}
315+
316+
/// Runs `cargo test` for miri.
317+
fn run(self, builder: &Builder) {
318+
let build = builder.build;
319+
let host = self.host;
320+
let compiler = builder.compiler(1, host);
321+
322+
let miri = builder.ensure(tool::Miri { compiler, target: self.host });
323+
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
324+
cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
325+
326+
// Don't build tests dynamically, just a pain to work with
327+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
328+
// miri tests need to know about the stage sysroot
329+
cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
330+
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
331+
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
332+
cargo.env("MIRI_PATH", miri);
333+
334+
builder.add_rustc_lib_path(compiler, &mut cargo);
335+
336+
try_run(build, &mut cargo);
337+
}
338+
}
339+
296340

297341
fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
298342
// Configure PATH to find the right rustc. NB. we have to use PATH

src/bootstrap/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub struct Config {
111111
pub low_priority: bool,
112112
pub channel: String,
113113
pub quiet_tests: bool,
114+
pub test_miri: bool,
114115
// Fallback musl-root for all targets
115116
pub musl_root: Option<PathBuf>,
116117
pub prefix: Option<PathBuf>,
@@ -269,6 +270,7 @@ struct Rust {
269270
debug: Option<bool>,
270271
dist_src: Option<bool>,
271272
quiet_tests: Option<bool>,
273+
test_miri: Option<bool>,
272274
}
273275

274276
/// TOML representation of how each build target is configured.
@@ -304,6 +306,7 @@ impl Config {
304306
config.codegen_tests = true;
305307
config.ignore_git = false;
306308
config.rust_dist_src = true;
309+
config.test_miri = false;
307310

308311
config.on_fail = flags.on_fail;
309312
config.stage = flags.stage;
@@ -444,6 +447,7 @@ impl Config {
444447
set(&mut config.channel, rust.channel.clone());
445448
set(&mut config.rust_dist_src, rust.dist_src);
446449
set(&mut config.quiet_tests, rust.quiet_tests);
450+
set(&mut config.test_miri, rust.test_miri);
447451
config.rustc_default_linker = rust.default_linker.clone();
448452
config.rustc_default_ar = rust.default_ar.clone();
449453
config.musl_root = rust.musl_root.clone().map(PathBuf::from);

src/bootstrap/configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def v(*args):
3838
o("docs", "build.docs", "build standard library documentation")
3939
o("compiler-docs", "build.compiler-docs", "build compiler documentation")
4040
o("optimize-tests", "rust.optimize-tests", "build tests with optimizations")
41+
o("test-miri", "rust.test-miri", "run miri's test suite")
4142
o("debuginfo-tests", "rust.debuginfo-tests", "build tests with debugger metadata")
4243
o("quiet-tests", "rust.quiet-tests", "enable quieter output when running tests")
4344
o("ccache", "llvm.ccache", "invoke gcc/clang via ccache to reuse object files between builds")

src/bootstrap/mk/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ check-aux:
5656
src/tools/cargo \
5757
src/tools/rls \
5858
src/tools/rustfmt \
59+
src/tools/miri \
5960
src/test/pretty \
6061
src/test/run-pass/pretty \
6162
src/test/run-fail/pretty \

src/bootstrap/tool.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,41 @@ impl Step for Rustfmt {
479479
}
480480
}
481481

482+
483+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
484+
pub struct Miri {
485+
pub compiler: Compiler,
486+
pub target: Interned<String>,
487+
}
488+
489+
impl Step for Miri {
490+
type Output = PathBuf;
491+
const DEFAULT: bool = true;
492+
const ONLY_HOSTS: bool = true;
493+
494+
fn should_run(run: ShouldRun) -> ShouldRun {
495+
let builder = run.builder;
496+
run.path("src/tools/miri").default_condition(builder.build.config.test_miri)
497+
}
498+
499+
fn make_run(run: RunConfig) {
500+
run.builder.ensure(Miri {
501+
compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
502+
target: run.target,
503+
});
504+
}
505+
506+
fn run(self, builder: &Builder) -> PathBuf {
507+
builder.ensure(ToolBuild {
508+
compiler: self.compiler,
509+
target: self.target,
510+
tool: "miri",
511+
mode: Mode::Librustc,
512+
path: "src/tools/miri",
513+
})
514+
}
515+
}
516+
482517
impl<'a> Builder<'a> {
483518
/// Get a `Command` which is ready to run `tool` in `stage` built for
484519
/// `host`.

src/ci/docker/x86_64-gnu-aux/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1717
COPY scripts/sccache.sh /scripts/
1818
RUN sh /scripts/sccache.sh
1919

20-
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu
20+
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --enable-test-miri
2121
ENV RUST_CHECK_TARGET check-aux

src/tools/miri

Submodule miri added at ce3576f

src/tools/tidy/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fn filter_dirs(path: &Path) -> bool {
6565
"src/tools/clippy",
6666
"src/tools/rust-installer",
6767
"src/tools/rustfmt",
68+
"src/tools/miri",
6869
];
6970
skip.iter().any(|p| path.ends_with(p))
7071
}

0 commit comments

Comments
 (0)