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