summary refs log tree commit diff
path: root/compiler/rustc_interface/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_interface/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_interface/src')
-rw-r--r--compiler/rustc_interface/src/interface.rs5
-rw-r--r--compiler/rustc_interface/src/util.rs10
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index 4d84462c42b..73a51ad477b 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -154,6 +154,10 @@ pub struct Config {
     pub override_queries:
         Option<fn(&Session, &mut ty::query::Providers, &mut ty::query::Providers)>,
 
+    /// This is a callback from the driver that is called to create a codegen backend.
+    pub make_codegen_backend:
+        Option<Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>>,
+
     /// Registry of diagnostics codes.
     pub registry: Registry,
 }
@@ -167,6 +171,7 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
         config.file_loader,
         config.input_path.clone(),
         config.lint_caps,
+        config.make_codegen_backend,
         registry.clone(),
     );
 
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs
index 0eed6938c31..7ace707cc88 100644
--- a/compiler/rustc_interface/src/util.rs
+++ b/compiler/rustc_interface/src/util.rs
@@ -63,9 +63,17 @@ pub fn create_session(
     file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
     input_path: Option<PathBuf>,
     lint_caps: FxHashMap<lint::LintId, lint::Level>,
+    make_codegen_backend: Option<
+        Box<dyn FnOnce(&config::Options) -> Box<dyn CodegenBackend> + Send>,
+    >,
     descriptions: Registry,
 ) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>) {
-    let codegen_backend = get_codegen_backend(&sopts);
+    let codegen_backend = if let Some(make_codegen_backend) = make_codegen_backend {
+        make_codegen_backend(&sopts)
+    } else {
+        get_codegen_backend(&sopts)
+    };
+
     // target_override is documented to be called before init(), so this is okay
     let target_override = codegen_backend.target_override(&sopts);