1 #![feature(rustc_private)]
3 extern crate rustc_data_structures;
4 extern crate rustc_driver;
5 extern crate rustc_interface;
6 extern crate rustc_session;
7 extern crate rustc_target;
9 use rustc_data_structures::profiling::print_time_passes_entry;
10 use rustc_interface::interface;
11 use rustc_session::config::ErrorOutputType;
12 use rustc_session::early_error;
13 use rustc_target::spec::PanicStrategy;
16 pub struct CraneliftPassesCallbacks {
20 impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
21 fn config(&mut self, config: &mut interface::Config) {
22 // If a --prints=... option has been given, we don't print the "total"
23 // time because it will mess up the --prints output. See #64339.
24 self.time_passes = config.opts.prints.is_empty()
25 && (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
27 config.opts.cg.panic = Some(PanicStrategy::Abort);
28 config.opts.debugging_opts.panic_abort_tests = true;
29 config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| {
30 std::env::current_exe()
42 let start = std::time::Instant::now();
43 rustc_driver::init_rustc_env_logger();
44 let mut callbacks = CraneliftPassesCallbacks::default();
45 rustc_driver::install_ice_hook();
46 let exit_code = rustc_driver::catch_with_exit_code(|| {
47 let args = std::env::args_os()
50 arg.into_string().unwrap_or_else(|arg| {
52 ErrorOutputType::default(),
53 &format!("Argument {} is not valid Unicode: {:?}", i, arg),
58 let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks);
59 run_compiler.set_make_codegen_backend(Some(Box::new(move |_| {
60 Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None })
64 // The extra `\t` is necessary to align this label with the others.
65 print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed());
66 std::process::exit(exit_code)