3
3
extern crate syntax;
4
4
extern crate rustc;
5
5
extern crate rustc_codegen_utils;
6
+ #[ macro_use]
7
+ extern crate rustc_data_structures;
8
+ extern crate rustc_target;
6
9
7
10
use std:: any:: Any ;
8
- use std:: sync:: mpsc;
11
+ use std:: sync:: { Arc , mpsc} ;
12
+ use std:: path:: Path ;
9
13
use syntax:: symbol:: Symbol ;
10
14
use rustc:: session:: Session ;
11
15
use rustc:: session:: config:: OutputFilenames ;
@@ -14,21 +18,44 @@ use rustc::ty::query::Providers;
14
18
use rustc:: middle:: cstore:: MetadataLoader ;
15
19
use rustc:: dep_graph:: DepGraph ;
16
20
use 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 ;
18
25
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 ;
20
41
21
42
impl CodegenBackend for TheBackend {
22
43
fn metadata_loader ( & self ) -> Box < MetadataLoader + Sync > {
23
- self . 0 . metadata_loader ( )
44
+ Box :: new ( NoLlvmMetadataLoader )
24
45
}
25
46
26
47
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 ( ) ) ;
28
55
}
29
56
30
57
fn provide_extern ( & self , providers : & mut Providers ) {
31
- self . 0 . provide_extern ( providers) ;
58
+ providers. is_reachable_non_generic = |_tcx , _defid| true ;
32
59
}
33
60
34
61
fn codegen_crate < ' a , ' tcx > (
@@ -69,5 +96,5 @@ impl CodegenBackend for TheBackend {
69
96
/// This is the entrypoint for a hot plugged rustc_codegen_llvm
70
97
#[ no_mangle]
71
98
pub fn __rustc_codegen_backend ( ) -> Box < CodegenBackend > {
72
- Box :: new ( TheBackend ( MetadataOnlyCodegenBackend :: boxed ( ) ) )
99
+ Box :: new ( TheBackend )
73
100
}
0 commit comments