Auto merge of #37681 - nrc:crate-metadata, r=@alexcrichton
add --crate-type metadata r? @alexcrichton
This commit is contained in:
commit
5196ca8518
@ -56,12 +56,13 @@ pub struct LinkMeta {
|
|||||||
pub crate_hash: Svh,
|
pub crate_hash: Svh,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where a crate came from on the local filesystem. One of these two options
|
// Where a crate came from on the local filesystem. One of these three options
|
||||||
// must be non-None.
|
// must be non-None.
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
pub struct CrateSource {
|
pub struct CrateSource {
|
||||||
pub dylib: Option<(PathBuf, PathKind)>,
|
pub dylib: Option<(PathBuf, PathKind)>,
|
||||||
pub rlib: Option<(PathBuf, PathKind)>,
|
pub rlib: Option<(PathBuf, PathKind)>,
|
||||||
|
pub rmeta: Option<(PathBuf, PathKind)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
||||||
@ -76,6 +77,30 @@ pub enum DepKind {
|
|||||||
Explicit,
|
Explicit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
|
pub enum LibSource {
|
||||||
|
Some(PathBuf),
|
||||||
|
MetadataOnly,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LibSource {
|
||||||
|
pub fn is_some(&self) -> bool {
|
||||||
|
if let LibSource::Some(_) = *self {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn option(&self) -> Option<PathBuf> {
|
||||||
|
match *self {
|
||||||
|
LibSource::Some(ref p) => Some(p.clone()),
|
||||||
|
LibSource::MetadataOnly | LibSource::None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
|
||||||
pub enum LinkagePreference {
|
pub enum LinkagePreference {
|
||||||
RequireDynamic,
|
RequireDynamic,
|
||||||
@ -244,7 +269,7 @@ pub trait CrateStore<'tcx> {
|
|||||||
// utility functions
|
// utility functions
|
||||||
fn metadata_filename(&self) -> &str;
|
fn metadata_filename(&self) -> &str;
|
||||||
fn metadata_section_name(&self, target: &Target) -> &str;
|
fn metadata_section_name(&self, target: &Target) -> &str;
|
||||||
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, Option<PathBuf>)>;
|
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
|
||||||
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
|
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
|
||||||
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
|
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
|
||||||
fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
@ -427,7 +452,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||||||
// utility functions
|
// utility functions
|
||||||
fn metadata_filename(&self) -> &str { bug!("metadata_filename") }
|
fn metadata_filename(&self) -> &str { bug!("metadata_filename") }
|
||||||
fn metadata_section_name(&self, target: &Target) -> &str { bug!("metadata_section_name") }
|
fn metadata_section_name(&self, target: &Target) -> &str { bug!("metadata_section_name") }
|
||||||
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, Option<PathBuf>)>
|
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
|
||||||
{ vec![] }
|
{ vec![] }
|
||||||
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
|
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
|
||||||
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
|
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
|
||||||
|
@ -114,7 +114,7 @@ fn calculate_type(sess: &session::Session,
|
|||||||
|
|
||||||
// No linkage happens with rlibs, we just needed the metadata (which we
|
// No linkage happens with rlibs, we just needed the metadata (which we
|
||||||
// got long ago), so don't bother with anything.
|
// got long ago), so don't bother with anything.
|
||||||
config::CrateTypeRlib => return Vec::new(),
|
config::CrateTypeRlib | config::CrateTypeMetadata => return Vec::new(),
|
||||||
|
|
||||||
// Staticlibs and cdylibs must have all static dependencies. If any fail
|
// Staticlibs and cdylibs must have all static dependencies. If any fail
|
||||||
// to be found, we generate some nice pretty errors.
|
// to be found, we generate some nice pretty errors.
|
||||||
@ -192,7 +192,7 @@ fn calculate_type(sess: &session::Session,
|
|||||||
if src.dylib.is_none() &&
|
if src.dylib.is_none() &&
|
||||||
!formats.contains_key(&cnum) &&
|
!formats.contains_key(&cnum) &&
|
||||||
sess.cstore.dep_kind(cnum) == DepKind::Explicit {
|
sess.cstore.dep_kind(cnum) == DepKind::Explicit {
|
||||||
assert!(src.rlib.is_some());
|
assert!(src.rlib.is_some() || src.rmeta.is_some());
|
||||||
info!("adding staticlib: {}", sess.cstore.crate_name(cnum));
|
info!("adding staticlib: {}", sess.cstore.crate_name(cnum));
|
||||||
add_library(sess, cnum, RequireStatic, &mut formats);
|
add_library(sess, cnum, RequireStatic, &mut formats);
|
||||||
ret[cnum.as_usize() - 1] = Linkage::Static;
|
ret[cnum.as_usize() - 1] = Linkage::Static;
|
||||||
|
@ -140,7 +140,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
|
|||||||
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
|
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ReachableContext<'a, 'tcx> {
|
||||||
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
|
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
|
||||||
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
|
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||
|
||||||
*ty == config::CrateTypeProcMacro
|
*ty == config::CrateTypeProcMacro || *ty == config::CrateTypeMetadata
|
||||||
});
|
});
|
||||||
ReachableContext {
|
ReachableContext {
|
||||||
tcx: tcx,
|
tcx: tcx,
|
||||||
|
@ -75,7 +75,8 @@ fn verify(sess: &Session, items: &lang_items::LanguageItems) {
|
|||||||
config::CrateTypeCdylib |
|
config::CrateTypeCdylib |
|
||||||
config::CrateTypeExecutable |
|
config::CrateTypeExecutable |
|
||||||
config::CrateTypeStaticlib => true,
|
config::CrateTypeStaticlib => true,
|
||||||
config::CrateTypeRlib => false,
|
config::CrateTypeRlib |
|
||||||
|
config::CrateTypeMetadata => false,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if !needs_check {
|
if !needs_check {
|
||||||
|
@ -78,18 +78,6 @@ pub enum OutputType {
|
|||||||
DepInfo,
|
DepInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub enum ErrorOutputType {
|
|
||||||
HumanReadable(ColorConfig),
|
|
||||||
Json,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ErrorOutputType {
|
|
||||||
fn default() -> ErrorOutputType {
|
|
||||||
ErrorOutputType::HumanReadable(ColorConfig::Auto)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OutputType {
|
impl OutputType {
|
||||||
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
|
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
@ -125,6 +113,18 @@ impl OutputType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum ErrorOutputType {
|
||||||
|
HumanReadable(ColorConfig),
|
||||||
|
Json,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ErrorOutputType {
|
||||||
|
fn default() -> ErrorOutputType {
|
||||||
|
ErrorOutputType::HumanReadable(ColorConfig::Auto)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Use tree-based collections to cheaply get a deterministic Hash implementation.
|
// Use tree-based collections to cheaply get a deterministic Hash implementation.
|
||||||
// DO NOT switch BTreeMap out for an unsorted container type! That would break
|
// DO NOT switch BTreeMap out for an unsorted container type! That would break
|
||||||
// dependency tracking for commandline arguments.
|
// dependency tracking for commandline arguments.
|
||||||
@ -483,6 +483,7 @@ pub enum CrateType {
|
|||||||
CrateTypeStaticlib,
|
CrateTypeStaticlib,
|
||||||
CrateTypeCdylib,
|
CrateTypeCdylib,
|
||||||
CrateTypeProcMacro,
|
CrateTypeProcMacro,
|
||||||
|
CrateTypeMetadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Hash)]
|
#[derive(Clone, Hash)]
|
||||||
@ -1147,7 +1148,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
|
|||||||
assumed.", "[KIND=]NAME"),
|
assumed.", "[KIND=]NAME"),
|
||||||
opt::multi_s("", "crate-type", "Comma separated list of types of crates
|
opt::multi_s("", "crate-type", "Comma separated list of types of crates
|
||||||
for the compiler to emit",
|
for the compiler to emit",
|
||||||
"[bin|lib|rlib|dylib|cdylib|staticlib]"),
|
"[bin|lib|rlib|dylib|cdylib|staticlib|metadata]"),
|
||||||
opt::opt_s("", "crate-name", "Specify the name of the crate being built",
|
opt::opt_s("", "crate-name", "Specify the name of the crate being built",
|
||||||
"NAME"),
|
"NAME"),
|
||||||
opt::multi_s("", "emit", "Comma separated list of types of output for \
|
opt::multi_s("", "emit", "Comma separated list of types of output for \
|
||||||
@ -1539,6 +1540,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
|
|||||||
"cdylib" => CrateTypeCdylib,
|
"cdylib" => CrateTypeCdylib,
|
||||||
"bin" => CrateTypeExecutable,
|
"bin" => CrateTypeExecutable,
|
||||||
"proc-macro" => CrateTypeProcMacro,
|
"proc-macro" => CrateTypeProcMacro,
|
||||||
|
"metadata" => CrateTypeMetadata,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(format!("unknown crate type: `{}`",
|
return Err(format!("unknown crate type: `{}`",
|
||||||
part));
|
part));
|
||||||
@ -1623,6 +1625,7 @@ impl fmt::Display for CrateType {
|
|||||||
CrateTypeStaticlib => "staticlib".fmt(f),
|
CrateTypeStaticlib => "staticlib".fmt(f),
|
||||||
CrateTypeCdylib => "cdylib".fmt(f),
|
CrateTypeCdylib => "cdylib".fmt(f),
|
||||||
CrateTypeProcMacro => "proc-macro".fmt(f),
|
CrateTypeProcMacro => "proc-macro".fmt(f),
|
||||||
|
CrateTypeMetadata => "metadata".fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1182,6 +1182,9 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
|
|||||||
Some(ref n) if *n == "rlib" => {
|
Some(ref n) if *n == "rlib" => {
|
||||||
Some(config::CrateTypeRlib)
|
Some(config::CrateTypeRlib)
|
||||||
}
|
}
|
||||||
|
Some(ref n) if *n == "metadata" => {
|
||||||
|
Some(config::CrateTypeMetadata)
|
||||||
|
}
|
||||||
Some(ref n) if *n == "dylib" => {
|
Some(ref n) if *n == "dylib" => {
|
||||||
Some(config::CrateTypeDylib)
|
Some(config::CrateTypeDylib)
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ use log;
|
|||||||
pub struct Library {
|
pub struct Library {
|
||||||
pub dylib: Option<(PathBuf, PathKind)>,
|
pub dylib: Option<(PathBuf, PathKind)>,
|
||||||
pub rlib: Option<(PathBuf, PathKind)>,
|
pub rlib: Option<(PathBuf, PathKind)>,
|
||||||
|
pub rmeta: Option<(PathBuf, PathKind)>,
|
||||||
pub metadata: MetadataBlob,
|
pub metadata: MetadataBlob,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,10 +63,11 @@ fn dump_crates(cstore: &CStore) {
|
|||||||
info!(" cnum: {}", data.cnum);
|
info!(" cnum: {}", data.cnum);
|
||||||
info!(" hash: {}", data.hash());
|
info!(" hash: {}", data.hash());
|
||||||
info!(" reqd: {:?}", data.dep_kind.get());
|
info!(" reqd: {:?}", data.dep_kind.get());
|
||||||
let CrateSource { dylib, rlib } = data.source.clone();
|
let CrateSource { dylib, rlib, rmeta } = data.source.clone();
|
||||||
dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
|
dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
|
||||||
rlib.map(|rl| info!(" rlib: {}", rl.0.display()));
|
rlib.map(|rl| info!(" rlib: {}", rl.0.display()));
|
||||||
})
|
rmeta.map(|rl| info!(" rmeta: {}", rl.0.display()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -278,6 +280,7 @@ impl<'a> CrateLoader<'a> {
|
|||||||
ident: ident.to_string(),
|
ident: ident.to_string(),
|
||||||
dylib: lib.dylib.clone().map(|p| p.0),
|
dylib: lib.dylib.clone().map(|p| p.0),
|
||||||
rlib: lib.rlib.clone().map(|p| p.0),
|
rlib: lib.rlib.clone().map(|p| p.0),
|
||||||
|
rmeta: lib.rmeta.clone().map(|p| p.0),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -285,7 +288,7 @@ impl<'a> CrateLoader<'a> {
|
|||||||
// Maintain a reference to the top most crate.
|
// Maintain a reference to the top most crate.
|
||||||
let root = if root.is_some() { root } else { &crate_paths };
|
let root = if root.is_some() { root } else { &crate_paths };
|
||||||
|
|
||||||
let Library { dylib, rlib, metadata } = lib;
|
let Library { dylib, rlib, rmeta, metadata } = lib;
|
||||||
|
|
||||||
let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span, dep_kind);
|
let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span, dep_kind);
|
||||||
|
|
||||||
@ -305,6 +308,7 @@ impl<'a> CrateLoader<'a> {
|
|||||||
source: cstore::CrateSource {
|
source: cstore::CrateSource {
|
||||||
dylib: dylib,
|
dylib: dylib,
|
||||||
rlib: rlib,
|
rlib: rlib,
|
||||||
|
rmeta: rmeta,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -767,7 +771,8 @@ impl<'a> CrateLoader<'a> {
|
|||||||
config::CrateTypeProcMacro |
|
config::CrateTypeProcMacro |
|
||||||
config::CrateTypeCdylib |
|
config::CrateTypeCdylib |
|
||||||
config::CrateTypeStaticlib => need_lib_alloc = true,
|
config::CrateTypeStaticlib => need_lib_alloc = true,
|
||||||
config::CrateTypeRlib => {}
|
config::CrateTypeRlib |
|
||||||
|
config::CrateTypeMetadata => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !need_lib_alloc && !need_exe_alloc { return }
|
if !need_lib_alloc && !need_exe_alloc { return }
|
||||||
|
@ -25,7 +25,6 @@ use rustc::util::nodemap::{FxHashMap, NodeMap, NodeSet, DefIdMap};
|
|||||||
|
|
||||||
use std::cell::{RefCell, Cell};
|
use std::cell::{RefCell, Cell};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::path::PathBuf;
|
|
||||||
use flate::Bytes;
|
use flate::Bytes;
|
||||||
use syntax::{ast, attr};
|
use syntax::{ast, attr};
|
||||||
use syntax::ext::base::SyntaxExtension;
|
use syntax::ext::base::SyntaxExtension;
|
||||||
@ -34,7 +33,7 @@ use syntax_pos;
|
|||||||
|
|
||||||
pub use rustc::middle::cstore::{NativeLibrary, LinkagePreference};
|
pub use rustc::middle::cstore::{NativeLibrary, LinkagePreference};
|
||||||
pub use rustc::middle::cstore::{NativeStatic, NativeFramework, NativeUnknown};
|
pub use rustc::middle::cstore::{NativeStatic, NativeFramework, NativeUnknown};
|
||||||
pub use rustc::middle::cstore::{CrateSource, LinkMeta};
|
pub use rustc::middle::cstore::{CrateSource, LinkMeta, LibSource};
|
||||||
|
|
||||||
// A map from external crate numbers (as decoded from some crate file) to
|
// A map from external crate numbers (as decoded from some crate file) to
|
||||||
// local crate numbers (as generated during this session). Each external
|
// local crate numbers (as generated during this session). Each external
|
||||||
@ -45,6 +44,7 @@ pub type CrateNumMap = IndexVec<CrateNum, CrateNum>;
|
|||||||
pub enum MetadataBlob {
|
pub enum MetadataBlob {
|
||||||
Inflated(Bytes),
|
Inflated(Bytes),
|
||||||
Archive(locator::ArchiveMetadata),
|
Archive(locator::ArchiveMetadata),
|
||||||
|
Raw(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Holds information about a syntax_pos::FileMap imported from another crate.
|
/// Holds information about a syntax_pos::FileMap imported from another crate.
|
||||||
@ -186,7 +186,7 @@ impl CStore {
|
|||||||
// positions.
|
// positions.
|
||||||
pub fn do_get_used_crates(&self,
|
pub fn do_get_used_crates(&self,
|
||||||
prefer: LinkagePreference)
|
prefer: LinkagePreference)
|
||||||
-> Vec<(CrateNum, Option<PathBuf>)> {
|
-> Vec<(CrateNum, LibSource)> {
|
||||||
let mut ordering = Vec::new();
|
let mut ordering = Vec::new();
|
||||||
for (&num, _) in self.metas.borrow().iter() {
|
for (&num, _) in self.metas.borrow().iter() {
|
||||||
self.push_dependencies_in_postorder(&mut ordering, num);
|
self.push_dependencies_in_postorder(&mut ordering, num);
|
||||||
@ -202,6 +202,16 @@ impl CStore {
|
|||||||
LinkagePreference::RequireDynamic => data.source.dylib.clone().map(|p| p.0),
|
LinkagePreference::RequireDynamic => data.source.dylib.clone().map(|p| p.0),
|
||||||
LinkagePreference::RequireStatic => data.source.rlib.clone().map(|p| p.0),
|
LinkagePreference::RequireStatic => data.source.rlib.clone().map(|p| p.0),
|
||||||
};
|
};
|
||||||
|
let path = match path {
|
||||||
|
Some(p) => LibSource::Some(p),
|
||||||
|
None => {
|
||||||
|
if data.source.rmeta.is_some() {
|
||||||
|
LibSource::MetadataOnly
|
||||||
|
} else {
|
||||||
|
LibSource::None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Some((cnum, path))
|
Some((cnum, path))
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -13,7 +13,7 @@ use encoder;
|
|||||||
use locator;
|
use locator;
|
||||||
use schema;
|
use schema;
|
||||||
|
|
||||||
use rustc::middle::cstore::{InlinedItem, CrateStore, CrateSource, DepKind, ExternCrate};
|
use rustc::middle::cstore::{InlinedItem, CrateStore, CrateSource, LibSource, DepKind, ExternCrate};
|
||||||
use rustc::middle::cstore::{NativeLibrary, LinkMeta, LinkagePreference, LoadedMacro};
|
use rustc::middle::cstore::{NativeLibrary, LinkMeta, LinkagePreference, LoadedMacro};
|
||||||
use rustc::hir::def::{self, Def};
|
use rustc::hir::def::{self, Def};
|
||||||
use rustc::middle::lang_items;
|
use rustc::middle::lang_items;
|
||||||
@ -28,7 +28,6 @@ use rustc::mir::Mir;
|
|||||||
use rustc::util::nodemap::{NodeSet, DefIdMap};
|
use rustc::util::nodemap::{NodeSet, DefIdMap};
|
||||||
use rustc_back::PanicStrategy;
|
use rustc_back::PanicStrategy;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::parse::new_parser_from_source_str;
|
use syntax::parse::new_parser_from_source_str;
|
||||||
@ -545,7 +544,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||||||
locator::meta_section_name(target)
|
locator::meta_section_name(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, Option<PathBuf>)>
|
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
|
||||||
{
|
{
|
||||||
self.do_get_used_crates(prefer)
|
self.do_get_used_crates(prefer)
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,9 @@ pub trait Metadata<'a, 'tcx>: Copy {
|
|||||||
impl<'a, 'tcx> Metadata<'a, 'tcx> for &'a MetadataBlob {
|
impl<'a, 'tcx> Metadata<'a, 'tcx> for &'a MetadataBlob {
|
||||||
fn raw_bytes(self) -> &'a [u8] {
|
fn raw_bytes(self) -> &'a [u8] {
|
||||||
match *self {
|
match *self {
|
||||||
MetadataBlob::Inflated(ref vec) => &vec[..],
|
MetadataBlob::Inflated(ref vec) => vec,
|
||||||
MetadataBlob::Archive(ref ar) => ar.as_slice(),
|
MetadataBlob::Archive(ref ar) => ar.as_slice(),
|
||||||
|
MetadataBlob::Raw(ref vec) => vec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,13 @@
|
|||||||
//! is a platform-defined dynamic library. Each library has a metadata somewhere
|
//! is a platform-defined dynamic library. Each library has a metadata somewhere
|
||||||
//! inside of it.
|
//! inside of it.
|
||||||
//!
|
//!
|
||||||
|
//! A third kind of dependency is an rmeta file. These are metadata files and do
|
||||||
|
//! not contain any code, etc. To a first approximation, these are treated in the
|
||||||
|
//! same way as rlibs. Where there is both an rlib and an rmeta file, the rlib
|
||||||
|
//! gets priority (even if the rmeta file is newer). An rmeta file is only
|
||||||
|
//! useful for checking a downstream crate, attempting to link one will cause an
|
||||||
|
//! error.
|
||||||
|
//!
|
||||||
//! When translating a crate name to a crate on the filesystem, we all of a
|
//! When translating a crate name to a crate on the filesystem, we all of a
|
||||||
//! sudden need to take into account both rlibs and dylibs! Linkage later on may
|
//! sudden need to take into account both rlibs and dylibs! Linkage later on may
|
||||||
//! use either one of these files, as each has their pros/cons. The job of crate
|
//! use either one of these files, as each has their pros/cons. The job of crate
|
||||||
@ -233,8 +240,8 @@ use rustc_back::target::Target;
|
|||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs;
|
use std::fs::{self, File};
|
||||||
use std::io;
|
use std::io::{self, Read};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
@ -276,6 +283,7 @@ pub struct CratePaths {
|
|||||||
pub ident: String,
|
pub ident: String,
|
||||||
pub dylib: Option<PathBuf>,
|
pub dylib: Option<PathBuf>,
|
||||||
pub rlib: Option<PathBuf>,
|
pub rlib: Option<PathBuf>,
|
||||||
|
pub rmeta: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const METADATA_FILENAME: &'static str = "rust.metadata.bin";
|
pub const METADATA_FILENAME: &'static str = "rust.metadata.bin";
|
||||||
@ -283,6 +291,7 @@ pub const METADATA_FILENAME: &'static str = "rust.metadata.bin";
|
|||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
enum CrateFlavor {
|
enum CrateFlavor {
|
||||||
Rlib,
|
Rlib,
|
||||||
|
Rmeta,
|
||||||
Dylib,
|
Dylib,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,6 +299,7 @@ impl fmt::Display for CrateFlavor {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
f.write_str(match *self {
|
f.write_str(match *self {
|
||||||
CrateFlavor::Rlib => "rlib",
|
CrateFlavor::Rlib => "rlib",
|
||||||
|
CrateFlavor::Rmeta => "rmeta",
|
||||||
CrateFlavor::Dylib => "dylib",
|
CrateFlavor::Dylib => "dylib",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -297,12 +307,7 @@ impl fmt::Display for CrateFlavor {
|
|||||||
|
|
||||||
impl CratePaths {
|
impl CratePaths {
|
||||||
fn paths(&self) -> Vec<PathBuf> {
|
fn paths(&self) -> Vec<PathBuf> {
|
||||||
match (&self.dylib, &self.rlib) {
|
self.dylib.iter().chain(self.rlib.iter()).chain(self.rmeta.iter()).cloned().collect()
|
||||||
(&None, &None) => vec![],
|
|
||||||
(&Some(ref p), &None) |
|
|
||||||
(&None, &Some(ref p)) => vec![p.clone()],
|
|
||||||
(&Some(ref p1), &Some(ref p2)) => vec![p1.clone(), p2.clone()],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,32 +463,35 @@ impl<'a> Context<'a> {
|
|||||||
None => return FileDoesntMatch,
|
None => return FileDoesntMatch,
|
||||||
Some(file) => file,
|
Some(file) => file,
|
||||||
};
|
};
|
||||||
let (hash, rlib) = if file.starts_with(&rlib_prefix[..]) && file.ends_with(".rlib") {
|
let (hash, found_kind) =
|
||||||
(&file[(rlib_prefix.len())..(file.len() - ".rlib".len())], true)
|
if file.starts_with(&rlib_prefix[..]) && file.ends_with(".rlib") {
|
||||||
} else if file.starts_with(&dylib_prefix) &&
|
(&file[(rlib_prefix.len())..(file.len() - ".rlib".len())], CrateFlavor::Rlib)
|
||||||
file.ends_with(&dypair.1) {
|
} else if file.starts_with(&rlib_prefix[..]) && file.ends_with(".rmeta") {
|
||||||
(&file[(dylib_prefix.len())..(file.len() - dypair.1.len())], false)
|
(&file[(rlib_prefix.len())..(file.len() - ".rmeta".len())], CrateFlavor::Rmeta)
|
||||||
} else {
|
} else if file.starts_with(&dylib_prefix) &&
|
||||||
if file.starts_with(&staticlib_prefix[..]) && file.ends_with(&staticpair.1) {
|
file.ends_with(&dypair.1) {
|
||||||
staticlibs.push(CrateMismatch {
|
(&file[(dylib_prefix.len())..(file.len() - dypair.1.len())], CrateFlavor::Dylib)
|
||||||
path: path.to_path_buf(),
|
} else {
|
||||||
got: "static".to_string(),
|
if file.starts_with(&staticlib_prefix[..]) && file.ends_with(&staticpair.1) {
|
||||||
});
|
staticlibs.push(CrateMismatch {
|
||||||
}
|
path: path.to_path_buf(),
|
||||||
return FileDoesntMatch;
|
got: "static".to_string(),
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
return FileDoesntMatch;
|
||||||
|
};
|
||||||
info!("lib candidate: {}", path.display());
|
info!("lib candidate: {}", path.display());
|
||||||
|
|
||||||
let hash_str = hash.to_string();
|
let hash_str = hash.to_string();
|
||||||
let slot = candidates.entry(hash_str)
|
let slot = candidates.entry(hash_str)
|
||||||
.or_insert_with(|| (FxHashMap(), FxHashMap()));
|
.or_insert_with(|| (FxHashMap(), FxHashMap(), FxHashMap()));
|
||||||
let (ref mut rlibs, ref mut dylibs) = *slot;
|
let (ref mut rlibs, ref mut rmetas, ref mut dylibs) = *slot;
|
||||||
fs::canonicalize(path)
|
fs::canonicalize(path)
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
if rlib {
|
match found_kind {
|
||||||
rlibs.insert(p, kind);
|
CrateFlavor::Rlib => { rlibs.insert(p, kind); }
|
||||||
} else {
|
CrateFlavor::Rmeta => { rmetas.insert(p, kind); }
|
||||||
dylibs.insert(p, kind);
|
CrateFlavor::Dylib => { dylibs.insert(p, kind); }
|
||||||
}
|
}
|
||||||
FileMatches
|
FileMatches
|
||||||
})
|
})
|
||||||
@ -500,15 +508,17 @@ impl<'a> Context<'a> {
|
|||||||
// libraries corresponds to the crate id and hash criteria that this
|
// libraries corresponds to the crate id and hash criteria that this
|
||||||
// search is being performed for.
|
// search is being performed for.
|
||||||
let mut libraries = FxHashMap();
|
let mut libraries = FxHashMap();
|
||||||
for (_hash, (rlibs, dylibs)) in candidates {
|
for (_hash, (rlibs, rmetas, dylibs)) in candidates {
|
||||||
let mut slot = None;
|
let mut slot = None;
|
||||||
let rlib = self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot);
|
let rlib = self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot);
|
||||||
|
let rmeta = self.extract_one(rmetas, CrateFlavor::Rmeta, &mut slot);
|
||||||
let dylib = self.extract_one(dylibs, CrateFlavor::Dylib, &mut slot);
|
let dylib = self.extract_one(dylibs, CrateFlavor::Dylib, &mut slot);
|
||||||
if let Some((h, m)) = slot {
|
if let Some((h, m)) = slot {
|
||||||
libraries.insert(h,
|
libraries.insert(h,
|
||||||
Library {
|
Library {
|
||||||
dylib: dylib,
|
dylib: dylib,
|
||||||
rlib: rlib,
|
rlib: rlib,
|
||||||
|
rmeta: rmeta,
|
||||||
metadata: m,
|
metadata: m,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -704,6 +714,7 @@ impl<'a> Context<'a> {
|
|||||||
let sess = self.sess;
|
let sess = self.sess;
|
||||||
let dylibname = self.dylibname();
|
let dylibname = self.dylibname();
|
||||||
let mut rlibs = FxHashMap();
|
let mut rlibs = FxHashMap();
|
||||||
|
let mut rmetas = FxHashMap();
|
||||||
let mut dylibs = FxHashMap();
|
let mut dylibs = FxHashMap();
|
||||||
{
|
{
|
||||||
let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
|
let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
|
||||||
@ -722,7 +733,8 @@ impl<'a> Context<'a> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if file.starts_with("lib") && file.ends_with(".rlib") {
|
if file.starts_with("lib") &&
|
||||||
|
(file.ends_with(".rlib") || file.ends_with(".rmeta")) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
let (ref prefix, ref suffix) = dylibname;
|
let (ref prefix, ref suffix) = dylibname;
|
||||||
@ -745,6 +757,8 @@ impl<'a> Context<'a> {
|
|||||||
for loc in locs {
|
for loc in locs {
|
||||||
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
|
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
|
||||||
rlibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
|
rlibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
|
||||||
|
} else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") {
|
||||||
|
rmetas.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
|
||||||
} else {
|
} else {
|
||||||
dylibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
|
dylibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag);
|
||||||
}
|
}
|
||||||
@ -754,9 +768,10 @@ impl<'a> Context<'a> {
|
|||||||
// Extract the rlib/dylib pair.
|
// Extract the rlib/dylib pair.
|
||||||
let mut slot = None;
|
let mut slot = None;
|
||||||
let rlib = self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot);
|
let rlib = self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot);
|
||||||
|
let rmeta = self.extract_one(rmetas, CrateFlavor::Rmeta, &mut slot);
|
||||||
let dylib = self.extract_one(dylibs, CrateFlavor::Dylib, &mut slot);
|
let dylib = self.extract_one(dylibs, CrateFlavor::Dylib, &mut slot);
|
||||||
|
|
||||||
if rlib.is_none() && dylib.is_none() {
|
if rlib.is_none() && rmeta.is_none() && dylib.is_none() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
match slot {
|
match slot {
|
||||||
@ -764,6 +779,7 @@ impl<'a> Context<'a> {
|
|||||||
Some(Library {
|
Some(Library {
|
||||||
dylib: dylib,
|
dylib: dylib,
|
||||||
rlib: rlib,
|
rlib: rlib,
|
||||||
|
rmeta: rmeta,
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -851,6 +867,15 @@ fn get_metadata_section_imp(target: &Target,
|
|||||||
Ok(blob)
|
Ok(blob)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
} else if flavor == CrateFlavor::Rmeta {
|
||||||
|
let mut file = File::open(filename).map_err(|_|
|
||||||
|
format!("could not open file: '{}'", filename.display()))?;
|
||||||
|
let mut buf = vec![];
|
||||||
|
file.read_to_end(&mut buf).map_err(|_|
|
||||||
|
format!("failed to read rlib metadata: '{}'", filename.display()))?;
|
||||||
|
let blob = MetadataBlob::Raw(buf);
|
||||||
|
verify_decompressed_encoding_version(&blob, filename)?;
|
||||||
|
return Ok(blob);
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
let buf = common::path2cstr(filename);
|
let buf = common::path2cstr(filename);
|
||||||
@ -934,6 +959,8 @@ pub fn list_file_metadata(target: &Target, path: &Path, out: &mut io::Write) ->
|
|||||||
let filename = path.file_name().unwrap().to_str().unwrap();
|
let filename = path.file_name().unwrap().to_str().unwrap();
|
||||||
let flavor = if filename.ends_with(".rlib") {
|
let flavor = if filename.ends_with(".rlib") {
|
||||||
CrateFlavor::Rlib
|
CrateFlavor::Rlib
|
||||||
|
} else if filename.ends_with(".rmeta") {
|
||||||
|
CrateFlavor::Rmeta
|
||||||
} else {
|
} else {
|
||||||
CrateFlavor::Dylib
|
CrateFlavor::Dylib
|
||||||
};
|
};
|
||||||
|
@ -231,7 +231,7 @@ impl<'a> ArchiveBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
|
fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
|
||||||
let kind = &self.config.sess.target.target.options.archive_format[..];
|
let kind = &*self.config.sess.target.target.options.archive_format;
|
||||||
kind.parse().map_err(|_| kind)
|
kind.parse().map_err(|_| kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ use session::config::{OutputFilenames, Input, OutputType};
|
|||||||
use session::filesearch;
|
use session::filesearch;
|
||||||
use session::search_paths::PathKind;
|
use session::search_paths::PathKind;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
use middle::cstore::{self, LinkMeta, NativeLibrary};
|
use middle::cstore::{self, LinkMeta, NativeLibrary, LibSource};
|
||||||
use middle::cstore::{LinkagePreference, NativeLibraryKind};
|
use middle::cstore::{LinkagePreference, NativeLibraryKind};
|
||||||
use middle::dependency_format::Linkage;
|
use middle::dependency_format::Linkage;
|
||||||
use CrateTranslation;
|
use CrateTranslation;
|
||||||
@ -124,7 +124,6 @@ pub fn find_crate_name(sess: Option<&Session>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
"rust_out".to_string()
|
"rust_out".to_string()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap,
|
pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap,
|
||||||
@ -264,6 +263,9 @@ pub fn filename_for_input(sess: &Session,
|
|||||||
config::CrateTypeRlib => {
|
config::CrateTypeRlib => {
|
||||||
outputs.out_directory.join(&format!("lib{}.rlib", libname))
|
outputs.out_directory.join(&format!("lib{}.rlib", libname))
|
||||||
}
|
}
|
||||||
|
config::CrateTypeMetadata => {
|
||||||
|
outputs.out_directory.join(&format!("lib{}.rmeta", libname))
|
||||||
|
}
|
||||||
config::CrateTypeCdylib |
|
config::CrateTypeCdylib |
|
||||||
config::CrateTypeProcMacro |
|
config::CrateTypeProcMacro |
|
||||||
config::CrateTypeDylib => {
|
config::CrateTypeDylib => {
|
||||||
@ -299,7 +301,7 @@ pub fn each_linked_rlib(sess: &Session,
|
|||||||
.or_else(|| fmts.get(&config::CrateTypeCdylib))
|
.or_else(|| fmts.get(&config::CrateTypeCdylib))
|
||||||
.or_else(|| fmts.get(&config::CrateTypeProcMacro));
|
.or_else(|| fmts.get(&config::CrateTypeProcMacro));
|
||||||
let fmts = fmts.unwrap_or_else(|| {
|
let fmts = fmts.unwrap_or_else(|| {
|
||||||
bug!("could not find formats for rlibs")
|
bug!("could not find formats for rlibs");
|
||||||
});
|
});
|
||||||
for (cnum, path) in crates {
|
for (cnum, path) in crates {
|
||||||
match fmts[cnum.as_usize() - 1] {
|
match fmts[cnum.as_usize() - 1] {
|
||||||
@ -308,8 +310,12 @@ pub fn each_linked_rlib(sess: &Session,
|
|||||||
}
|
}
|
||||||
let name = sess.cstore.crate_name(cnum).clone();
|
let name = sess.cstore.crate_name(cnum).clone();
|
||||||
let path = match path {
|
let path = match path {
|
||||||
Some(p) => p,
|
LibSource::Some(p) => p,
|
||||||
None => {
|
LibSource::MetadataOnly => {
|
||||||
|
sess.fatal(&format!("could not find rlib for: `{}`, found rmeta (metadata) file",
|
||||||
|
name));
|
||||||
|
}
|
||||||
|
LibSource::None => {
|
||||||
sess.fatal(&format!("could not find rlib for: `{}`", name));
|
sess.fatal(&format!("could not find rlib for: `{}`", name));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -353,6 +359,9 @@ fn link_binary_output(sess: &Session,
|
|||||||
config::CrateTypeStaticlib => {
|
config::CrateTypeStaticlib => {
|
||||||
link_staticlib(sess, &objects, &out_filename, tmpdir.path());
|
link_staticlib(sess, &objects, &out_filename, tmpdir.path());
|
||||||
}
|
}
|
||||||
|
config::CrateTypeMetadata => {
|
||||||
|
emit_metadata(sess, trans, &out_filename);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
link_natively(sess, crate_type, &objects, &out_filename, trans,
|
link_natively(sess, crate_type, &objects, &out_filename, trans,
|
||||||
outputs, tmpdir.path());
|
outputs, tmpdir.path());
|
||||||
@ -391,6 +400,13 @@ fn archive_config<'a>(sess: &'a Session,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn emit_metadata<'a>(sess: &'a Session, trans: &CrateTranslation, out_filename: &Path) {
|
||||||
|
let result = fs::File::create(out_filename).and_then(|mut f| f.write_all(&trans.metadata));
|
||||||
|
if let Err(e) = result {
|
||||||
|
sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create an 'rlib'
|
// Create an 'rlib'
|
||||||
//
|
//
|
||||||
// An rlib in its current incarnation is essentially a renamed .a file. The
|
// An rlib in its current incarnation is essentially a renamed .a file. The
|
||||||
@ -404,6 +420,7 @@ fn link_rlib<'a>(sess: &'a Session,
|
|||||||
tmpdir: &Path) -> ArchiveBuilder<'a> {
|
tmpdir: &Path) -> ArchiveBuilder<'a> {
|
||||||
info!("preparing rlib from {:?} to {:?}", objects, out_filename);
|
info!("preparing rlib from {:?} to {:?}", objects, out_filename);
|
||||||
let mut ab = ArchiveBuilder::new(archive_config(sess, out_filename, None));
|
let mut ab = ArchiveBuilder::new(archive_config(sess, out_filename, None));
|
||||||
|
|
||||||
for obj in objects {
|
for obj in objects {
|
||||||
ab.add_file(obj);
|
ab.add_file(obj);
|
||||||
}
|
}
|
||||||
@ -465,15 +482,7 @@ fn link_rlib<'a>(sess: &'a Session,
|
|||||||
// here so concurrent builds in the same directory don't try to use
|
// here so concurrent builds in the same directory don't try to use
|
||||||
// the same filename for metadata (stomping over one another)
|
// the same filename for metadata (stomping over one another)
|
||||||
let metadata = tmpdir.join(sess.cstore.metadata_filename());
|
let metadata = tmpdir.join(sess.cstore.metadata_filename());
|
||||||
match fs::File::create(&metadata).and_then(|mut f| {
|
emit_metadata(sess, trans, &metadata);
|
||||||
f.write_all(&trans.metadata)
|
|
||||||
}) {
|
|
||||||
Ok(..) => {}
|
|
||||||
Err(e) => {
|
|
||||||
sess.fatal(&format!("failed to write {}: {}",
|
|
||||||
metadata.display(), e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ab.add_file(&metadata);
|
ab.add_file(&metadata);
|
||||||
|
|
||||||
// For LTO purposes, the bytecode of this library is also inserted
|
// For LTO purposes, the bytecode of this library is also inserted
|
||||||
|
@ -14,9 +14,10 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use rustc::hir::def_id::CrateNum;
|
use rustc::hir::def_id::CrateNum;
|
||||||
|
use rustc::middle::cstore::LibSource;
|
||||||
|
|
||||||
pub struct RPathConfig<'a> {
|
pub struct RPathConfig<'a> {
|
||||||
pub used_crates: Vec<(CrateNum, Option<PathBuf>)>,
|
pub used_crates: Vec<(CrateNum, LibSource)>,
|
||||||
pub out_filename: PathBuf,
|
pub out_filename: PathBuf,
|
||||||
pub is_like_osx: bool,
|
pub is_like_osx: bool,
|
||||||
pub has_rpath: bool,
|
pub has_rpath: bool,
|
||||||
@ -35,7 +36,7 @@ pub fn get_rpath_flags(config: &mut RPathConfig) -> Vec<String> {
|
|||||||
debug!("preparing the RPATH!");
|
debug!("preparing the RPATH!");
|
||||||
|
|
||||||
let libs = config.used_crates.clone();
|
let libs = config.used_crates.clone();
|
||||||
let libs = libs.into_iter().filter_map(|(_, l)| l).collect::<Vec<_>>();
|
let libs = libs.into_iter().filter_map(|(_, l)| l.option()).collect::<Vec<_>>();
|
||||||
let rpaths = get_rpaths(config, &libs[..]);
|
let rpaths = get_rpaths(config, &libs[..]);
|
||||||
flags.extend_from_slice(&rpaths_to_flags(&rpaths[..]));
|
flags.extend_from_slice(&rpaths_to_flags(&rpaths[..]));
|
||||||
|
|
||||||
|
@ -1260,7 +1260,8 @@ fn write_metadata(cx: &SharedCrateContext,
|
|||||||
config::CrateTypeStaticlib |
|
config::CrateTypeStaticlib |
|
||||||
config::CrateTypeCdylib => MetadataKind::None,
|
config::CrateTypeCdylib => MetadataKind::None,
|
||||||
|
|
||||||
config::CrateTypeRlib => MetadataKind::Uncompressed,
|
config::CrateTypeRlib |
|
||||||
|
config::CrateTypeMetadata => MetadataKind::Uncompressed,
|
||||||
|
|
||||||
config::CrateTypeDylib |
|
config::CrateTypeDylib |
|
||||||
config::CrateTypeProcMacro => MetadataKind::Compressed,
|
config::CrateTypeProcMacro => MetadataKind::Compressed,
|
||||||
@ -1600,7 +1601,8 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||||||
assert_module_sources::assert_module_sources(tcx, &modules);
|
assert_module_sources::assert_module_sources(tcx, &modules);
|
||||||
|
|
||||||
// Skip crate items and just output metadata in -Z no-trans mode.
|
// Skip crate items and just output metadata in -Z no-trans mode.
|
||||||
if tcx.sess.opts.debugging_opts.no_trans {
|
if tcx.sess.opts.debugging_opts.no_trans ||
|
||||||
|
tcx.sess.crate_types.borrow().iter().all(|ct| ct == &config::CrateTypeMetadata) {
|
||||||
let linker_info = LinkerInfo::new(&shared_ccx, &[]);
|
let linker_info = LinkerInfo::new(&shared_ccx, &[]);
|
||||||
return CrateTranslation {
|
return CrateTranslation {
|
||||||
modules: modules,
|
modules: modules,
|
||||||
|
17
src/test/compile-fail/auxiliary/rmeta_meta.rs
Normal file
17
src/test/compile-fail/auxiliary/rmeta_meta.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
#![crate_type="metadata"]
|
||||||
|
|
||||||
|
pub struct Foo {
|
||||||
|
pub field: i32,
|
||||||
|
}
|
15
src/test/compile-fail/auxiliary/rmeta_rlib.rs
Normal file
15
src/test/compile-fail/auxiliary/rmeta_rlib.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![crate_type="rlib"]
|
||||||
|
|
||||||
|
pub struct Foo {
|
||||||
|
pub field: i32,
|
||||||
|
}
|
25
src/test/compile-fail/rmeta-lib-pass.rs
Normal file
25
src/test/compile-fail/rmeta-lib-pass.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// aux-build:rmeta_rlib.rs
|
||||||
|
// no-prefer-dynamic
|
||||||
|
// must-compile-successfully
|
||||||
|
|
||||||
|
// Check that building a metadata crate works with a dependent, rlib crate.
|
||||||
|
// This is a cfail test since there is no executable to run.
|
||||||
|
|
||||||
|
#![crate_type="metadata"]
|
||||||
|
|
||||||
|
extern crate rmeta_rlib;
|
||||||
|
use rmeta_rlib::Foo;
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let _ = Foo { field: 42 };
|
||||||
|
}
|
26
src/test/compile-fail/rmeta-pass.rs
Normal file
26
src/test/compile-fail/rmeta-pass.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// aux-build:rmeta_meta.rs
|
||||||
|
// no-prefer-dynamic
|
||||||
|
// must-compile-successfully
|
||||||
|
|
||||||
|
// Check that building a metadata crate works with a dependent, metadata-only
|
||||||
|
// crate.
|
||||||
|
// This is a cfail test since there is no executable to run.
|
||||||
|
|
||||||
|
#![crate_type="metadata"]
|
||||||
|
|
||||||
|
extern crate rmeta_meta;
|
||||||
|
use rmeta_meta::Foo;
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let _ = Foo { field: 42 };
|
||||||
|
}
|
19
src/test/compile-fail/rmeta.rs
Normal file
19
src/test/compile-fail/rmeta.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
// Check that building a metadata crate finds an error.
|
||||||
|
|
||||||
|
#![crate_type="metadata"]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = Foo; //~ ERROR unresolved name `Foo`
|
||||||
|
}
|
23
src/test/compile-fail/rmeta_lib.rs
Normal file
23
src/test/compile-fail/rmeta_lib.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// aux-build:rmeta_meta.rs
|
||||||
|
// no-prefer-dynamic
|
||||||
|
// error-pattern: crate `rmeta_meta` required to be available in rlib, but it was not available
|
||||||
|
|
||||||
|
// Check that building a non-metadata crate fails if a dependent crate is
|
||||||
|
// metadata-only.
|
||||||
|
|
||||||
|
extern crate rmeta_meta;
|
||||||
|
use rmeta_meta::Foo;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = Foo { field: 42 };
|
||||||
|
}
|
24
src/test/compile-fail/rmeta_meta_main.rs
Normal file
24
src/test/compile-fail/rmeta_meta_main.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// aux-build:rmeta_meta.rs
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
// Check that building a metadata crate finds an error with a dependent,
|
||||||
|
// metadata-only crate.
|
||||||
|
|
||||||
|
#![crate_type="metadata"]
|
||||||
|
|
||||||
|
extern crate rmeta_meta;
|
||||||
|
use rmeta_meta::Foo;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = Foo { field2: 42 }; //~ ERROR struct `rmeta_meta::Foo` has no field named `field2`
|
||||||
|
}
|
18
src/test/run-pass/auxiliary/rmeta_rlib.rs
Normal file
18
src/test/run-pass/auxiliary/rmeta_rlib.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
#![crate_type="rlib"]
|
||||||
|
#![crate_name="rmeta_aux"]
|
||||||
|
|
||||||
|
pub struct Foo {
|
||||||
|
pub field: i32,
|
||||||
|
}
|
18
src/test/run-pass/auxiliary/rmeta_rmeta.rs
Normal file
18
src/test/run-pass/auxiliary/rmeta_rmeta.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
#![crate_type="metadata"]
|
||||||
|
#![crate_name="rmeta_aux"]
|
||||||
|
|
||||||
|
pub struct Foo {
|
||||||
|
pub field2: i32,
|
||||||
|
}
|
22
src/test/run-pass/rmeta.rs
Normal file
22
src/test/run-pass/rmeta.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// Test that using rlibs and rmeta dep crates work together. Specifically, that
|
||||||
|
// there can be both an rmeta and an rlib file and rustc will prefer the rlib.
|
||||||
|
|
||||||
|
// aux-build:rmeta_rmeta.rs
|
||||||
|
// aux-build:rmeta_rlib.rs
|
||||||
|
|
||||||
|
extern crate rmeta_aux;
|
||||||
|
use rmeta_aux::Foo;
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let _ = Foo { field: 42 };
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user