]> git.lizzy.rs Git - rust.git/blob - src/metadata.rs
Misc renames and changes
[rust.git] / src / metadata.rs
1 use rustc::middle::cstore::MetadataLoader;
2 use rustc_data_structures::owning_ref::{self, OwningRef};
3 use std::fs::File;
4 use std::path::Path;
5
6 pub const METADATA_FILENAME: &'static [u8] = b"rust.metadata.bin" as &[u8];
7
8 pub struct CraneliftMetadataLoader;
9
10 impl MetadataLoader for CraneliftMetadataLoader {
11     fn get_rlib_metadata(
12         &self,
13         _target: &crate::rustc_target::spec::Target,
14         path: &Path,
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 {
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()));
25             }
26         }
27
28         Err("couldn't find metadata entry".to_string())
29         //self.get_dylib_metadata(target, path)
30     }
31
32     fn get_dylib_metadata(
33         &self,
34         _target: &crate::rustc_target::spec::Target,
35         _path: &Path,
36     ) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
37         Err("dylib metadata loading is not yet supported".to_string())
38     }
39 }