1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(rustc_private)]
15 extern crate rustc_trans_utils;
19 use syntax::symbol::Symbol;
20 use rustc::session::{Session, CompileIncomplete};
21 use rustc::session::config::OutputFilenames;
22 use rustc::ty::TyCtxt;
23 use rustc::ty::maps::Providers;
24 use rustc::middle::cstore::MetadataLoader;
25 use rustc::dep_graph::DepGraph;
26 use rustc_trans_utils::trans_crate::{TransCrate, MetadataOnlyTransCrate};
28 struct TheBackend(Box<TransCrate>);
30 impl TransCrate for TheBackend {
31 fn metadata_loader(&self) -> Box<MetadataLoader> {
32 self.0.metadata_loader()
35 fn provide(&self, providers: &mut Providers) {
36 self.0.provide(providers);
39 fn provide_extern(&self, providers: &mut Providers) {
40 self.0.provide_extern(providers);
43 fn trans_crate<'a, 'tcx>(
45 tcx: TyCtxt<'a, 'tcx, 'tcx>,
46 _rx: mpsc::Receiver<Box<Any + Send>>
48 use rustc::hir::def_id::LOCAL_CRATE;
50 Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol)
53 fn join_trans_and_link(
57 _dep_graph: &DepGraph,
58 outputs: &OutputFilenames,
59 ) -> Result<(), CompileIncomplete> {
61 use rustc::session::config::CrateType;
62 use rustc_trans_utils::link::out_filename;
63 let crate_name = trans.downcast::<Symbol>()
64 .expect("in join_trans_and_link: trans is not a Symbol");
65 for &crate_type in sess.opts.crate_types.iter() {
66 if crate_type != CrateType::CrateTypeExecutable {
67 sess.fatal(&format!("Crate type is {:?}", crate_type));
70 out_filename(sess, crate_type, &outputs, &*crate_name.as_str());
71 let mut out_file = ::std::fs::File::create(output_name).unwrap();
72 write!(out_file, "This has been \"compiled\" succesfully.").unwrap();
78 /// This is the entrypoint for a hot plugged rustc_trans
80 pub fn __rustc_codegen_backend() -> Box<TransCrate> {
81 Box::new(TheBackend(MetadataOnlyTransCrate::new()))