33extern crate syntax;
44extern crate rustc;
55extern crate rustc_codegen_utils;
6+ #[ macro_use]
7+ extern crate rustc_data_structures;
8+ extern crate rustc_target;
69
710use std:: any:: Any ;
8- use std:: sync:: mpsc;
11+ use std:: sync:: { Arc , mpsc} ;
12+ use std:: path:: Path ;
913use syntax:: symbol:: Symbol ;
1014use rustc:: session:: Session ;
1115use rustc:: session:: config:: OutputFilenames ;
@@ -14,21 +18,44 @@ use rustc::ty::query::Providers;
1418use rustc:: middle:: cstore:: MetadataLoader ;
1519use rustc:: dep_graph:: DepGraph ;
1620use rustc:: util:: common:: ErrorReported ;
17- use rustc_codegen_utils:: codegen_backend:: { CodegenBackend , MetadataOnlyCodegenBackend } ;
21+ use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
22+ use rustc_data_structures:: sync:: MetadataRef ;
23+ use rustc_data_structures:: owning_ref:: OwningRef ;
24+ use rustc_target:: spec:: Target ;
1825
19- struct TheBackend ( Box < CodegenBackend > ) ;
26+ pub struct NoLlvmMetadataLoader ;
27+
28+ impl MetadataLoader for NoLlvmMetadataLoader {
29+ fn get_rlib_metadata ( & self , _: & Target , filename : & Path ) -> Result < MetadataRef , String > {
30+ let buf = std:: fs:: read ( filename) . map_err ( |e| format ! ( "metadata file open err: {:?}" , e) ) ?;
31+ let buf: OwningRef < Vec < u8 > , [ u8 ] > = OwningRef :: new ( buf) ;
32+ Ok ( rustc_erase_owner ! ( buf. map_owner_box( ) ) )
33+ }
34+
35+ fn get_dylib_metadata ( & self , target : & Target , filename : & Path ) -> Result < MetadataRef , String > {
36+ self . get_rlib_metadata ( target, filename)
37+ }
38+ }
39+
40+ struct TheBackend ;
2041
2142impl CodegenBackend for TheBackend {
2243 fn metadata_loader ( & self ) -> Box < MetadataLoader + Sync > {
23- self . 0 . metadata_loader ( )
44+ Box :: new ( NoLlvmMetadataLoader )
2445 }
2546
2647 fn provide ( & self , providers : & mut Providers ) {
27- self . 0 . provide ( providers) ;
48+ rustc_codegen_utils:: symbol_names:: provide ( providers) ;
49+
50+ providers. target_features_whitelist = |_tcx, _cnum| {
51+ Default :: default ( ) // Just a dummy
52+ } ;
53+ providers. is_reachable_non_generic = |_tcx, _defid| true ;
54+ providers. exported_symbols = |_tcx, _crate| Arc :: new ( Vec :: new ( ) ) ;
2855 }
2956
3057 fn provide_extern ( & self , providers : & mut Providers ) {
31- self . 0 . provide_extern ( providers) ;
58+ providers. is_reachable_non_generic = |_tcx , _defid| true ;
3259 }
3360
3461 fn codegen_crate < ' a , ' tcx > (
@@ -69,5 +96,5 @@ impl CodegenBackend for TheBackend {
6996/// This is the entrypoint for a hot plugged rustc_codegen_llvm
7097#[ no_mangle]
7198pub fn __rustc_codegen_backend ( ) -> Box < CodegenBackend > {
72- Box :: new ( TheBackend ( MetadataOnlyCodegenBackend :: boxed ( ) ) )
99+ Box :: new ( TheBackend )
73100}
0 commit comments