about summary refs log tree commit diff
path: root/compiler/rustc_driver/src
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-09-08 13:44:41 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2020-09-27 14:16:42 +0200
commit71bc62b9f696ae83ef1713bd96054c92cda9f27f (patch)
treed4229eff34beb4d3ed6539ff1f0105a2309a527f /compiler/rustc_driver/src
parent956e06c6c85e918524b67503c4d65c7baf539585 (diff)
downloadrust-71bc62b9f696ae83ef1713bd96054c92cda9f27f.tar.gz
rust-71bc62b9f696ae83ef1713bd96054c92cda9f27f.zip
Add option to pass a custom codegen backend from a driver
Diffstat (limited to 'compiler/rustc_driver/src')
-rw-r--r--compiler/rustc_driver/src/lib.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs
index 972e04fd101..fa5be646de2 100644
--- a/compiler/rustc_driver/src/lib.rs
+++ b/compiler/rustc_driver/src/lib.rs
@@ -141,6 +141,9 @@ pub fn run_compiler(
     callbacks: &mut (dyn Callbacks + Send),
     file_loader: Option<Box<dyn FileLoader + Send + Sync>>,
     emitter: Option<Box<dyn Write + Send>>,
+    make_codegen_backend: Option<
+        Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
+    >,
 ) -> interface::Result<()> {
     let mut args = Vec::new();
     for arg in at_args {
@@ -162,6 +165,11 @@ pub fn run_compiler(
     let sopts = config::build_session_options(&matches);
     let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg"));
 
+    // We wrap `make_codegen_backend` in another `Option` such that `dummy_config` can take
+    // ownership of it when necessary, while also allowing the non-dummy config to take ownership
+    // when `dummy_config` is not used.
+    let mut make_codegen_backend = Some(make_codegen_backend);
+
     let mut dummy_config = |sopts, cfg, diagnostic_output| {
         let mut config = interface::Config {
             opts: sopts,
@@ -177,6 +185,7 @@ pub fn run_compiler(
             lint_caps: Default::default(),
             register_lints: None,
             override_queries: None,
+            make_codegen_backend: make_codegen_backend.take().unwrap(),
             registry: diagnostics_registry(),
         };
         callbacks.config(&mut config);
@@ -253,6 +262,7 @@ pub fn run_compiler(
         lint_caps: Default::default(),
         register_lints: None,
         override_queries: None,
+        make_codegen_backend: make_codegen_backend.unwrap(),
         registry: diagnostics_registry(),
     };
 
@@ -1265,7 +1275,7 @@ pub fn main() -> ! {
                 })
             })
             .collect::<Vec<_>>();
-        run_compiler(&args, &mut callbacks, None, None)
+        run_compiler(&args, &mut callbacks, None, None, None)
     });
     // The extra `\t` is necessary to align this label with the others.
     print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed());