2024-06-05 20:12:18 +10:00
|
|
|
//@ edition: 2021
|
|
|
|
|
|
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
|
|
|
|
2024-11-28 16:40:42 +00:00
|
|
|
use std::any::Any;
|
|
|
|
|
|
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};
|
2023-04-07 17:26:30 -04:00
|
|
|
use rustc_data_structures::fx::FxIndexMap;
|
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-12 18:07:58 -05:00
|
|
|
use rustc_session::Session;
|
2024-11-28 16:40:42 +00:00
|
|
|
use rustc_session::config::OutputFilenames;
|
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 {
|
2024-06-03 16:03:45 +10:00
|
|
|
fn locale_resource(&self) -> &'static str {
|
|
|
|
|
""
|
|
|
|
|
}
|
2022-10-17 14:11:26 +01:00
|
|
|
|
2025-09-28 12:08:44 -04:00
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
"the-backend"
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 12:51:15 +00:00
|
|
|
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {
|
2020-10-10 17:59:16 +02:00
|
|
|
Box::new(CodegenResults {
|
|
|
|
|
modules: vec![],
|
|
|
|
|
allocator_module: None,
|
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,
|
2024-02-17 10:51:35 +11:00
|
|
|
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
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");
|
2024-02-17 10:51:35 +11:00
|
|
|
(*codegen_results, FxIndexMap::default())
|
2020-01-29 00:16:14 +11:00
|
|
|
}
|
|
|
|
|
|
2025-05-30 12:51:15 +00:00
|
|
|
fn link(
|
|
|
|
|
&self,
|
|
|
|
|
sess: &Session,
|
|
|
|
|
codegen_results: CodegenResults,
|
|
|
|
|
_metadata: EncodedMetadata,
|
|
|
|
|
outputs: &OutputFilenames,
|
|
|
|
|
) {
|
2018-01-04 18:15:40 +01:00
|
|
|
use std::io::Write;
|
2024-11-28 16:40:42 +00:00
|
|
|
|
|
|
|
|
use rustc_session::config::{CrateType, OutFileName};
|
|
|
|
|
use rustc_session::output::out_filename;
|
|
|
|
|
|
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 {
|
2023-12-18 22:21:37 +11:00
|
|
|
sess.dcx().fatal(format!("Crate type is {:?}", crate_type));
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
2022-12-06 12:46:10 +00:00
|
|
|
let output_name = out_filename(sess, crate_type, &outputs, crate_name);
|
2023-02-26 15:27:27 -05:00
|
|
|
match output_name {
|
|
|
|
|
OutFileName::Real(ref path) => {
|
|
|
|
|
let mut out_file = ::std::fs::File::create(path).unwrap();
|
2024-06-05 20:12:18 +10:00
|
|
|
writeln!(out_file, "This has been 'compiled' successfully.").unwrap();
|
2023-02-26 15:27:27 -05:00
|
|
|
}
|
|
|
|
|
OutFileName::Stdout => {
|
|
|
|
|
let mut stdout = std::io::stdout();
|
2024-06-05 20:12:18 +10:00
|
|
|
writeln!(stdout, "This has been 'compiled' successfully.").unwrap();
|
2023-02-26 15:27:27 -05:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|