mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Put metadata loader in its own file
This commit is contained in:
parent
5ea8bae114
commit
b752c88fef
58
src/lib.rs
58
src/lib.rs
@ -24,7 +24,6 @@ extern crate target_lexicon;
|
||||
|
||||
use std::any::Any;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::sync::{mpsc, Arc};
|
||||
|
||||
use rustc::dep_graph::DepGraph;
|
||||
@ -33,7 +32,6 @@ use rustc::session::{config::OutputFilenames, CompileIncomplete};
|
||||
use rustc::ty::query::Providers;
|
||||
use rustc_codegen_utils::codegen_backend::CodegenBackend;
|
||||
use rustc_codegen_utils::link::{build_link_meta, out_filename};
|
||||
use rustc_data_structures::owning_ref::{self, OwningRef};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use syntax::symbol::Symbol;
|
||||
|
||||
@ -63,6 +61,7 @@ mod base;
|
||||
mod common;
|
||||
mod constant;
|
||||
mod pretty_clif;
|
||||
mod metadata;
|
||||
|
||||
mod prelude {
|
||||
pub use std::any::Any;
|
||||
@ -125,59 +124,6 @@ pub struct ModuleTup<T> {
|
||||
faerie: Option<T>,
|
||||
}
|
||||
|
||||
struct CraneliftMetadataLoader;
|
||||
|
||||
impl MetadataLoader for CraneliftMetadataLoader {
|
||||
fn get_rlib_metadata(
|
||||
&self,
|
||||
_target: &rustc_target::spec::Target,
|
||||
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))?;
|
||||
if entry.header().identifier().starts_with(b".rustc.clif_metadata") {
|
||||
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,
|
||||
_target: &rustc_target::spec::Target,
|
||||
_path: &Path,
|
||||
) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
|
||||
//use goblin::Object;
|
||||
|
||||
//let buffer = ::std::fs::read(path).map_err(|e|format!("{:?}", e))?;
|
||||
/*match Object::parse(&buffer).map_err(|e|format!("{:?}", e))? {
|
||||
Object::Elf(elf) => {
|
||||
println!("elf: {:#?}", &elf);
|
||||
},
|
||||
Object::PE(pe) => {
|
||||
println!("pe: {:#?}", &pe);
|
||||
},
|
||||
Object::Mach(mach) => {
|
||||
println!("mach: {:#?}", &mach);
|
||||
},
|
||||
Object::Archive(archive) => {
|
||||
return Err(format!("archive: {:#?}", &archive));
|
||||
},
|
||||
Object::Unknown(magic) => {
|
||||
return Err(format!("unknown magic: {:#x}", magic))
|
||||
}
|
||||
}*/
|
||||
Err("dylib metadata loading is not yet supported".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
struct CraneliftCodegenBackend;
|
||||
|
||||
struct OngoingCodegen {
|
||||
@ -203,7 +149,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||
}
|
||||
|
||||
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> {
|
||||
Box::new(CraneliftMetadataLoader)
|
||||
Box::new(crate::metadata::CraneliftMetadataLoader)
|
||||
}
|
||||
|
||||
fn provide(&self, providers: &mut Providers) {
|
||||
|
57
src/metadata.rs
Normal file
57
src/metadata.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use std::path::Path;
|
||||
use std::fs::File;
|
||||
use rustc_data_structures::owning_ref::{self, OwningRef};
|
||||
use rustc::middle::cstore::MetadataLoader;
|
||||
|
||||
pub struct CraneliftMetadataLoader;
|
||||
|
||||
impl MetadataLoader for CraneliftMetadataLoader {
|
||||
fn get_rlib_metadata(
|
||||
&self,
|
||||
_target: &::rustc_target::spec::Target,
|
||||
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))?;
|
||||
if entry.header().identifier().starts_with(b".rustc.clif_metadata") {
|
||||
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,
|
||||
_target: &::rustc_target::spec::Target,
|
||||
_path: &Path,
|
||||
) -> Result<owning_ref::ErasedBoxRef<[u8]>, String> {
|
||||
//use goblin::Object;
|
||||
|
||||
//let buffer = ::std::fs::read(path).map_err(|e|format!("{:?}", e))?;
|
||||
/*match Object::parse(&buffer).map_err(|e|format!("{:?}", e))? {
|
||||
Object::Elf(elf) => {
|
||||
println!("elf: {:#?}", &elf);
|
||||
},
|
||||
Object::PE(pe) => {
|
||||
println!("pe: {:#?}", &pe);
|
||||
},
|
||||
Object::Mach(mach) => {
|
||||
println!("mach: {:#?}", &mach);
|
||||
},
|
||||
Object::Archive(archive) => {
|
||||
return Err(format!("archive: {:#?}", &archive));
|
||||
},
|
||||
Object::Unknown(magic) => {
|
||||
return Err(format!("unknown magic: {:#x}", magic))
|
||||
}
|
||||
}*/
|
||||
Err("dylib metadata loading is not yet supported".to_string())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user