2018-01-04 11:15:40 -06:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
|
|
|
|
extern crate syntax;
|
|
|
|
extern crate rustc;
|
2018-05-08 08:10:16 -05:00
|
|
|
extern crate rustc_codegen_utils;
|
2018-01-04 11:15:40 -06:00
|
|
|
|
|
|
|
use std::any::Any;
|
|
|
|
use std::sync::mpsc;
|
|
|
|
use syntax::symbol::Symbol;
|
|
|
|
use rustc::session::{Session, CompileIncomplete};
|
|
|
|
use rustc::session::config::OutputFilenames;
|
|
|
|
use rustc::ty::TyCtxt;
|
2018-06-13 08:44:43 -05:00
|
|
|
use rustc::ty::query::Providers;
|
2018-01-04 11:15:40 -06:00
|
|
|
use rustc::middle::cstore::MetadataLoader;
|
|
|
|
use rustc::dep_graph::DepGraph;
|
2018-05-08 08:10:16 -05:00
|
|
|
use rustc_codegen_utils::codegen_backend::{CodegenBackend, MetadataOnlyCodegenBackend};
|
2018-01-04 11:15:40 -06:00
|
|
|
|
2018-05-08 08:10:16 -05:00
|
|
|
struct TheBackend(Box<CodegenBackend>);
|
2018-01-04 11:15:40 -06:00
|
|
|
|
2018-05-08 08:10:16 -05:00
|
|
|
impl CodegenBackend for TheBackend {
|
2018-03-02 23:26:48 -06:00
|
|
|
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> {
|
2018-01-04 11:15:40 -06:00
|
|
|
self.0.metadata_loader()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn provide(&self, providers: &mut Providers) {
|
|
|
|
self.0.provide(providers);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn provide_extern(&self, providers: &mut Providers) {
|
|
|
|
self.0.provide_extern(providers);
|
|
|
|
}
|
|
|
|
|
2018-05-08 08:10:16 -05:00
|
|
|
fn codegen_crate<'a, 'tcx>(
|
2018-01-04 11:15:40 -06:00
|
|
|
&self,
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
_rx: mpsc::Receiver<Box<Any + Send>>
|
|
|
|
) -> Box<Any> {
|
|
|
|
use rustc::hir::def_id::LOCAL_CRATE;
|
2018-01-04 11:26:34 -06:00
|
|
|
|
2018-01-04 11:15:40 -06:00
|
|
|
Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol)
|
|
|
|
}
|
|
|
|
|
2018-05-08 08:10:16 -05:00
|
|
|
fn join_codegen_and_link(
|
2018-01-04 11:15:40 -06:00
|
|
|
&self,
|
2018-05-08 08:10:16 -05:00
|
|
|
ongoing_codegen: Box<Any>,
|
2018-01-04 11:15:40 -06:00
|
|
|
sess: &Session,
|
|
|
|
_dep_graph: &DepGraph,
|
|
|
|
outputs: &OutputFilenames,
|
|
|
|
) -> Result<(), CompileIncomplete> {
|
|
|
|
use std::io::Write;
|
|
|
|
use rustc::session::config::CrateType;
|
2018-05-08 08:10:16 -05:00
|
|
|
use rustc_codegen_utils::link::out_filename;
|
|
|
|
let crate_name = ongoing_codegen.downcast::<Symbol>()
|
|
|
|
.expect("in join_codegen_and_link: ongoing_codegen is not a Symbol");
|
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));
|
|
|
|
}
|
|
|
|
let output_name =
|
|
|
|
out_filename(sess, crate_type, &outputs, &*crate_name.as_str());
|
|
|
|
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]
|
2018-05-08 08:10:16 -05:00
|
|
|
pub fn __rustc_codegen_backend() -> Box<CodegenBackend> {
|
2018-12-06 09:39:19 -06:00
|
|
|
Box::new(TheBackend(MetadataOnlyCodegenBackend::boxed()))
|
2018-01-04 11:15:40 -06:00
|
|
|
}
|