rust/tests/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
3.0 KiB
Rust
Raw Normal View History

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
extern crate rustc_codegen_ssa;
2019-03-02 06:46:10 -06:00
extern crate rustc_data_structures;
extern crate rustc_driver;
2021-09-24 14:06:11 -05:00
extern crate rustc_errors;
extern crate rustc_hir;
2021-09-24 14:06:11 -05:00
extern crate rustc_metadata;
extern crate rustc_middle;
extern crate rustc_session;
2020-01-01 17:01:07 -06:00
extern crate rustc_span;
extern crate rustc_symbol_mangling;
extern crate rustc_target;
2018-01-04 11:15:40 -06:00
use rustc_codegen_ssa::traits::CodegenBackend;
2020-10-10 10:59:16 -05:00
use rustc_codegen_ssa::{CodegenResults, CrateInfo};
2023-04-07 16:26:30 -05:00
use rustc_data_structures::fx::FxIndexMap;
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};
use rustc_middle::ty::TyCtxt;
use rustc_session::config::OutputFilenames;
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 {
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,
_need_metadata_module: bool,
) -> 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
}
fn join_codegen(
2018-01-04 11:15:40 -06:00
&self,
ongoing_codegen: Box<dyn Any>,
_sess: &Session,
_outputs: &OutputFilenames,
2023-04-07 16:26:30 -05:00
) -> Result<(CodegenResults, FxIndexMap<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");
2023-04-07 16:26:30 -05:00
Ok((*codegen_results, FxIndexMap::default()))
}
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,
) -> Result<(), ErrorGuaranteed> {
use rustc_session::{config::{CrateType, OutFileName}, 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() {
if crate_type != CrateType::Rlib {
sess.fatal(format!("Crate type is {:?}", crate_type));
2018-01-04 11:15:40 -06:00
}
let output_name = out_filename(sess, crate_type, &outputs, crate_name);
match output_name {
OutFileName::Real(ref path) => {
let mut out_file = ::std::fs::File::create(path).unwrap();
write!(out_file, "This has been \"compiled\" successfully.").unwrap();
}
OutFileName::Stdout => {
let mut stdout = std::io::stdout();
write!(stdout, "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]
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
}