@@ -134,9 +134,52 @@ pub fn diagnostics_registry() -> Registry {
134134 Registry :: new ( & rustc_error_codes:: DIAGNOSTICS )
135135}
136136
137+ pub struct RunCompiler < ' a , ' b > {
138+ at_args : & ' a [ String ] ,
139+ callbacks : & ' b mut ( dyn Callbacks + Send ) ,
140+ file_loader : Option < Box < dyn FileLoader + Send + Sync > > ,
141+ emitter : Option < Box < dyn Write + Send > > ,
142+ make_codegen_backend :
143+ Option < Box < dyn FnOnce ( & config:: Options ) -> Box < dyn CodegenBackend > + Send > > ,
144+ }
145+
146+ impl < ' a , ' b > RunCompiler < ' a , ' b > {
147+ pub fn new ( at_args : & ' a [ String ] , callbacks : & ' b mut ( dyn Callbacks + Send ) ) -> Self {
148+ Self { at_args, callbacks, file_loader : None , emitter : None , make_codegen_backend : None }
149+ }
150+ pub fn set_make_codegen_backend (
151+ & mut self ,
152+ make_codegen_backend : Option <
153+ Box < dyn FnOnce ( & config:: Options ) -> Box < dyn CodegenBackend > + Send > ,
154+ > ,
155+ ) -> & mut Self {
156+ self . make_codegen_backend = make_codegen_backend;
157+ self
158+ }
159+ pub fn set_emitter ( & mut self , emitter : Option < Box < dyn Write + Send > > ) -> & mut Self {
160+ self . emitter = emitter;
161+ self
162+ }
163+ pub fn set_file_loader (
164+ & mut self ,
165+ file_loader : Option < Box < dyn FileLoader + Send + Sync > > ,
166+ ) -> & mut Self {
167+ self . file_loader = file_loader;
168+ self
169+ }
170+ pub fn run ( self ) -> interface:: Result < ( ) > {
171+ run_compiler (
172+ self . at_args ,
173+ self . callbacks ,
174+ self . file_loader ,
175+ self . emitter ,
176+ self . make_codegen_backend ,
177+ )
178+ }
179+ }
137180// Parse args and run the compiler. This is the primary entry point for rustc.
138181// The FileLoader provides a way to load files from sources other than the file system.
139- pub fn run_compiler (
182+ fn run_compiler (
140183 at_args : & [ String ] ,
141184 callbacks : & mut ( dyn Callbacks + Send ) ,
142185 file_loader : Option < Box < dyn FileLoader + Send + Sync > > ,
@@ -1275,7 +1318,7 @@ pub fn main() -> ! {
12751318 } )
12761319 } )
12771320 . collect :: < Vec < _ > > ( ) ;
1278- run_compiler ( & args, & mut callbacks, None , None , None )
1321+ RunCompiler :: new ( & args, & mut callbacks) . run ( )
12791322 } ) ;
12801323 // The extra `\t` is necessary to align this label with the others.
12811324 print_time_passes_entry ( callbacks. time_passes , "\t total" , start. elapsed ( ) ) ;
0 commit comments