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