]> git.lizzy.rs Git - rust.git/blob - src/metadata.rs
Rustup to rustc 1.30.0-nightly (cb6d2dfa8 2018-09-16)
[rust.git] / src / metadata.rs
1 use crate::rustc::middle::cstore::MetadataLoader;
2 use crate::rustc_data_structures::owning_ref::{self, OwningRef};
3 use std::fs::File;
4 use std::path::Path;
5
6 pub struct CraneliftMetadataLoader;
7
8 impl MetadataLoader for CraneliftMetadataLoader {
9     fn get_rlib_metadata(
10         &self,
11         _target: &crate::rustc_target::spec::Target,
12         path: &Path,
13     ) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
14         let mut archive = ar::Archive::new(File::open(path).map_err(|e| format!("{:?}", e))?);
15         // Iterate over all entries in the archive:
16         while let Some(entry_result) = archive.next_entry() {
17             let mut entry = entry_result.map_err(|e| format!("{:?}", e))?;
18             if entry
19                 .header()
20                 .identifier()
21                 .starts_with(b".rustc.clif_metadata")
22             {
23                 let mut buf = Vec::new();
24                 ::std::io::copy(&mut entry, &mut buf).map_err(|e| format!("{:?}", e))?;
25                 let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
26                 return Ok(rustc_erase_owner!(buf.map_owner_box()));
27             }
28         }
29
30         Err("couldn't find metadata entry".to_string())
31         //self.get_dylib_metadata(target, path)
32     }
33
34     fn get_dylib_metadata(
35         &self,
36         _target: &crate::rustc_target::spec::Target,
37         _path: &Path,
38     ) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
39         Err("dylib metadata loading is not yet supported".to_string())
40     }
41 }