28
28
#![ feature( rustc_diagnostic_macros) ]
29
29
#![ feature( set_stdio) ]
30
30
31
+ #[ cfg( not( feature="llvm" ) ) ]
32
+ extern crate ar;
33
+
31
34
extern crate arena;
32
35
extern crate getopts;
33
36
extern crate graphviz;
@@ -49,6 +52,7 @@ extern crate rustc_metadata;
49
52
extern crate rustc_mir;
50
53
extern crate rustc_resolve;
51
54
extern crate rustc_save_analysis;
55
+ #[ cfg( feature="llvm" ) ]
52
56
extern crate rustc_trans;
53
57
extern crate rustc_typeck;
54
58
extern crate serialize;
@@ -74,6 +78,8 @@ use rustc::session::config::nightly_options;
74
78
use rustc:: session:: { early_error, early_warn} ;
75
79
use rustc:: lint:: Lint ;
76
80
use rustc:: lint;
81
+ #[ cfg( not( feature="llvm" ) ) ]
82
+ use rustc:: middle:: cstore:: MetadataLoader ;
77
83
use rustc_metadata:: locator;
78
84
use rustc_metadata:: cstore:: CStore ;
79
85
use rustc:: util:: common:: { time, ErrorReported } ;
@@ -151,6 +157,45 @@ pub fn run<F>(run_compiler: F) -> isize
151
157
0
152
158
}
153
159
160
+ #[ cfg( not( feature="llvm" ) ) ]
161
+ pub struct NoLLvmMetadataLoader ;
162
+
163
+ #[ cfg( not( feature="llvm" ) ) ]
164
+ pub use NoLLvmMetadataLoader as MetadataLoader ;
165
+ #[ cfg( feature="llvm" ) ]
166
+ pub use rustc_trans:: LlvmMetadataLoader as MetadataLoader ;
167
+
168
+ #[ cfg( not( feature="llvm" ) ) ]
169
+ impl MetadataLoader for NoLLvmMetadataLoader {
170
+ fn get_rlib_metadata ( & self , _: & Target , filename : & Path ) -> Result < ErasedBoxRef < [ u8 ] > , String > {
171
+ use std:: fs:: File ;
172
+ use std:: io;
173
+ use self :: ar:: Archive ;
174
+
175
+ let file = File :: open ( filename) . map_err ( |e|format ! ( "metadata file open err: {:?}" , e) ) ?;
176
+ let mut archive = Archive :: new ( file) ;
177
+
178
+ while let Some ( entry_result) = archive. next_entry ( ) {
179
+ let mut entry = entry_result. map_err ( |e|format ! ( "metadata section read err: {:?}" , e) ) ?;
180
+ if entry. header ( ) . identifier ( ) == METADATA_FILENAME {
181
+ let mut buf = Vec :: new ( ) ;
182
+ io:: copy ( & mut entry, & mut buf) . unwrap ( ) ;
183
+ let buf: OwningRef < Vec < u8 > , [ u8 ] > = OwningRef :: new ( buf) . into ( ) ;
184
+ return Ok ( buf. erase_owner ( ) ) ;
185
+ }
186
+ }
187
+
188
+ Err ( "Couldnt find metadata section" . to_string ( ) )
189
+ }
190
+
191
+ fn get_dylib_metadata ( & self ,
192
+ target : & Target ,
193
+ filename : & Path )
194
+ -> Result < ErasedBoxRef < [ u8 ] > , String > {
195
+ panic ! ( "Dylib metadata loading not supported without LLVM" )
196
+ }
197
+ }
198
+
154
199
// Parse args and run the compiler. This is the primary entry point for rustc.
155
200
// See comments on CompilerCalls below for details about the callbacks argument.
156
201
// The FileLoader provides a way to load files from sources other than the file system.
@@ -197,7 +242,7 @@ pub fn run_compiler<'a>(args: &[String],
197
242
} ;
198
243
199
244
let dep_graph = DepGraph :: new ( sopts. build_dep_graph ( ) ) ;
200
- let cstore = Rc :: new ( CStore :: new ( & dep_graph, box rustc_trans :: LlvmMetadataLoader ) ) ;
245
+ let cstore = Rc :: new ( CStore :: new ( & dep_graph, box :: MetadataLoader ) ) ;
201
246
202
247
let loader = file_loader. unwrap_or ( box RealFileLoader ) ;
203
248
let codemap = Rc :: new ( CodeMap :: with_file_loader ( loader, sopts. file_path_mapping ( ) ) ) ;
@@ -477,7 +522,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
477
522
return None ;
478
523
}
479
524
let dep_graph = DepGraph :: new ( sopts. build_dep_graph ( ) ) ;
480
- let cstore = Rc :: new ( CStore :: new ( & dep_graph, box rustc_trans :: LlvmMetadataLoader ) ) ;
525
+ let cstore = Rc :: new ( CStore :: new ( & dep_graph, box :: MetadataLoader ) ) ;
481
526
let mut sess = build_session ( sopts. clone ( ) ,
482
527
& dep_graph,
483
528
None ,
0 commit comments