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, Queries};
11 use rustc_driver::Compilation;
12 use crate::test::Bencher;
14 struct MiriCompilerCalls<'a> {
15 bencher: &'a mut Bencher,
18 impl rustc_driver::Callbacks for MiriCompilerCalls<'_> {
19 fn after_analysis<'tcx>(&mut self, compiler: &interface::Compiler, queries: &'tcx Queries<'tcx>) -> Compilation {
20 compiler.session().abort_if_errors();
22 queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
23 let (entry_def_id, _) = tcx.entry_fn(LOCAL_CRATE).expect(
24 "no main or start function found",
27 self.bencher.iter(|| {
28 let config = miri::MiriConfig {
31 excluded_env_vars: vec![],
35 eval_main(tcx, entry_def_id, config);
39 compiler.session().abort_if_errors();
45 fn find_sysroot() -> String {
46 // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
47 let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
48 let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
49 match (home, toolchain) {
50 (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
52 option_env!("RUST_SYSROOT")
54 "need to specify RUST_SYSROOT env var or use rustup or multirust",
61 pub fn run(filename: &str, bencher: &mut Bencher) {
64 format!("benches/helpers/{}.rs", filename),
65 "--sysroot".to_string(),
68 rustc_driver::run_compiler(args, &mut MiriCompilerCalls { bencher }, None, None).unwrap()