Skip to content

Commit

Permalink
Auto merge of rust-lang#85810 - bjorn3:further_driver_cleanup, r=varkor
Browse files Browse the repository at this point in the history
Driver improvements

This PR contains a couple of cleanups for the driver and a few small improvements for the custom codegen backend interface. It also implements `--version` and `-Cpasses=list` support for custom codegen backends.
  • Loading branch information
bors committed Jun 7, 2021
2 parents df47bce + dbdeafb commit ab73115
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
17 changes: 0 additions & 17 deletions src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,6 @@ pub(crate) fn run_aot(
metadata: EncodedMetadata,
need_metadata_module: bool,
) -> Box<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>)> {
use rustc_span::symbol::sym;

let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
let windows_subsystem = subsystem.map(|subsystem| {
if subsystem != sym::windows && subsystem != sym::console {
tcx.sess.fatal(&format!(
"invalid windows subsystem `{}`, only \
`windows` and `console` are allowed",
subsystem
));
}
subsystem.to_string()
});

let mut work_products = FxHashMap::default();

let cgus = if tcx.sess.opts.output_types.should_codegen() {
Expand Down Expand Up @@ -307,12 +292,10 @@ pub(crate) fn run_aot(

Box::new((
CodegenResults {
crate_name: tcx.crate_name(LOCAL_CRATE),
modules,
allocator_module,
metadata_module,
metadata,
windows_subsystem,
linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()),
crate_info: CrateInfo::new(tcx),
},
Expand Down
16 changes: 6 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_codegen_ssa::CodegenResults;
use rustc_errors::ErrorReported;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader};
use rustc_middle::ty::query::Providers;
use rustc_middle::middle::cstore::EncodedMetadata;
use rustc_session::config::OutputFilenames;
use rustc_session::Session;

Expand Down Expand Up @@ -164,17 +163,14 @@ impl CodegenBackend for CraneliftCodegenBackend {
}
}

fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader)
}

fn provide(&self, _providers: &mut Providers) {}
fn provide_extern(&self, _providers: &mut Providers) {}

fn target_features(&self, _sess: &Session) -> Vec<rustc_span::Symbol> {
vec![]
}

fn print_version(&self) {
println!("Cranelift version: {}", cranelift_codegen::VERSION);
}

fn codegen_crate(
&self,
tcx: TyCtxt<'_>,
Expand Down Expand Up @@ -222,7 +218,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
sess,
&codegen_results,
outputs,
&codegen_results.crate_name.as_str(),
&codegen_results.crate_info.local_crate_name.as_str(),
);

Ok(())
Expand Down

0 comments on commit ab73115

Please sign in to comment.