1 use rustc::middle::cstore::MetadataLoader;
2 use rustc_codegen_ssa::METADATA_FILENAME;
3 use rustc_data_structures::owning_ref::{self, OwningRef};
4 use rustc_data_structures::rustc_erase_owner;
8 pub struct CraneliftMetadataLoader;
10 impl MetadataLoader for CraneliftMetadataLoader {
13 _target: &crate::rustc_target::spec::Target,
15 ) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
16 let mut archive = ar::Archive::new(File::open(path).map_err(|e| format!("{:?}", e))?);
17 // Iterate over all entries in the archive:
18 while let Some(entry_result) = archive.next_entry() {
19 let mut entry = entry_result.map_err(|e| format!("{:?}", e))?;
20 if entry.header().identifier() == METADATA_FILENAME.as_bytes() {
21 let mut buf = Vec::new();
22 ::std::io::copy(&mut entry, &mut buf).map_err(|e| format!("{:?}", e))?;
23 let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
24 return Ok(rustc_erase_owner!(buf.map_owner_box()));
28 Err("couldn't find metadata entry".to_string())
29 //self.get_dylib_metadata(target, path)
32 fn get_dylib_metadata(
34 _target: &crate::rustc_target::spec::Target,
36 ) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
37 Err("dylib metadata loading is not yet supported".to_string())