]>
Commit | Line | Data |
---|---|---|
2c00a5a8 XL |
1 | #![feature(rustc_private)] |
2 | ||
ba9703b0 XL |
3 | extern crate rustc_codegen_ssa; |
4 | extern crate rustc_errors; | |
5 | extern crate rustc_middle; | |
532ac7d7 | 6 | extern crate rustc_data_structures; |
416331ca | 7 | extern crate rustc_driver; |
ba9703b0 XL |
8 | extern crate rustc_hir; |
9 | extern crate rustc_session; | |
dfeec247 | 10 | extern crate rustc_span; |
ba9703b0 XL |
11 | extern crate rustc_symbol_mangling; |
12 | extern crate rustc_target; | |
2c00a5a8 | 13 | |
29967ef6 | 14 | use rustc_codegen_ssa::back::linker::LinkerInfo; |
ba9703b0 | 15 | use rustc_codegen_ssa::traits::CodegenBackend; |
29967ef6 XL |
16 | use rustc_codegen_ssa::{CodegenResults, CrateInfo}; |
17 | use rustc_data_structures::fx::FxHashMap; | |
ba9703b0 XL |
18 | use rustc_data_structures::sync::MetadataRef; |
19 | use rustc_errors::ErrorReported; | |
20 | use rustc_middle::dep_graph::DepGraph; | |
29967ef6 | 21 | use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; |
ba9703b0 XL |
22 | use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn}; |
23 | use rustc_middle::ty::query::Providers; | |
24 | use rustc_middle::ty::TyCtxt; | |
25 | use rustc_session::config::OutputFilenames; | |
26 | use rustc_session::Session; | |
532ac7d7 | 27 | use rustc_target::spec::Target; |
ba9703b0 XL |
28 | use std::any::Any; |
29 | use std::path::Path; | |
2c00a5a8 | 30 | |
532ac7d7 XL |
31 | pub struct NoLlvmMetadataLoader; |
32 | ||
33 | impl MetadataLoader for NoLlvmMetadataLoader { | |
34 | fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> { | |
29967ef6 | 35 | unreachable!("some_crate.rs shouldn't depend on any external crates"); |
532ac7d7 XL |
36 | } |
37 | ||
38 | fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> { | |
29967ef6 | 39 | unreachable!("some_crate.rs shouldn't depend on any external crates"); |
532ac7d7 XL |
40 | } |
41 | } | |
42 | ||
43 | struct TheBackend; | |
2c00a5a8 | 44 | |
94b46f34 | 45 | impl CodegenBackend for TheBackend { |
e74abb32 | 46 | fn metadata_loader(&self) -> Box<MetadataLoaderDyn> { |
532ac7d7 | 47 | Box::new(NoLlvmMetadataLoader) |
2c00a5a8 XL |
48 | } |
49 | ||
29967ef6 XL |
50 | fn provide(&self, providers: &mut Providers) {} |
51 | fn provide_extern(&self, providers: &mut Providers) {} | |
2c00a5a8 | 52 | |
94b46f34 | 53 | fn codegen_crate<'a, 'tcx>( |
2c00a5a8 | 54 | &self, |
dc9dc135 | 55 | tcx: TyCtxt<'tcx>, |
29967ef6 | 56 | metadata: EncodedMetadata, |
48663c56 | 57 | _need_metadata_module: bool, |
e74abb32 | 58 | ) -> Box<dyn Any> { |
dfeec247 | 59 | use rustc_hir::def_id::LOCAL_CRATE; |
2c00a5a8 | 60 | |
29967ef6 XL |
61 | Box::new(CodegenResults { |
62 | crate_name: tcx.crate_name(LOCAL_CRATE), | |
63 | modules: vec![], | |
64 | allocator_module: None, | |
65 | metadata_module: None, | |
66 | metadata, | |
67 | windows_subsystem: None, | |
68 | linker_info: LinkerInfo::new(tcx), | |
69 | crate_info: CrateInfo::new(tcx), | |
70 | }) | |
2c00a5a8 XL |
71 | } |
72 | ||
74b04a01 | 73 | fn join_codegen( |
2c00a5a8 | 74 | &self, |
e74abb32 | 75 | ongoing_codegen: Box<dyn Any>, |
74b04a01 | 76 | _sess: &Session, |
29967ef6 XL |
77 | ) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> { |
78 | let codegen_results = ongoing_codegen | |
79 | .downcast::<CodegenResults>() | |
80 | .expect("in join_codegen: ongoing_codegen is not a CodegenResults"); | |
81 | Ok((*codegen_results, FxHashMap::default())) | |
74b04a01 XL |
82 | } |
83 | ||
84 | fn link( | |
85 | &self, | |
86 | sess: &Session, | |
29967ef6 | 87 | codegen_results: CodegenResults, |
2c00a5a8 | 88 | outputs: &OutputFilenames, |
532ac7d7 | 89 | ) -> Result<(), ErrorReported> { |
ba9703b0 | 90 | use rustc_session::{config::CrateType, output::out_filename}; |
2c00a5a8 | 91 | use std::io::Write; |
29967ef6 | 92 | let crate_name = codegen_results.crate_name; |
2c00a5a8 | 93 | for &crate_type in sess.opts.crate_types.iter() { |
b7449926 | 94 | if crate_type != CrateType::Rlib { |
2c00a5a8 XL |
95 | sess.fatal(&format!("Crate type is {:?}", crate_type)); |
96 | } | |
ba9703b0 | 97 | let output_name = out_filename(sess, crate_type, &outputs, &*crate_name.as_str()); |
2c00a5a8 | 98 | let mut out_file = ::std::fs::File::create(output_name).unwrap(); |
0531ce1d | 99 | write!(out_file, "This has been \"compiled\" successfully.").unwrap(); |
2c00a5a8 XL |
100 | } |
101 | Ok(()) | |
102 | } | |
103 | } | |
104 | ||
94b46f34 | 105 | /// This is the entrypoint for a hot plugged rustc_codegen_llvm |
2c00a5a8 | 106 | #[no_mangle] |
e74abb32 | 107 | pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> { |
532ac7d7 | 108 | Box::new(TheBackend) |
2c00a5a8 | 109 | } |