4 extern crate rustc_driver;
5 extern crate rustc_interface;
8 use self::miri::eval_main;
9 use crate::test::Bencher;
10 use rustc::hir::def_id::LOCAL_CRATE;
11 use rustc_driver::Compilation;
12 use rustc_interface::{interface, Queries};
14 struct MiriCompilerCalls<'a> {
15 bencher: &'a mut Bencher,
18 impl rustc_driver::Callbacks for MiriCompilerCalls<'_> {
19 fn after_analysis<'tcx>(
21 compiler: &interface::Compiler,
22 queries: &'tcx Queries<'tcx>,
24 compiler.session().abort_if_errors();
26 queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
27 let (entry_def_id, _) =
28 tcx.entry_fn(LOCAL_CRATE).expect("no main or start function found");
30 self.bencher.iter(|| {
31 let config = miri::MiriConfig {
35 excluded_env_vars: vec![],
38 tracked_pointer_tag: None,
40 eval_main(tcx, entry_def_id, config);
44 compiler.session().abort_if_errors();
50 fn find_sysroot() -> String {
51 // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
52 let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
53 let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
54 match (home, toolchain) {
55 (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
56 _ => option_env!("RUST_SYSROOT")
57 .expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
62 pub fn run(filename: &str, bencher: &mut Bencher) {
65 format!("benches/helpers/{}.rs", filename),
66 "--sysroot".to_string(),
69 rustc_driver::run_compiler(args, &mut MiriCompilerCalls { bencher }, None, None).unwrap()