mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-22 06:45:13 +00:00
link: rely on the default metadata loader.
This commit is contained in:
parent
731a5e86aa
commit
4dcb50169f
@ -167,10 +167,9 @@ use rustc_codegen_ssa::traits::{
|
||||
};
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, ModuleKind};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::MetadataRef;
|
||||
use rustc_errors::{ErrorReported, FatalError, Handler};
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn};
|
||||
use rustc_middle::middle::cstore::EncodedMetadata;
|
||||
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{self, query, DefIdTree, Instance, InstanceDef, TyCtxt};
|
||||
@ -262,18 +261,6 @@ impl ThinBufferMethods for SpirvThinBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
struct SpirvMetadataLoader;
|
||||
|
||||
impl MetadataLoader for SpirvMetadataLoader {
|
||||
fn get_rlib_metadata(&self, _: &Target, path: &Path) -> Result<MetadataRef, String> {
|
||||
link::read_metadata(path)
|
||||
}
|
||||
|
||||
fn get_dylib_metadata(&self, target: &Target, path: &Path) -> Result<MetadataRef, String> {
|
||||
rustc_codegen_ssa::back::metadata::DefaultMetadataLoader.get_dylib_metadata(target, path)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct SpirvCodegenBackend;
|
||||
|
||||
@ -299,10 +286,6 @@ impl CodegenBackend for SpirvCodegenBackend {
|
||||
}
|
||||
}
|
||||
|
||||
fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
|
||||
Box::new(SpirvMetadataLoader)
|
||||
}
|
||||
|
||||
fn provide(&self, providers: &mut query::Providers) {
|
||||
// This is a lil weird: so, we obviously don't support C ABIs at all. However, libcore does declare some extern
|
||||
// C functions:
|
||||
|
@ -8,9 +8,6 @@ use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModul
|
||||
use rustc_codegen_ssa::back::write::CodegenContext;
|
||||
use rustc_codegen_ssa::{CodegenResults, NativeLib, METADATA_FILENAME};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::owning_ref::OwningRef;
|
||||
use rustc_data_structures::rustc_erase_owner;
|
||||
use rustc_data_structures::sync::MetadataRef;
|
||||
use rustc_errors::FatalError;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::dep_graph::WorkProduct;
|
||||
@ -481,27 +478,6 @@ fn create_archive(files: &[&Path], metadata: &[u8], out_filename: &Path) {
|
||||
builder.into_inner().unwrap();
|
||||
}
|
||||
|
||||
pub fn read_metadata(rlib: &Path) -> Result<MetadataRef, String> {
|
||||
fn read_metadata_internal(rlib: &Path) -> Result<Option<MetadataRef>, std::io::Error> {
|
||||
let mut archive = Archive::new(File::open(rlib).unwrap());
|
||||
while let Some(entry) = archive.next_entry() {
|
||||
let mut entry = entry?;
|
||||
if entry.header().identifier() == METADATA_FILENAME.as_bytes() {
|
||||
let mut bytes = Vec::new();
|
||||
entry.read_to_end(&mut bytes)?;
|
||||
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(bytes);
|
||||
return Ok(Some(rustc_erase_owner!(buf.map_owner_box())));
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
match read_metadata_internal(rlib) {
|
||||
Ok(Some(m)) => Ok(m),
|
||||
Ok(None) => Err(format!("No .metadata file in rlib: {:?}", rlib)),
|
||||
Err(io) => Err(format!("Failed to read rlib at {:?}: {}", rlib, io)),
|
||||
}
|
||||
}
|
||||
|
||||
/// This is the actual guts of linking: the rest of the link-related functions are just digging through rustc's
|
||||
/// shenanigans to collect all the object files we need to link.
|
||||
fn do_link(
|
||||
|
Loading…
Reference in New Issue
Block a user