|
| 1 | +#![feature(rustc_private)] |
| 2 | + |
| 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; |
| 8 | + |
| 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; |
| 14 | + |
| 15 | +#[derive(Default)] |
| 16 | +pub struct TimePassesCallbacks { |
| 17 | + time_passes: bool, |
| 18 | +} |
| 19 | + |
| 20 | +impl rustc_driver::Callbacks for TimePassesCallbacks { |
| 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); |
| 26 | + |
| 27 | + // FIXME workaround for an ICE |
| 28 | + config.opts.debugging_opts.trim_diagnostic_paths = false; |
| 29 | + |
| 30 | + config.opts.cg.panic = Some(PanicStrategy::Abort); |
| 31 | + config.opts.debugging_opts.panic_abort_tests = true; |
| 32 | + config.opts.maybe_sysroot = Some( |
| 33 | + std::env::current_exe() |
| 34 | + .unwrap() |
| 35 | + .parent() |
| 36 | + .unwrap() |
| 37 | + .parent() |
| 38 | + .unwrap() |
| 39 | + .parent() |
| 40 | + .unwrap() |
| 41 | + .join("build_sysroot") |
| 42 | + .join("sysroot"), |
| 43 | + ); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +fn main() { |
| 48 | + let start = std::time::Instant::now(); |
| 49 | + rustc_driver::init_rustc_env_logger(); |
| 50 | + let mut callbacks = TimePassesCallbacks::default(); |
| 51 | + rustc_driver::install_ice_hook(); |
| 52 | + let exit_code = rustc_driver::catch_with_exit_code(|| { |
| 53 | + let mut use_jit = false; |
| 54 | + |
| 55 | + let mut args = std::env::args_os() |
| 56 | + .enumerate() |
| 57 | + .map(|(i, arg)| { |
| 58 | + arg.into_string().unwrap_or_else(|arg| { |
| 59 | + early_error( |
| 60 | + ErrorOutputType::default(), |
| 61 | + &format!("Argument {} is not valid Unicode: {:?}", i, arg), |
| 62 | + ) |
| 63 | + }) |
| 64 | + }) |
| 65 | + .filter(|arg| { |
| 66 | + if arg == "--jit" { |
| 67 | + use_jit = true; |
| 68 | + false |
| 69 | + } else { |
| 70 | + true |
| 71 | + } |
| 72 | + }) |
| 73 | + .collect::<Vec<_>>(); |
| 74 | + if use_jit { |
| 75 | + args.push("-Cprefer-dynamic".to_string()); |
| 76 | + } |
| 77 | + rustc_driver::run_compiler( |
| 78 | + &args, |
| 79 | + &mut callbacks, |
| 80 | + None, |
| 81 | + None, |
| 82 | + Some(Box::new(move |_| { |
| 83 | + Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { |
| 84 | + config: rustc_codegen_cranelift::BackendConfig { |
| 85 | + use_jit, |
| 86 | + } |
| 87 | + }) |
| 88 | + })), |
| 89 | + ) |
| 90 | + }); |
| 91 | + // The extra `\t` is necessary to align this label with the others. |
| 92 | + print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed()); |
| 93 | + std::process::exit(exit_code) |
| 94 | +} |
0 commit comments