4 extern crate rustc_driver;
7 use self::miri::eval_main;
8 use self::rustc_driver::{driver, Compilation};
9 use std::cell::RefCell;
11 use crate::test::Bencher;
13 pub struct MiriCompilerCalls<'a>(Rc<RefCell<&'a mut Bencher>>);
15 fn find_sysroot() -> String {
16 // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
17 let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
18 let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
19 match (home, toolchain) {
20 (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
22 option_env!("RUST_SYSROOT")
24 "need to specify RUST_SYSROOT env var or use rustup or multirust",
31 pub fn run(filename: &str, bencher: &mut Bencher) {
34 format!("benches/helpers/{}.rs", filename),
35 "--sysroot".to_string(),
38 let bencher = RefCell::new(bencher);
40 let mut control = driver::CompileController::basic();
42 control.after_analysis.stop = Compilation::Stop;
43 control.after_analysis.callback = Box::new(move |state| {
44 state.session.abort_if_errors();
46 let tcx = state.tcx.unwrap();
47 let (entry_node_id, _, _) = state.session.entry_fn.borrow().expect(
48 "no main or start function found",
50 let entry_def_id = tcx.hir().local_def_id(entry_node_id);
52 bencher.borrow_mut().iter(|| {
53 eval_main(tcx, entry_def_id, false);
56 state.session.abort_if_errors();
59 rustc_driver::run_compiler(args, Box::new(control), None, None);