2018-01-04 18:15:40 +01:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
|
|
|
|
extern crate rustc;
|
2018-05-08 16:10:16 +03:00
|
|
|
extern crate rustc_codegen_utils;
|
2019-03-02 13:46:10 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_data_structures;
|
|
|
|
extern crate rustc_target;
|
2019-07-19 13:06:31 -07:00
|
|
|
extern crate rustc_driver;
|
2020-01-02 00:01:07 +01:00
|
|
|
extern crate rustc_span;
|
2018-01-04 18:15:40 +01:00
|
|
|
|
|
|
|
use std::any::Any;
|
2019-10-17 21:26:13 +03:00
|
|
|
use std::sync::Arc;
|
2019-03-02 13:46:10 +01:00
|
|
|
use std::path::Path;
|
2020-01-02 00:01:07 +01:00
|
|
|
use rustc_span::symbol::Symbol;
|
2018-12-08 20:30:23 +01:00
|
|
|
use rustc::session::Session;
|
2018-01-04 18:15:40 +01:00
|
|
|
use rustc::session::config::OutputFilenames;
|
|
|
|
use rustc::ty::TyCtxt;
|
2018-06-13 16:44:43 +03:00
|
|
|
use rustc::ty::query::Providers;
|
2019-10-17 21:26:13 +03:00
|
|
|
use rustc::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn};
|
2018-01-04 18:15:40 +01:00
|
|
|
use rustc::dep_graph::DepGraph;
|
2018-12-08 20:30:23 +01:00
|
|
|
use rustc::util::common::ErrorReported;
|
2019-03-02 13:46:10 +01: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 18:15:40 +01:00
|
|
|
|
2019-03-02 13:46:10 +01: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 18:15:40 +01:00
|
|
|
|
2018-05-08 16:10:16 +03:00
|
|
|
impl CodegenBackend for TheBackend {
|
2019-10-17 21:26:13 +03:00
|
|
|
fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
|
2019-03-02 13:46:10 +01:00
|
|
|
Box::new(NoLlvmMetadataLoader)
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn provide(&self, providers: &mut Providers) {
|
2019-03-02 13:46:10 +01:00
|
|
|
rustc_codegen_utils::symbol_names::provide(providers);
|
|
|
|
|
2018-12-01 16:30:42 +01:00
|
|
|
providers.target_features_whitelist = |tcx, _cnum| {
|
|
|
|
tcx.arena.alloc(Default::default()) // Just a dummy
|
2019-03-02 13:46:10 +01:00
|
|
|
};
|
|
|
|
providers.is_reachable_non_generic = |_tcx, _defid| true;
|
|
|
|
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn provide_extern(&self, providers: &mut Providers) {
|
2019-03-02 13:46:10 +01:00
|
|
|
providers.is_reachable_non_generic = |_tcx, _defid| true;
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
|
|
|
|
2018-05-08 16:10:16 +03:00
|
|
|
fn codegen_crate<'a, 'tcx>(
|
2018-01-04 18:15:40 +01:00
|
|
|
&self,
|
2019-06-14 00:48:52 +03:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2019-04-26 17:22:36 +10:00
|
|
|
_metadata: EncodedMetadata,
|
|
|
|
_need_metadata_module: bool,
|
2019-09-22 01:32:51 +02:00
|
|
|
) -> Box<dyn Any> {
|
2018-01-04 18:15:40 +01:00
|
|
|
use rustc::hir::def_id::LOCAL_CRATE;
|
2018-01-04 18:26:34 +01:00
|
|
|
|
2018-01-04 18:15:40 +01:00
|
|
|
Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol)
|
|
|
|
}
|
|
|
|
|
2018-05-08 16:10:16 +03:00
|
|
|
fn join_codegen_and_link(
|
2018-01-04 18:15:40 +01:00
|
|
|
&self,
|
2019-09-22 01:32:51 +02:00
|
|
|
ongoing_codegen: Box<dyn Any>,
|
2018-01-04 18:15:40 +01:00
|
|
|
sess: &Session,
|
|
|
|
_dep_graph: &DepGraph,
|
|
|
|
outputs: &OutputFilenames,
|
2018-12-08 20:30:23 +01:00
|
|
|
) -> Result<(), ErrorReported> {
|
2018-01-04 18:15:40 +01:00
|
|
|
use std::io::Write;
|
|
|
|
use rustc::session::config::CrateType;
|
2018-05-08 16:10:16 +03: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 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 {
|
2018-01-04 18:15:40 +01: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 15:56:50 +01:00
|
|
|
write!(out_file, "This has been \"compiled\" successfully.").unwrap();
|
2018-01-04 18:15:40 +01:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|