diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2018-01-04 18:15:40 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2018-01-19 20:27:36 +0100 |
| commit | 4ef16d7466cca262c682fb3a9441a88a61a089df (patch) | |
| tree | 33d45a8b327fc4ff4405c940d6927bcb91380f45 /src/test/run-make/hotplug_codegen_backend | |
| parent | ace502a10736dba186785ea439c50be75d0cfdfb (diff) | |
| download | rust-4ef16d7466cca262c682fb3a9441a88a61a089df.tar.gz rust-4ef16d7466cca262c682fb3a9441a88a61a089df.zip | |
Fix hotplug backend and add test
Diffstat (limited to 'src/test/run-make/hotplug_codegen_backend')
| -rw-r--r-- | src/test/run-make/hotplug_codegen_backend/Makefile | 10 | ||||
| -rw-r--r-- | src/test/run-make/hotplug_codegen_backend/some_crate.rs | 3 | ||||
| -rw-r--r-- | src/test/run-make/hotplug_codegen_backend/the_backend.rs | 72 |
3 files changed, 85 insertions, 0 deletions
diff --git a/src/test/run-make/hotplug_codegen_backend/Makefile b/src/test/run-make/hotplug_codegen_backend/Makefile new file mode 100644 index 00000000000..1916983a9e7 --- /dev/null +++ b/src/test/run-make/hotplug_codegen_backend/Makefile @@ -0,0 +1,10 @@ +include ../tools.mk + +all: + /bin/echo || exit 0 # This test requires /bin/echo to exist + $(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \ + -o $(TMPDIR)/the_backend.dylib + sleep 10 + $(RUSTC) some_crate.rs --crate-name some_crate --crate-type bin -o $(TMPDIR)/some_crate \ + -Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options + grep -x "This has been \"compiled\" succesfully." $(TMPDIR)/some_crate diff --git a/src/test/run-make/hotplug_codegen_backend/some_crate.rs b/src/test/run-make/hotplug_codegen_backend/some_crate.rs new file mode 100644 index 00000000000..7d01978dcee --- /dev/null +++ b/src/test/run-make/hotplug_codegen_backend/some_crate.rs @@ -0,0 +1,3 @@ +fn main() { + ::std::process::exit(1); +} diff --git a/src/test/run-make/hotplug_codegen_backend/the_backend.rs b/src/test/run-make/hotplug_codegen_backend/the_backend.rs new file mode 100644 index 00000000000..8200658b1f1 --- /dev/null +++ b/src/test/run-make/hotplug_codegen_backend/the_backend.rs @@ -0,0 +1,72 @@ +#![feature(rustc_private)] + +extern crate syntax; +extern crate rustc; +extern crate rustc_trans_utils; + +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; +use rustc::ty::maps::Providers; +use rustc::middle::cstore::MetadataLoader; +use rustc::dep_graph::DepGraph; +use rustc_trans_utils::trans_crate::{TransCrate, MetadataOnlyTransCrate}; + +struct TheBackend(Box<TransCrate>); + +impl TransCrate for TheBackend { + fn metadata_loader(&self) -> Box<MetadataLoader> { + 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); + } + + fn trans_crate<'a, 'tcx>( + &self, + tcx: TyCtxt<'a, 'tcx, 'tcx>, + _rx: mpsc::Receiver<Box<Any + Send>> + ) -> Box<Any> { + use rustc::hir::def_id::LOCAL_CRATE; + + Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol) + } + + fn join_trans_and_link( + &self, + trans: Box<Any>, + sess: &Session, + _dep_graph: &DepGraph, + outputs: &OutputFilenames, + ) -> Result<(), CompileIncomplete> { + use std::io::Write; + use rustc::session::config::CrateType; + use rustc_trans_utils::link::out_filename; + let crate_name = trans.downcast::<Symbol>() + .expect("in join_trans_and_link: trans is not a Symbol"); + for &crate_type in sess.opts.crate_types.iter() { + if crate_type != CrateType::CrateTypeExecutable { + 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(); + write!(out_file, "This has been \"compiled\" succesfully.").unwrap(); + } + Ok(()) + } +} + +/// This is the entrypoint for a hot plugged rustc_trans +#[no_mangle] +pub extern "C" fn __rustc_codegen_backend(sess: &Session) -> Box<TransCrate> { + Box::new(TheBackend(MetadataOnlyTransCrate::new(sess))) +} |
