Auto merge of #85810 - bjorn3:further_driver_cleanup, r=varkor

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.
This commit is contained in:
bors 2021-06-07 02:30:24 +00:00
commit ab73115be0
2 changed files with 6 additions and 27 deletions

View File

@ -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() {
@ -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),
},

View File

@ -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;
@ -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<'_>,
@ -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(())