2018-01-04 17:15:40 +00:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
|
|
|
|
extern crate syntax;
|
|
|
|
extern crate rustc;
|
2018-05-08 13:10:16 +00:00
|
|
|
extern crate rustc_codegen_utils;
|
2019-03-02 12:46:10 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_data_structures;
|
|
|
|
extern crate rustc_target;
|
2018-01-04 17:15:40 +00:00
|
|
|
|
|
|
|
use std::any::Any;
|
2019-03-02 12:46:10 +00:00
|
|
|
use std::sync::{Arc, mpsc};
|
|
|
|
use std::path::Path;
|
2018-01-04 17:15:40 +00:00
|
|
|
use syntax::symbol::Symbol;
|
2018-12-08 19:30:23 +00:00
|
|
|
use rustc::session::Session;
|
2018-01-04 17:15:40 +00:00
|
|
|
use rustc::session::config::OutputFilenames;
|
|
|
|
use rustc::ty::TyCtxt;
|
2018-06-13 13:44:43 +00:00
|
|
|
use rustc::ty::query::Providers;
|
2018-01-04 17:15:40 +00:00
|
|
|
use rustc::middle::cstore::MetadataLoader;
|
|
|
|
use rustc::dep_graph::DepGraph;
|
2018-12-08 19:30:23 +00:00
|
|
|
use rustc::util::common::ErrorReported;
|
2019-03-02 12:46:10 +00:00
|
|
|
use rustc_codegen_utils::codegen_backend::CodegenBackend;
|
|
|
|
use rustc_data_structures::sync::MetadataRef;
|
|
|
|
use rustc_data_structures::owning_ref::OwningRef;
|
|
|
|
use rustc_target::spec::Target;
|
2018-01-04 17:15:40 +00:00
|
|
|
|
2019-03-02 12:46:10 +00:00
|
|
|
pub struct NoLlvmMetadataLoader;
|
|
|
|
|
|
|
|
impl MetadataLoader for NoLlvmMetadataLoader {
|
|
|
|
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
|
|
|
|
let buf = std::fs::read(filename).map_err(|e| format!("metadata file open err: {:?}", e))?;
|
|
|
|
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
|
|
|
|
Ok(rustc_erase_owner!(buf.map_owner_box()))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
|
|
|
|
self.get_rlib_metadata(target, filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TheBackend;
|
2018-01-04 17:15:40 +00:00
|
|
|
|
2018-05-08 13:10:16 +00:00
|
|
|
impl CodegenBackend for TheBackend {
|
2018-03-03 05:26:48 +00:00
|
|
|
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> {
|
2019-03-02 12:46:10 +00:00
|
|
|
Box::new(NoLlvmMetadataLoader)
|
2018-01-04 17:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn provide(&self, providers: &mut Providers) {
|
2019-03-02 12:46:10 +00:00
|
|
|
rustc_codegen_utils::symbol_names::provide(providers);
|
|
|
|
|
|
|
|
providers.target_features_whitelist = |_tcx, _cnum| {
|
|
|
|
Default::default() // Just a dummy
|
|
|
|
};
|
|
|
|
providers.is_reachable_non_generic = |_tcx, _defid| true;
|
|
|
|
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());
|
2018-01-04 17:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn provide_extern(&self, providers: &mut Providers) {
|
2019-03-02 12:46:10 +00:00
|
|
|
providers.is_reachable_non_generic = |_tcx, _defid| true;
|
2018-01-04 17:15:40 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 13:10:16 +00:00
|
|
|
fn codegen_crate<'a, 'tcx>(
|
2018-01-04 17:15:40 +00: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 17:26:34 +00:00
|
|
|
|
2018-01-04 17:15:40 +00:00
|
|
|
Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol)
|
|
|
|
}
|
|
|
|
|
2018-05-08 13:10:16 +00:00
|
|
|
fn join_codegen_and_link(
|
2018-01-04 17:15:40 +00:00
|
|
|
&self,
|
2018-05-08 13:10:16 +00:00
|
|
|
ongoing_codegen: Box<Any>,
|
2018-01-04 17:15:40 +00:00
|
|
|
sess: &Session,
|
|
|
|
_dep_graph: &DepGraph,
|
|
|
|
outputs: &OutputFilenames,
|
2018-12-08 19:30:23 +00:00
|
|
|
) -> Result<(), ErrorReported> {
|
2018-01-04 17:15:40 +00:00
|
|
|
use std::io::Write;
|
|
|
|
use rustc::session::config::CrateType;
|
2018-05-08 13:10:16 +00: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 17:15:40 +00:00
|
|
|
for &crate_type in sess.opts.crate_types.iter() {
|
2018-07-26 17:13:11 +00:00
|
|
|
if crate_type != CrateType::Rlib {
|
2018-01-04 17:15:40 +00: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 14:56:50 +00:00
|
|
|
write!(out_file, "This has been \"compiled\" successfully.").unwrap();
|
2018-01-04 17:15:40 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 13:10:16 +00:00
|
|
|
/// This is the entrypoint for a hot plugged rustc_codegen_llvm
|
2018-01-04 17:15:40 +00:00
|
|
|
#[no_mangle]
|
2018-05-08 13:10:16 +00:00
|
|
|
pub fn __rustc_codegen_backend() -> Box<CodegenBackend> {
|
2019-03-02 12:46:10 +00:00
|
|
|
Box::new(TheBackend)
|
2018-01-04 17:15:40 +00:00
|
|
|
}
|