Skip to content

Commit caad256

Browse files
committed
Auto merge of #43628 - oli-obk:orbital_standard_library, r=alexcrichton
Run the miri test suite on the aux builder and travis Reopen of #38350 see #43340 (comment) for earlier discussion Rationale for running miri's test suite in rustc's CI is that miri currently contains many features that we want in const eval in the future, and these features would break if the test suite is not run. fixes #44077 r? @nikomatsakis cc @eddyb
2 parents e8a76d8 + 01555b1 commit caad256

File tree

20 files changed

+334
-45
lines changed

20 files changed

+334
-45
lines changed

.gitmodules

+3
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

+4
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

+6
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") {
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,18 @@ impl<'a> Builder<'a> {
250250
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
251251
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
252252
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
253-
native::Llvm, tool::Rustfmt),
253+
native::Llvm, tool::Rustfmt, tool::Miri),
254254
Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
255255
check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Rustdoc,
256256
check::Linkcheck, check::Cargotest, check::Cargo, check::Rls, check::Docs,
257-
check::ErrorIndex, check::Distcheck, check::Rustfmt),
257+
check::ErrorIndex, check::Distcheck, check::Rustfmt, check::Miri),
258258
Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
259259
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
260260
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
261261
doc::Reference, doc::Rustdoc, doc::CargoBook),
262262
Kind::Dist => describe!(dist::Docs, dist::Mingw, dist::Rustc, dist::DebuggerScripts,
263263
dist::Std, dist::Analysis, dist::Src, dist::PlainSourceTarball, dist::Cargo,
264-
dist::Rls, dist::Extended, dist::HashSign),
264+
dist::Rls, dist::Extended, dist::HashSign, dist::DontDistWithMiriEnabled),
265265
Kind::Install => describe!(install::Docs, install::Std, install::Cargo, install::Rls,
266266
install::Analysis, install::Src, install::Rustc),
267267
}
@@ -481,6 +481,7 @@ impl<'a> Builder<'a> {
481481
} else {
482482
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
483483
})
484+
.env("TEST_MIRI", self.config.test_miri.to_string())
484485
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
485486

486487
if mode != Mode::Tool {

src/bootstrap/check.rs

+59-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::path::{PathBuf, Path};
2323
use std::process::Command;
2424
use std::io::Read;
2525

26-
use build_helper::{self, output};
26+
use build_helper::{self, output, BuildExpectation};
2727

2828
use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
2929
use cache::{INTERNER, Interned};
@@ -33,6 +33,7 @@ use native;
3333
use tool::{self, Tool};
3434
use util::{self, dylib_path, dylib_path_var};
3535
use {Build, Mode};
36+
use toolstate::ToolState;
3637

3738
const ADB_TEST_DIR: &str = "/data/tmp/work";
3839

@@ -64,17 +65,21 @@ impl fmt::Display for TestKind {
6465
}
6566
}
6667

67-
fn try_run(build: &Build, cmd: &mut Command) {
68+
fn try_run_expecting(build: &Build, cmd: &mut Command, expect: BuildExpectation) {
6869
if !build.fail_fast {
69-
if !build.try_run(cmd) {
70+
if !build.try_run(cmd, expect) {
7071
let failures = build.delayed_failures.get();
7172
build.delayed_failures.set(failures + 1);
7273
}
7374
} else {
74-
build.run(cmd);
75+
build.run_expecting(cmd, expect);
7576
}
7677
}
7778

79+
fn try_run(build: &Build, cmd: &mut Command) {
80+
try_run_expecting(build, cmd, BuildExpectation::None)
81+
}
82+
7883
fn try_run_quiet(build: &Build, cmd: &mut Command) {
7984
if !build.fail_fast {
8085
if !build.try_run_quiet(cmd) {
@@ -294,6 +299,56 @@ impl Step for Rustfmt {
294299
}
295300
}
296301

302+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
303+
pub struct Miri {
304+
host: Interned<String>,
305+
}
306+
307+
impl Step for Miri {
308+
type Output = ();
309+
const ONLY_HOSTS: bool = true;
310+
const DEFAULT: bool = true;
311+
312+
fn should_run(run: ShouldRun) -> ShouldRun {
313+
let test_miri = run.builder.build.config.test_miri;
314+
run.path("src/tools/miri").default_condition(test_miri)
315+
}
316+
317+
fn make_run(run: RunConfig) {
318+
run.builder.ensure(Miri {
319+
host: run.target,
320+
});
321+
}
322+
323+
/// Runs `cargo test` for miri.
324+
fn run(self, builder: &Builder) {
325+
let build = builder.build;
326+
let host = self.host;
327+
let compiler = builder.compiler(1, host);
328+
329+
let miri = builder.ensure(tool::Miri { compiler, target: self.host });
330+
let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
331+
cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
332+
333+
// Don't build tests dynamically, just a pain to work with
334+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
335+
// miri tests need to know about the stage sysroot
336+
cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
337+
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
338+
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
339+
cargo.env("MIRI_PATH", miri);
340+
341+
builder.add_rustc_lib_path(compiler, &mut cargo);
342+
343+
try_run_expecting(
344+
build,
345+
&mut cargo,
346+
builder.build.config.toolstate.miri.passes(ToolState::Testing),
347+
);
348+
}
349+
}
350+
351+
297352
fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
298353
// Configure PATH to find the right rustc. NB. we have to use PATH
299354
// and not RUSTC because the Cargo test suite has tests that will

src/bootstrap/config.rs

+19
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use util::exe;
2727
use cache::{INTERNER, Interned};
2828
use flags::Flags;
2929
pub use flags::Subcommand;
30+
use toolstate::ToolStates;
3031

3132
/// Global configuration for the entire build and/or bootstrap.
3233
///
@@ -111,6 +112,7 @@ pub struct Config {
111112
pub low_priority: bool,
112113
pub channel: String,
113114
pub quiet_tests: bool,
115+
pub test_miri: bool,
114116
// Fallback musl-root for all targets
115117
pub musl_root: Option<PathBuf>,
116118
pub prefix: Option<PathBuf>,
@@ -130,6 +132,8 @@ pub struct Config {
130132
// These are either the stage0 downloaded binaries or the locally installed ones.
131133
pub initial_cargo: PathBuf,
132134
pub initial_rustc: PathBuf,
135+
136+
pub toolstate: ToolStates,
133137
}
134138

135139
/// Per-target configuration stored in the global configuration structure.
@@ -269,6 +273,7 @@ struct Rust {
269273
debug: Option<bool>,
270274
dist_src: Option<bool>,
271275
quiet_tests: Option<bool>,
276+
test_miri: Option<bool>,
272277
}
273278

274279
/// TOML representation of how each build target is configured.
@@ -304,6 +309,7 @@ impl Config {
304309
config.codegen_tests = true;
305310
config.ignore_git = false;
306311
config.rust_dist_src = true;
312+
config.test_miri = false;
307313

308314
config.on_fail = flags.on_fail;
309315
config.stage = flags.stage;
@@ -330,6 +336,18 @@ impl Config {
330336
}
331337
}).unwrap_or_else(|| TomlConfig::default());
332338

339+
let toolstate_toml_path = config.src.join("src/tools/toolstate.toml");
340+
let parse_toolstate = || -> Result<_, Box<::std::error::Error>> {
341+
let mut f = File::open(toolstate_toml_path)?;
342+
let mut contents = String::new();
343+
f.read_to_string(&mut contents)?;
344+
Ok(toml::from_str(&contents)?)
345+
};
346+
config.toolstate = parse_toolstate().unwrap_or_else(|err| {
347+
println!("failed to parse TOML configuration 'toolstate.toml': {}", err);
348+
process::exit(2);
349+
});
350+
333351
let build = toml.build.clone().unwrap_or(Build::default());
334352
set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
335353
set(&mut config.build, flags.build);
@@ -444,6 +462,7 @@ impl Config {
444462
set(&mut config.channel, rust.channel.clone());
445463
set(&mut config.rust_dist_src, rust.dist_src);
446464
set(&mut config.quiet_tests, rust.quiet_tests);
465+
set(&mut config.test_miri, rust.test_miri);
447466
config.rustc_default_linker = rust.default_linker.clone();
448467
config.rustc_default_ar = rust.default_ar.clone();
449468
config.musl_root = rust.musl_root.clone().map(PathBuf::from);

src/bootstrap/configure.py

+1
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/dist.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,31 @@ impl Step for Rls {
11111111
}
11121112
}
11131113

1114+
1115+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1116+
pub struct DontDistWithMiriEnabled;
1117+
1118+
impl Step for DontDistWithMiriEnabled {
1119+
type Output = PathBuf;
1120+
const DEFAULT: bool = true;
1121+
1122+
fn should_run(run: ShouldRun) -> ShouldRun {
1123+
let build_miri = run.builder.build.config.test_miri;
1124+
run.default_condition(build_miri)
1125+
}
1126+
1127+
fn make_run(run: RunConfig) {
1128+
run.builder.ensure(DontDistWithMiriEnabled);
1129+
}
1130+
1131+
fn run(self, _: &Builder) -> PathBuf {
1132+
panic!("Do not distribute with miri enabled.\n\
1133+
The distributed libraries would include all MIR (increasing binary size).
1134+
The distributed MIR would include validation statements.");
1135+
}
1136+
}
1137+
1138+
11141139
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
11151140
pub struct Extended {
11161141
stage: u32,

src/bootstrap/lib.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ use std::path::{PathBuf, Path};
143143
use std::process::Command;
144144
use std::slice;
145145

146-
use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime};
146+
use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppressed, output, mtime,
147+
BuildExpectation};
147148

148149
use util::{exe, libdir, OutputFolder, CiEnv};
149150

@@ -164,6 +165,7 @@ pub mod util;
164165
mod builder;
165166
mod cache;
166167
mod tool;
168+
mod toolstate;
167169

168170
#[cfg(windows)]
169171
mod job;
@@ -542,32 +544,39 @@ impl Build {
542544
.join(libdir(&self.config.build))
543545
}
544546

547+
/// Runs a command, printing out nice contextual information if its build
548+
/// status is not the expected one
549+
fn run_expecting(&self, cmd: &mut Command, expect: BuildExpectation) {
550+
self.verbose(&format!("running: {:?}", cmd));
551+
run_silent(cmd, expect)
552+
}
553+
545554
/// Runs a command, printing out nice contextual information if it fails.
546555
fn run(&self, cmd: &mut Command) {
547-
self.verbose(&format!("running: {:?}", cmd));
548-
run_silent(cmd)
556+
self.run_expecting(cmd, BuildExpectation::None)
549557
}
550558

551559
/// Runs a command, printing out nice contextual information if it fails.
552560
fn run_quiet(&self, cmd: &mut Command) {
553561
self.verbose(&format!("running: {:?}", cmd));
554-
run_suppressed(cmd)
562+
run_suppressed(cmd, BuildExpectation::None)
555563
}
556564

557-
/// Runs a command, printing out nice contextual information if it fails.
558-
/// Exits if the command failed to execute at all, otherwise returns its
559-
/// `status.success()`.
560-
fn try_run(&self, cmd: &mut Command) -> bool {
565+
/// Runs a command, printing out nice contextual information if its build
566+
/// status is not the expected one.
567+
/// Exits if the command failed to execute at all, otherwise returns whether
568+
/// the expectation was met
569+
fn try_run(&self, cmd: &mut Command, expect: BuildExpectation) -> bool {
561570
self.verbose(&format!("running: {:?}", cmd));
562-
try_run_silent(cmd)
571+
try_run_silent(cmd, expect)
563572
}
564573

565574
/// Runs a command, printing out nice contextual information if it fails.
566575
/// Exits if the command failed to execute at all, otherwise returns its
567576
/// `status.success()`.
568577
fn try_run_quiet(&self, cmd: &mut Command) -> bool {
569578
self.verbose(&format!("running: {:?}", cmd));
570-
try_run_suppressed(cmd)
579+
try_run_suppressed(cmd, BuildExpectation::None)
571580
}
572581

573582
pub fn is_verbose(&self) -> bool {

src/bootstrap/mk/Makefile.in

+1
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 \

0 commit comments

Comments
 (0)