| 37 | |
| 38 | impl<C: CallbacksExt> Callbacks for CallbackWrapper<C> { |
| 39 | fn config(&mut self, config: &mut Config) { |
| 40 | self.callback.lock().unwrap().config(config); |
| 41 | |
| 42 | let make_codegen_backend = config.make_codegen_backend.take().unwrap_or_else(|| { |
| 43 | Box::new(|sess| { |
| 44 | let early_dcx = EarlyDiagCtxt::new(sess.opts.error_format); |
| 45 | rustc_interface::util::get_codegen_backend( |
| 46 | &early_dcx, |
| 47 | &sess.opts.sysroot, |
| 48 | sess.opts.unstable_opts.codegen_backend.as_deref(), |
| 49 | &sess.target, |
| 50 | ) |
| 51 | }) |
| 52 | }); |
| 53 | |
| 54 | // By default, Rust starts codegen with a TyCtxt, but then leaves `TyCtxt` and join |
| 55 | // codegen. This is useful to reduce memory consumption while building, but also means that |
| 56 | // we will no longer have access to `TyCtxt` when we want to lint based on the generated |
| 57 | // binary. We therefore hook the backend so that the whole process is done with `TyCtxt` |
| 58 | // still present. |
| 59 | let callback_clone = self.callback.clone(); |
| 60 | config.make_codegen_backend = Some(Box::new(|sess| { |
| 61 | let codegen_backend = make_codegen_backend(sess); |
| 62 | Box::new(BackendWrapper { |
| 63 | backend: codegen_backend, |
| 64 | callback: callback_clone, |
| 65 | }) |
| 66 | })); |
| 67 | } |
| 68 | |
| 69 | fn after_crate_root_parsing( |
| 70 | &mut self, |