@@ -19,9 +19,9 @@ extern crate rustc_codegen_utils;
19
19
extern crate syntax;
20
20
21
21
use rustc:: session:: { build_session, Session } ;
22
- use rustc:: session:: config:: { basic_options, Input ,
22
+ use rustc:: session:: config:: { basic_options, Input , Options ,
23
23
OutputType , OutputTypes } ;
24
- use rustc_driver:: driver:: { compile_input, CompileController } ;
24
+ use rustc_driver:: driver:: { self , compile_input, CompileController } ;
25
25
use rustc_metadata:: cstore:: CStore ;
26
26
use rustc_errors:: registry:: Registry ;
27
27
use syntax:: codemap:: FileName ;
@@ -52,14 +52,7 @@ fn main() {
52
52
compile ( src. to_string ( ) , tmpdir. join ( "out" ) , sysroot. clone ( ) ) ;
53
53
}
54
54
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 > ) {
63
56
let descriptions = Registry :: new ( & rustc:: DIAGNOSTICS ) ;
64
57
let sess = build_session ( opts, None , descriptions) ;
65
58
let codegen_backend = rustc_driver:: get_codegen_backend ( & sess) ;
@@ -70,19 +63,27 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>, Box<CodegenBackend>) {
70
63
71
64
fn compile ( code : String , output : PathBuf , sysroot : PathBuf ) {
72
65
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
+ } ) ;
87
88
} ) ;
88
89
}
0 commit comments