@@ -19,9 +19,9 @@ extern crate rustc_codegen_utils;
1919extern crate syntax;
2020
2121use rustc:: session:: { build_session, Session } ;
22- use rustc:: session:: config:: { basic_options, Input ,
22+ use rustc:: session:: config:: { basic_options, Input , Options ,
2323 OutputType , OutputTypes } ;
24- use rustc_driver:: driver:: { compile_input, CompileController } ;
24+ use rustc_driver:: driver:: { self , compile_input, CompileController } ;
2525use rustc_metadata:: cstore:: CStore ;
2626use rustc_errors:: registry:: Registry ;
2727use syntax:: codemap:: FileName ;
@@ -52,14 +52,7 @@ fn main() {
5252 compile ( src. to_string ( ) , tmpdir. join ( "out" ) , sysroot. clone ( ) ) ;
5353}
5454
55- fn basic_sess ( sysroot : PathBuf ) -> ( Session , Rc < CStore > , Box < CodegenBackend > ) {
56- let mut opts = basic_options ( ) ;
57- opts. output_types = OutputTypes :: new ( & [ ( OutputType :: Exe , None ) ] ) ;
58- opts. maybe_sysroot = Some ( sysroot) ;
59- if let Ok ( linker) = std:: env:: var ( "RUSTC_LINKER" ) {
60- opts. cg . linker = Some ( linker. into ( ) ) ;
61- }
62-
55+ fn basic_sess ( opts : Options ) -> ( Session , Rc < CStore > , Box < CodegenBackend > ) {
6356 let descriptions = Registry :: new ( & rustc:: DIAGNOSTICS ) ;
6457 let sess = build_session ( opts, None , descriptions) ;
6558 let codegen_backend = rustc_driver:: get_codegen_backend ( & sess) ;
@@ -70,19 +63,27 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>, Box<CodegenBackend>) {
7063
7164fn compile ( code : String , output : PathBuf , sysroot : PathBuf ) {
7265 syntax:: with_globals ( || {
73- let ( sess, cstore, codegen_backend) = basic_sess ( sysroot) ;
74- let control = CompileController :: basic ( ) ;
75- let input = Input :: Str { name : FileName :: Anon , input : code } ;
76- let _ = compile_input (
77- codegen_backend,
78- & sess,
79- & cstore,
80- & None ,
81- & input,
82- & None ,
83- & Some ( output) ,
84- None ,
85- & control
86- ) ;
66+ let mut opts = basic_options ( ) ;
67+ opts. output_types = OutputTypes :: new ( & [ ( OutputType :: Exe , None ) ] ) ;
68+ opts. maybe_sysroot = Some ( sysroot) ;
69+ if let Ok ( linker) = std:: env:: var ( "RUSTC_LINKER" ) {
70+ opts. cg . linker = Some ( linker. into ( ) ) ;
71+ }
72+ driver:: spawn_thread_pool ( opts, |opts| {
73+ let ( sess, cstore, codegen_backend) = basic_sess ( opts) ;
74+ let control = CompileController :: basic ( ) ;
75+ let input = Input :: Str { name : FileName :: Anon , input : code } ;
76+ let _ = compile_input (
77+ codegen_backend,
78+ & sess,
79+ & cstore,
80+ & None ,
81+ & input,
82+ & None ,
83+ & Some ( output) ,
84+ None ,
85+ & control
86+ ) ;
87+ } ) ;
8788 } ) ;
8889}
0 commit comments