|
10 | 10 | #![feature(box_syntax)]
|
11 | 11 |
|
12 | 12 | use std::any::Any;
|
13 |
| -use std::io::Write; |
14 |
| -use std::fs; |
15 |
| -use std::path::Path; |
16 |
| -use std::sync::{mpsc, Arc}; |
17 |
| - |
18 |
| -use rustc_data_structures::owning_ref::OwningRef; |
19 |
| -use flate2::Compression; |
20 |
| -use flate2::write::DeflateEncoder; |
| 13 | +use std::sync::mpsc; |
21 | 14 |
|
22 | 15 | use syntax::symbol::Symbol;
|
23 |
| -use rustc::hir::def_id::LOCAL_CRATE; |
24 | 16 | use rustc::session::Session;
|
25 | 17 | use rustc::util::common::ErrorReported;
|
26 |
| -use rustc::session::config::{CrateType, OutputFilenames, PrintRequest}; |
| 18 | +use rustc::session::config::{OutputFilenames, PrintRequest}; |
27 | 19 | use rustc::ty::TyCtxt;
|
28 | 20 | use rustc::ty::query::Providers;
|
29 |
| -use rustc::middle::cstore::EncodedMetadata; |
30 | 21 | use rustc::middle::cstore::MetadataLoader;
|
31 | 22 | use rustc::dep_graph::DepGraph;
|
32 |
| -use rustc_target::spec::Target; |
33 |
| -use crate::link::out_filename; |
34 | 23 |
|
35 | 24 | pub use rustc_data_structures::sync::MetadataRef;
|
36 | 25 |
|
@@ -64,134 +53,3 @@ pub trait CodegenBackend {
|
64 | 53 | outputs: &OutputFilenames,
|
65 | 54 | ) -> Result<(), ErrorReported>;
|
66 | 55 | }
|
67 |
| - |
68 |
| -pub struct NoLlvmMetadataLoader; |
69 |
| - |
70 |
| -impl MetadataLoader for NoLlvmMetadataLoader { |
71 |
| - fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> { |
72 |
| - let buf = fs::read(filename).map_err(|e| format!("metadata file open err: {:?}", e))?; |
73 |
| - let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf); |
74 |
| - Ok(rustc_erase_owner!(buf.map_owner_box())) |
75 |
| - } |
76 |
| - |
77 |
| - fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> { |
78 |
| - self.get_rlib_metadata(target, filename) |
79 |
| - } |
80 |
| -} |
81 |
| - |
82 |
| -pub struct MetadataOnlyCodegenBackend(()); |
83 |
| -pub struct OngoingCodegen { |
84 |
| - metadata: EncodedMetadata, |
85 |
| - metadata_version: Vec<u8>, |
86 |
| - crate_name: Symbol, |
87 |
| -} |
88 |
| - |
89 |
| -impl MetadataOnlyCodegenBackend { |
90 |
| - pub fn boxed() -> Box<dyn CodegenBackend> { |
91 |
| - box MetadataOnlyCodegenBackend(()) |
92 |
| - } |
93 |
| -} |
94 |
| - |
95 |
| -impl CodegenBackend for MetadataOnlyCodegenBackend { |
96 |
| - fn init(&self, sess: &Session) { |
97 |
| - for cty in sess.opts.crate_types.iter() { |
98 |
| - match *cty { |
99 |
| - CrateType::Rlib | CrateType::Dylib | CrateType::Executable => {}, |
100 |
| - _ => { |
101 |
| - sess.diagnostic().warn( |
102 |
| - &format!("LLVM unsupported, so output type {} is not supported", cty) |
103 |
| - ); |
104 |
| - }, |
105 |
| - } |
106 |
| - } |
107 |
| - } |
108 |
| - |
109 |
| - fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> { |
110 |
| - box NoLlvmMetadataLoader |
111 |
| - } |
112 |
| - |
113 |
| - fn provide(&self, providers: &mut Providers<'_>) { |
114 |
| - crate::symbol_names::provide(providers); |
115 |
| - |
116 |
| - providers.target_features_whitelist = |_tcx, _cnum| { |
117 |
| - Default::default() // Just a dummy |
118 |
| - }; |
119 |
| - providers.is_reachable_non_generic = |_tcx, _defid| true; |
120 |
| - providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new()); |
121 |
| - } |
122 |
| - fn provide_extern(&self, providers: &mut Providers<'_>) { |
123 |
| - providers.is_reachable_non_generic = |_tcx, _defid| true; |
124 |
| - } |
125 |
| - |
126 |
| - fn codegen_crate<'a, 'tcx>( |
127 |
| - &self, |
128 |
| - tcx: TyCtxt<'a, 'tcx, 'tcx>, |
129 |
| - _rx: mpsc::Receiver<Box<dyn Any + Send>> |
130 |
| - ) -> Box<dyn Any> { |
131 |
| - use rustc_mir::monomorphize::item::MonoItem; |
132 |
| - |
133 |
| - crate::check_for_rustc_errors_attr(tcx); |
134 |
| - crate::symbol_names_test::report_symbol_names(tcx); |
135 |
| - rustc_incremental::assert_dep_graph(tcx); |
136 |
| - rustc_incremental::assert_module_sources::assert_module_sources(tcx); |
137 |
| - // FIXME: Fix this |
138 |
| - // rustc::middle::dependency_format::calculate(tcx); |
139 |
| - let _ = tcx.link_args(LOCAL_CRATE); |
140 |
| - let _ = tcx.native_libraries(LOCAL_CRATE); |
141 |
| - let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); |
142 |
| - for (mono_item, _) in cgus.iter().flat_map(|cgu| cgu.items().iter()) { |
143 |
| - if let MonoItem::Fn(inst) = mono_item { |
144 |
| - let def_id = inst.def_id(); |
145 |
| - if def_id.is_local() { |
146 |
| - let _ = tcx.codegen_fn_attrs(def_id); |
147 |
| - } |
148 |
| - } |
149 |
| - } |
150 |
| - tcx.sess.abort_if_errors(); |
151 |
| - |
152 |
| - let metadata = tcx.encode_metadata(); |
153 |
| - |
154 |
| - box OngoingCodegen { |
155 |
| - metadata, |
156 |
| - metadata_version: tcx.metadata_encoding_version().to_vec(), |
157 |
| - crate_name: tcx.crate_name(LOCAL_CRATE), |
158 |
| - } |
159 |
| - } |
160 |
| - |
161 |
| - fn join_codegen_and_link( |
162 |
| - &self, |
163 |
| - ongoing_codegen: Box<dyn Any>, |
164 |
| - sess: &Session, |
165 |
| - _dep_graph: &DepGraph, |
166 |
| - outputs: &OutputFilenames, |
167 |
| - ) -> Result<(), ErrorReported> { |
168 |
| - let ongoing_codegen = ongoing_codegen.downcast::<OngoingCodegen>() |
169 |
| - .expect("Expected MetadataOnlyCodegenBackend's OngoingCodegen, found Box<dyn Any>"); |
170 |
| - for &crate_type in sess.opts.crate_types.iter() { |
171 |
| - if crate_type != CrateType::Rlib && |
172 |
| - crate_type != CrateType::Dylib { |
173 |
| - continue; |
174 |
| - } |
175 |
| - let output_name = |
176 |
| - out_filename(sess, crate_type, &outputs, &ongoing_codegen.crate_name.as_str()); |
177 |
| - let mut compressed = ongoing_codegen.metadata_version.clone(); |
178 |
| - let metadata = if crate_type == CrateType::Dylib { |
179 |
| - DeflateEncoder::new(&mut compressed, Compression::fast()) |
180 |
| - .write_all(&ongoing_codegen.metadata.raw_data) |
181 |
| - .unwrap(); |
182 |
| - &compressed |
183 |
| - } else { |
184 |
| - &ongoing_codegen.metadata.raw_data |
185 |
| - }; |
186 |
| - fs::write(&output_name, metadata).unwrap(); |
187 |
| - } |
188 |
| - |
189 |
| - sess.abort_if_errors(); |
190 |
| - if !sess.opts.crate_types.contains(&CrateType::Rlib) |
191 |
| - && !sess.opts.crate_types.contains(&CrateType::Dylib) |
192 |
| - { |
193 |
| - sess.fatal("Executables are not supported by the metadata-only backend."); |
194 |
| - } |
195 |
| - Ok(()) |
196 |
| - } |
197 |
| -} |
0 commit comments