2018-01-04 18:15:40 +01:00
|
|
|
#![feature(rustc_private)]
|
2021-05-29 18:14:30 +02:00
|
|
|
#![deny(warnings)]
|
2018-01-04 18:15:40 +01:00
|
|
|
|
2020-03-12 18:07:58 -05:00
|
|
|
extern crate rustc_codegen_ssa;
|
2019-03-02 13:46:10 +01:00
|
|
|
extern crate rustc_data_structures;
|
2019-07-19 13:06:31 -07:00
|
|
|
extern crate rustc_driver;
|
2021-09-24 21:06:11 +02:00
|
|
|
extern crate rustc_errors;
|
2020-03-12 18:07:58 -05:00
|
|
|
extern crate rustc_hir;
|
2021-09-24 21:06:11 +02:00
|
|
|
extern crate rustc_metadata;
|
|
|
|
extern crate rustc_middle;
|
2020-03-11 12:49:08 +01:00
|
|
|
extern crate rustc_session;
|
2020-01-02 00:01:07 +01:00
|
|
|
extern crate rustc_span;
|
2020-03-12 18:07:58 -05:00
|
|
|
extern crate rustc_symbol_mangling;
|
|
|
|
extern crate rustc_target;
|
2018-01-04 18:15:40 +01:00
|
|
|
|
2020-03-12 18:07:58 -05:00
|
|
|
use rustc_codegen_ssa::traits::CodegenBackend;
|
2020-10-10 17:59:16 +02:00
|
|
|
use rustc_codegen_ssa::{CodegenResults, CrateInfo};
|
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2022-01-23 12:34:26 -06:00
|
|
|
use rustc_errors::ErrorGuaranteed;
|
2021-09-24 21:06:11 +02:00
|
|
|
use rustc_metadata::EncodedMetadata;
|
2020-10-10 17:59:16 +02:00
|
|
|
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
2020-03-29 18:08:01 +02:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2020-03-11 12:49:08 +01:00
|
|
|
use rustc_session::config::OutputFilenames;
|
2020-03-12 18:07:58 -05:00
|
|
|
use rustc_session::Session;
|
|
|
|
use std::any::Any;
|
2018-01-04 18:15:40 +01:00
|
|
|
|
2019-03-02 13:46:10 +01:00
|
|
|
struct TheBackend;
|
2018-01-04 18:15:40 +01:00
|
|
|
|
2018-05-08 16:10:16 +03:00
|
|
|
impl CodegenBackend for TheBackend {
|
2022-10-17 14:11:26 +01:00
|
|
|
fn locale_resource(&self) -> &'static str { "" }
|
|
|
|
|
2018-05-08 16:10:16 +03:00
|
|
|
fn codegen_crate<'a, 'tcx>(
|
2018-01-04 18:15:40 +01:00
|
|
|
&self,
|
2019-06-14 00:48:52 +03:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-10-10 17:59:16 +02:00
|
|
|
metadata: EncodedMetadata,
|
2019-04-26 17:22:36 +10:00
|
|
|
_need_metadata_module: bool,
|
2019-09-22 01:32:51 +02:00
|
|
|
) -> Box<dyn Any> {
|
2020-10-10 17:59:16 +02:00
|
|
|
Box::new(CodegenResults {
|
|
|
|
modules: vec![],
|
|
|
|
allocator_module: None,
|
|
|
|
metadata_module: None,
|
|
|
|
metadata,
|
2021-07-06 19:40:21 +02:00
|
|
|
crate_info: CrateInfo::new(tcx, "fake_target_cpu".to_string()),
|
2020-10-10 17:59:16 +02:00
|
|
|
})
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 00:16:14 +11:00
|
|
|
fn join_codegen(
|
2018-01-04 18:15:40 +01:00
|
|
|
&self,
|
2019-09-22 01:32:51 +02:00
|
|
|
ongoing_codegen: Box<dyn Any>,
|
2020-01-29 00:16:14 +11:00
|
|
|
_sess: &Session,
|
2021-12-13 00:00:00 +00:00
|
|
|
_outputs: &OutputFilenames,
|
2022-01-23 12:34:26 -06:00
|
|
|
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
|
2020-10-10 17:59:16 +02:00
|
|
|
let codegen_results = ongoing_codegen
|
|
|
|
.downcast::<CodegenResults>()
|
|
|
|
.expect("in join_codegen: ongoing_codegen is not a CodegenResults");
|
|
|
|
Ok((*codegen_results, FxHashMap::default()))
|
2020-01-29 00:16:14 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
fn link(
|
|
|
|
&self,
|
|
|
|
sess: &Session,
|
2020-10-10 17:59:16 +02:00
|
|
|
codegen_results: CodegenResults,
|
2018-01-04 18:15:40 +01:00
|
|
|
outputs: &OutputFilenames,
|
2022-01-23 12:34:26 -06:00
|
|
|
) -> Result<(), ErrorGuaranteed> {
|
2020-03-12 18:07:58 -05:00
|
|
|
use rustc_session::{config::CrateType, output::out_filename};
|
2018-01-04 18:15:40 +01:00
|
|
|
use std::io::Write;
|
2021-05-29 18:14:30 +02:00
|
|
|
let crate_name = codegen_results.crate_info.local_crate_name;
|
2018-01-04 18:15:40 +01:00
|
|
|
for &crate_type in sess.opts.crate_types.iter() {
|
2018-07-26 11:13:11 -06:00
|
|
|
if crate_type != CrateType::Rlib {
|
2018-01-04 18:15:40 +01:00
|
|
|
sess.fatal(&format!("Crate type is {:?}", crate_type));
|
|
|
|
}
|
2022-12-06 12:46:10 +00:00
|
|
|
let output_name = out_filename(sess, crate_type, &outputs, crate_name);
|
2018-01-04 18:15:40 +01:00
|
|
|
let mut out_file = ::std::fs::File::create(output_name).unwrap();
|
2018-02-16 15:56:50 +01:00
|
|
|
write!(out_file, "This has been \"compiled\" successfully.").unwrap();
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 16:10:16 +03:00
|
|
|
/// This is the entrypoint for a hot plugged rustc_codegen_llvm
|
2018-01-04 18:15:40 +01:00
|
|
|
#[no_mangle]
|
2019-09-22 01:32:51 +02:00
|
|
|
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
|
2019-03-02 13:46:10 +01:00
|
|
|
Box::new(TheBackend)
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|