2018-11-07 13:29:38 +01:00
|
|
|
use rustc::middle::cstore::MetadataLoader;
|
2019-04-20 17:35:58 +02:00
|
|
|
use rustc_codegen_ssa::METADATA_FILENAME;
|
2018-11-07 13:29:38 +01:00
|
|
|
use rustc_data_structures::owning_ref::{self, OwningRef};
|
2018-11-17 18:23:52 +01:00
|
|
|
use rustc_data_structures::rustc_erase_owner;
|
2018-08-15 14:45:32 +02:00
|
|
|
use std::fs::File;
|
|
|
|
use std::path::Path;
|
2018-08-15 12:07:08 +02:00
|
|
|
|
|
|
|
pub struct CraneliftMetadataLoader;
|
|
|
|
|
|
|
|
impl MetadataLoader for CraneliftMetadataLoader {
|
|
|
|
fn get_rlib_metadata(
|
|
|
|
&self,
|
2018-09-17 18:49:10 +02:00
|
|
|
_target: &crate::rustc_target::spec::Target,
|
2018-08-15 12:07:08 +02:00
|
|
|
path: &Path,
|
|
|
|
) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
|
|
|
|
let mut archive = ar::Archive::new(File::open(path).map_err(|e| format!("{:?}", e))?);
|
|
|
|
// Iterate over all entries in the archive:
|
|
|
|
while let Some(entry_result) = archive.next_entry() {
|
|
|
|
let mut entry = entry_result.map_err(|e| format!("{:?}", e))?;
|
2018-11-10 15:01:01 +01:00
|
|
|
if entry.header().identifier() == METADATA_FILENAME.as_bytes() {
|
2018-08-15 12:07:08 +02:00
|
|
|
let mut buf = Vec::new();
|
|
|
|
::std::io::copy(&mut entry, &mut buf).map_err(|e| format!("{:?}", e))?;
|
|
|
|
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
|
|
|
|
return Ok(rustc_erase_owner!(buf.map_owner_box()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Err("couldn't find metadata entry".to_string())
|
|
|
|
//self.get_dylib_metadata(target, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_dylib_metadata(
|
|
|
|
&self,
|
2018-09-17 18:49:10 +02:00
|
|
|
_target: &crate::rustc_target::spec::Target,
|
2018-08-15 12:07:08 +02:00
|
|
|
_path: &Path,
|
|
|
|
) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
|
|
|
|
Err("dylib metadata loading is not yet supported".to_string())
|
|
|
|
}
|
|
|
|
}
|