]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
Rollup merge of #82571 - aDotInTheVoid:reexport-tests, r=CraftSpider
[rust.git] / compiler / rustc_codegen_cranelift / src / bin / cg_clif.rs
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::{get_resident_set_size, 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 CraneliftPassesCallbacks {
17     time_passes: bool,
18 }
19
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);
26
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().unwrap().parent().unwrap().parent().unwrap().to_owned()
31         }));
32     }
33 }
34
35 fn main() {
36     let start_time = std::time::Instant::now();
37     let start_rss = get_resident_set_size();
38     rustc_driver::init_rustc_env_logger();
39     let mut callbacks = CraneliftPassesCallbacks::default();
40     rustc_driver::install_ice_hook();
41     let exit_code = rustc_driver::catch_with_exit_code(|| {
42         let args = std::env::args_os()
43             .enumerate()
44             .map(|(i, arg)| {
45                 arg.into_string().unwrap_or_else(|arg| {
46                     early_error(
47                         ErrorOutputType::default(),
48                         &format!("Argument {} is not valid Unicode: {:?}", i, arg),
49                     )
50                 })
51             })
52             .collect::<Vec<_>>();
53         let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks);
54         run_compiler.set_make_codegen_backend(Some(Box::new(move |_| {
55             Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None })
56         })));
57         run_compiler.run()
58     });
59
60     if callbacks.time_passes {
61         let end_rss = get_resident_set_size();
62         print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss);
63     }
64
65     std::process::exit(exit_code)
66 }