4 extern crate rustc_driver;
5 extern crate rustc_interface;
8 use self::miri::eval_main;
9 use rustc::hir::def_id::LOCAL_CRATE;
10 use rustc_interface::interface;
11 use crate::test::Bencher;
13 struct MiriCompilerCalls<'a> {
14 bencher: &'a mut Bencher,
17 impl rustc_driver::Callbacks for MiriCompilerCalls<'_> {
18 fn after_analysis(&mut self, compiler: &interface::Compiler<'_>) -> bool {
19 compiler.session().abort_if_errors();
21 compiler.global_ctxt().unwrap().peek_mut().enter(|tcx| {
22 let (entry_def_id, _) = tcx.entry_fn(LOCAL_CRATE).expect(
23 "no main or start function found",
26 self.bencher.iter(|| {
27 let config = MiriConfig { validate: true, args: vec![] };
28 eval_main(tcx, entry_def_id, config);
32 compiler.session().abort_if_errors();
34 // Don't continue execution
39 fn find_sysroot() -> String {
40 // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
41 let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
42 let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
43 match (home, toolchain) {
44 (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
46 option_env!("RUST_SYSROOT")
48 "need to specify RUST_SYSROOT env var or use rustup or multirust",
55 pub fn run(filename: &str, bencher: &mut Bencher) {
58 format!("benches/helpers/{}.rs", filename),
59 "--sysroot".to_string(),
62 rustc_driver::run_compiler(args, &mut MiriCompilerCalls { bencher }, None, None);