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;
|
2019-03-02 06:46:10 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_data_structures;
|
|
|
|
extern crate rustc_target;
|
2019-07-19 15:06:31 -05:00
|
|
|
extern crate rustc_driver;
|
2018-01-04 11:15:40 -06:00
|
|
|
|
|
|
|
use std::any::Any;
|
2019-03-02 06:46:10 -06:00
|
|
|
use std::sync::{Arc, mpsc};
|
|
|
|
use std::path::Path;
|
2018-01-04 11:15:40 -06:00
|
|
|
use syntax::symbol::Symbol;
|
2018-12-08 13:30:23 -06:00
|
|
|
use rustc::session::Session;
|
2018-01-04 11:15:40 -06:00
|
|
|
use rustc::session::config::OutputFilenames;
|
|
|
|
use rustc::ty::TyCtxt;
|
2018-06-13 08:44:43 -05:00
|
|
|
use rustc::ty::query::Providers;
|
2019-04-26 02:22:36 -05:00
|
|
|
use rustc::middle::cstore::{EncodedMetadata, MetadataLoader};
|
2018-01-04 11:15:40 -06:00
|
|
|
use rustc::dep_graph::DepGraph;
|
2018-12-08 13:30:23 -06:00
|
|
|
use rustc::util::common::ErrorReported;
|
2019-03-02 06:46:10 -06: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 11:15:40 -06:00
|
|
|
|
2019-03-02 06:46:10 -06: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 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> {
|
2019-03-02 06:46:10 -06:00
|
|
|
Box::new(NoLlvmMetadataLoader)
|
2018-01-04 11:15:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn provide(&self, providers: &mut Providers) {
|
2019-03-02 06:46:10 -06:00
|
|
|
rustc_codegen_utils::symbol_names::provide(providers);
|
|
|
|
|
2018-12-01 09:30:42 -06:00
|
|
|
providers.target_features_whitelist = |tcx, _cnum| {
|
|
|
|
tcx.arena.alloc(Default::default()) // Just a dummy
|
2019-03-02 06:46:10 -06:00
|
|
|
};
|
|
|
|
providers.is_reachable_non_generic = |_tcx, _defid| true;
|
|
|
|
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());
|
2018-01-04 11:15:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn provide_extern(&self, providers: &mut Providers) {
|
2019-03-02 06:46:10 -06:00
|
|
|
providers.is_reachable_non_generic = |_tcx, _defid| true;
|
2018-01-04 11:15:40 -06:00
|
|
|
}
|
|
|
|
|
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>,
|
2019-04-26 02:22:36 -05:00
|
|
|
_metadata: EncodedMetadata,
|
|
|
|
_need_metadata_module: bool,
|
2018-01-04 11:15:40 -06:00
|
|
|
) -> 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,
|
2018-12-08 13:30:23 -06:00
|
|
|
) -> Result<(), ErrorReported> {
|
2018-01-04 11:15:40 -06:00
|
|
|
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> {
|
2019-03-02 06:46:10 -06:00
|
|
|
Box::new(TheBackend)
|
2018-01-04 11:15:40 -06:00
|
|
|
}
|