2014-02-10 15:36:31 +01:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-04 01:48:01 +01:00
|
|
|
// 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.
|
|
|
|
|
2011-07-08 03:39:44 +02:00
|
|
|
// The crate store - a central repo for information collected about external
|
|
|
|
// crates and libraries
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
use schema::{self, Tracked};
|
2015-11-24 23:00:26 +01:00
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
use rustc::dep_graph::{DepGraph, DepNode, GlobalMetaDataKind};
|
2016-11-24 01:09:51 +01:00
|
|
|
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefIndex, DefId};
|
2016-12-16 18:51:36 +01:00
|
|
|
use rustc::hir::map::definitions::DefPathTable;
|
2016-03-29 07:50:44 +02:00
|
|
|
use rustc::hir::svh::Svh;
|
2017-04-26 23:22:45 +02:00
|
|
|
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
|
2016-09-28 04:26:08 +02:00
|
|
|
use rustc_back::PanicStrategy;
|
2016-06-28 22:41:09 +02:00
|
|
|
use rustc_data_structures::indexed_vec::IndexVec;
|
2016-11-24 01:09:51 +01:00
|
|
|
use rustc::util::nodemap::{FxHashMap, FxHashSet, NodeMap, DefIdMap};
|
2012-12-23 23:41:37 +01:00
|
|
|
|
2016-09-16 16:25:54 +02:00
|
|
|
use std::cell::{RefCell, Cell};
|
2014-03-27 18:28:38 +01:00
|
|
|
use std::rc::Rc;
|
2017-04-26 23:22:45 +02:00
|
|
|
use owning_ref::ErasedBoxRef;
|
2016-10-19 21:35:32 +02:00
|
|
|
use syntax::{ast, attr};
|
2016-11-05 21:30:40 +01:00
|
|
|
use syntax::ext::base::SyntaxExtension;
|
2016-11-16 11:52:37 +01:00
|
|
|
use syntax::symbol::Symbol;
|
2016-06-22 00:08:13 +02:00
|
|
|
use syntax_pos;
|
2015-11-24 23:00:26 +01:00
|
|
|
|
2016-11-24 01:09:51 +01:00
|
|
|
pub use rustc::middle::cstore::{NativeLibrary, NativeLibraryKind, LinkagePreference};
|
2016-12-13 18:50:30 +01:00
|
|
|
pub use rustc::middle::cstore::NativeLibraryKind::*;
|
2016-11-10 03:57:30 +01:00
|
|
|
pub use rustc::middle::cstore::{CrateSource, LinkMeta, LibSource};
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2016-09-29 01:30:53 +02:00
|
|
|
pub use cstore_impl::provide;
|
|
|
|
|
2011-07-08 21:08:43 +02:00
|
|
|
// A map from external crate numbers (as decoded from some crate file) to
|
|
|
|
// local crate numbers (as generated during this session). Each external
|
|
|
|
// crate may refer to types in other external crates, and each has their
|
|
|
|
// own crate numbers.
|
2016-08-31 13:00:29 +02:00
|
|
|
pub type CrateNumMap = IndexVec<CrateNum, CrateNum>;
|
2011-07-08 21:08:43 +02:00
|
|
|
|
2017-04-26 23:22:45 +02:00
|
|
|
pub struct MetadataBlob(pub ErasedBoxRef<[u8]>);
|
2013-12-18 23:10:28 +01:00
|
|
|
|
2016-06-22 00:08:13 +02:00
|
|
|
/// Holds information about a syntax_pos::FileMap imported from another crate.
|
2016-09-16 16:25:54 +02:00
|
|
|
/// See `imported_filemaps()` for more information.
|
2015-02-11 18:29:49 +01:00
|
|
|
pub struct ImportedFileMap {
|
|
|
|
/// This FileMap's byte-offset within the codemap of its original crate
|
2016-06-22 00:08:13 +02:00
|
|
|
pub original_start_pos: syntax_pos::BytePos,
|
2015-02-11 18:29:49 +01:00
|
|
|
/// The end of this FileMap within the codemap of its original crate
|
2016-06-22 00:08:13 +02:00
|
|
|
pub original_end_pos: syntax_pos::BytePos,
|
2015-02-11 18:29:49 +01:00
|
|
|
/// The imported FileMap's representation within the local codemap
|
2016-10-23 05:02:37 +02:00
|
|
|
pub translated_filemap: Rc<syntax_pos::FileMap>,
|
2015-02-11 18:29:49 +01:00
|
|
|
}
|
|
|
|
|
2016-06-28 22:41:09 +02:00
|
|
|
pub struct CrateMetadata {
|
2016-11-16 11:52:37 +01:00
|
|
|
pub name: Symbol,
|
2016-03-16 10:50:38 +01:00
|
|
|
|
|
|
|
/// Information about the extern crate that caused this crate to
|
|
|
|
/// be loaded. If this is `None`, then the crate was injected
|
|
|
|
/// (e.g., by the allocator)
|
|
|
|
pub extern_crate: Cell<Option<ExternCrate>>,
|
|
|
|
|
2016-09-16 16:25:54 +02:00
|
|
|
pub blob: MetadataBlob,
|
2016-06-28 22:41:09 +02:00
|
|
|
pub cnum_map: RefCell<CrateNumMap>,
|
2016-08-31 13:00:29 +02:00
|
|
|
pub cnum: CrateNum,
|
2015-05-22 15:15:21 +02:00
|
|
|
pub codemap_import_info: RefCell<Vec<ImportedFileMap>>,
|
2017-04-20 14:08:41 +02:00
|
|
|
pub attribute_cache: RefCell<[Vec<Option<Rc<[ast::Attribute]>>>; 2]>,
|
2015-09-17 15:04:18 +02:00
|
|
|
|
2016-09-16 16:25:54 +02:00
|
|
|
pub root: schema::CrateRoot,
|
2015-06-25 19:07:01 +02:00
|
|
|
|
2016-05-06 20:52:57 +02:00
|
|
|
/// For each public item in this crate, we encode a key. When the
|
|
|
|
/// crate is loaded, we read all the keys and put them in this
|
|
|
|
/// hashmap, which gives the reverse mapping. This allows us to
|
|
|
|
/// quickly retrace a `DefPath`, which is needed for incremental
|
|
|
|
/// compilation support.
|
2016-12-16 18:51:36 +01:00
|
|
|
pub def_path_table: DefPathTable,
|
2016-05-06 20:52:57 +02:00
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub exported_symbols: Tracked<FxHashSet<DefIndex>>,
|
2017-01-09 15:46:24 +01:00
|
|
|
|
2017-05-08 23:36:37 +02:00
|
|
|
pub trait_impls: Tracked<FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>>,
|
|
|
|
|
2016-10-27 11:18:45 +02:00
|
|
|
pub dep_kind: Cell<DepKind>,
|
2016-10-27 07:03:11 +02:00
|
|
|
pub source: CrateSource,
|
2016-11-05 21:30:40 +01:00
|
|
|
|
|
|
|
pub proc_macros: Option<Vec<(ast::Name, Rc<SyntaxExtension>)>>,
|
2016-11-24 01:09:51 +01:00
|
|
|
// Foreign items imported from a dylib (Windows only)
|
2017-04-27 16:12:57 +02:00
|
|
|
pub dllimport_foreign_items: Tracked<FxHashSet<DefIndex>>,
|
2013-02-19 08:40:42 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2013-02-04 23:02:01 +01:00
|
|
|
pub struct CStore {
|
2016-04-22 21:47:14 +02:00
|
|
|
pub dep_graph: DepGraph,
|
2016-11-08 04:02:55 +01:00
|
|
|
metas: RefCell<FxHashMap<CrateNum, Rc<CrateMetadata>>>,
|
2014-11-09 23:59:56 +01:00
|
|
|
/// Map from NodeId's of local extern crate statements to crate numbers
|
2016-08-31 13:00:29 +02:00
|
|
|
extern_mod_crate_map: RefCell<NodeMap<CrateNum>>,
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-11-01 00:40:13 +01:00
|
|
|
used_libraries: RefCell<Vec<NativeLibrary>>,
|
2014-05-23 01:57:53 +02:00
|
|
|
used_link_args: RefCell<Vec<String>>,
|
2016-11-24 01:09:51 +01:00
|
|
|
statically_included_foreign_items: RefCell<FxHashSet<DefIndex>>,
|
|
|
|
pub dllimport_foreign_items: RefCell<FxHashSet<DefIndex>>,
|
2016-03-19 10:01:29 +01:00
|
|
|
pub visible_parent_map: RefCell<DefIdMap<DefId>>,
|
2017-04-26 23:22:45 +02:00
|
|
|
pub metadata_loader: Box<MetadataLoader>,
|
2013-02-04 23:02:01 +01:00
|
|
|
}
|
2011-07-10 07:56:12 +02:00
|
|
|
|
2013-12-25 21:08:04 +01:00
|
|
|
impl CStore {
|
2017-04-26 23:22:45 +02:00
|
|
|
pub fn new(dep_graph: &DepGraph, metadata_loader: Box<MetadataLoader>) -> CStore {
|
2013-12-25 21:08:04 +01:00
|
|
|
CStore {
|
2016-04-22 21:47:14 +02:00
|
|
|
dep_graph: dep_graph.clone(),
|
2016-11-08 04:02:55 +01:00
|
|
|
metas: RefCell::new(FxHashMap()),
|
|
|
|
extern_mod_crate_map: RefCell::new(FxHashMap()),
|
2014-03-04 19:02:49 +01:00
|
|
|
used_libraries: RefCell::new(Vec::new()),
|
|
|
|
used_link_args: RefCell::new(Vec::new()),
|
2016-11-24 01:09:51 +01:00
|
|
|
statically_included_foreign_items: RefCell::new(FxHashSet()),
|
|
|
|
dllimport_foreign_items: RefCell::new(FxHashSet()),
|
2016-11-08 04:02:55 +01:00
|
|
|
visible_parent_map: RefCell::new(FxHashMap()),
|
2017-04-26 23:22:45 +02:00
|
|
|
metadata_loader: metadata_loader,
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2016-08-31 13:00:29 +02:00
|
|
|
pub fn next_crate_num(&self) -> CrateNum {
|
|
|
|
CrateNum::new(self.metas.borrow().len() + 1)
|
2014-04-07 21:14:33 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 13:00:29 +02:00
|
|
|
pub fn get_crate_data(&self, cnum: CrateNum) -> Rc<CrateMetadata> {
|
2015-03-22 02:15:47 +01:00
|
|
|
self.metas.borrow().get(&cnum).unwrap().clone()
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2016-08-31 13:00:29 +02:00
|
|
|
pub fn get_crate_hash(&self, cnum: CrateNum) -> Svh {
|
2016-09-08 18:05:50 +02:00
|
|
|
self.get_crate_data(cnum).hash()
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2012-04-06 12:45:49 +02:00
|
|
|
|
2016-08-31 13:00:29 +02:00
|
|
|
pub fn set_crate_data(&self, cnum: CrateNum, data: Rc<CrateMetadata>) {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.metas.borrow_mut().insert(cnum, data);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2016-10-23 05:02:37 +02:00
|
|
|
pub fn iter_crate_data<I>(&self, mut i: I)
|
|
|
|
where I: FnMut(CrateNum, &Rc<CrateMetadata>)
|
2014-12-09 02:26:43 +01:00
|
|
|
{
|
2015-06-11 14:56:07 +02:00
|
|
|
for (&k, v) in self.metas.borrow().iter() {
|
2015-06-25 19:07:01 +02:00
|
|
|
i(k, v);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2013-02-04 23:02:01 +01:00
|
|
|
}
|
2011-07-08 03:00:16 +02:00
|
|
|
|
2013-12-25 19:10:33 +01:00
|
|
|
pub fn reset(&self) {
|
2014-03-21 03:55:52 +01:00
|
|
|
self.metas.borrow_mut().clear();
|
|
|
|
self.extern_mod_crate_map.borrow_mut().clear();
|
|
|
|
self.used_libraries.borrow_mut().clear();
|
|
|
|
self.used_link_args.borrow_mut().clear();
|
2015-07-30 23:20:36 +02:00
|
|
|
self.statically_included_foreign_items.borrow_mut().clear();
|
2013-12-25 19:10:33 +01:00
|
|
|
}
|
|
|
|
|
2016-10-23 05:02:37 +02:00
|
|
|
pub fn crate_dependencies_in_rpo(&self, krate: CrateNum) -> Vec<CrateNum> {
|
2016-06-28 22:41:09 +02:00
|
|
|
let mut ordering = Vec::new();
|
|
|
|
self.push_dependencies_in_postorder(&mut ordering, krate);
|
|
|
|
ordering.reverse();
|
|
|
|
ordering
|
|
|
|
}
|
|
|
|
|
2016-10-23 05:02:37 +02:00
|
|
|
pub fn push_dependencies_in_postorder(&self, ordering: &mut Vec<CrateNum>, krate: CrateNum) {
|
|
|
|
if ordering.contains(&krate) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-28 22:41:09 +02:00
|
|
|
|
|
|
|
let data = self.get_crate_data(krate);
|
|
|
|
for &dep in data.cnum_map.borrow().iter() {
|
|
|
|
if dep != krate {
|
|
|
|
self.push_dependencies_in_postorder(ordering, dep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ordering.push(krate);
|
|
|
|
}
|
|
|
|
|
2014-03-14 02:47:43 +01:00
|
|
|
// This method is used when generating the command line to pass through to
|
|
|
|
// system linker. The linker expects undefined symbols on the left of the
|
|
|
|
// command line to be defined in libraries on the right, not the other way
|
|
|
|
// around. For more info, see some comments in the add_used_library function
|
|
|
|
// below.
|
|
|
|
//
|
|
|
|
// In order to get this left-to-right dependency ordering, we perform a
|
|
|
|
// topological sort of all crates putting the leaves at the right-most
|
|
|
|
// positions.
|
2016-10-23 05:02:37 +02:00
|
|
|
pub fn do_get_used_crates(&self,
|
|
|
|
prefer: LinkagePreference)
|
2016-11-10 03:57:30 +01:00
|
|
|
-> Vec<(CrateNum, LibSource)> {
|
2014-03-14 02:47:43 +01:00
|
|
|
let mut ordering = Vec::new();
|
2015-06-11 14:56:07 +02:00
|
|
|
for (&num, _) in self.metas.borrow().iter() {
|
2016-06-28 22:41:09 +02:00
|
|
|
self.push_dependencies_in_postorder(&mut ordering, num);
|
2014-03-14 02:47:43 +01:00
|
|
|
}
|
2015-06-25 19:07:01 +02:00
|
|
|
info!("topological ordering: {:?}", ordering);
|
2014-11-27 22:47:48 +01:00
|
|
|
ordering.reverse();
|
2016-10-27 07:03:11 +02:00
|
|
|
let mut libs = self.metas
|
2016-10-23 05:02:37 +02:00
|
|
|
.borrow()
|
2013-12-21 04:50:13 +01:00
|
|
|
.iter()
|
2016-10-28 07:56:06 +02:00
|
|
|
.filter_map(|(&cnum, data)| {
|
2016-11-27 03:57:15 +01:00
|
|
|
if data.dep_kind.get().macros_only() { return None; }
|
2016-10-28 07:56:06 +02:00
|
|
|
let path = match prefer {
|
|
|
|
LinkagePreference::RequireDynamic => data.source.dylib.clone().map(|p| p.0),
|
|
|
|
LinkagePreference::RequireStatic => data.source.rlib.clone().map(|p| p.0),
|
|
|
|
};
|
2016-11-10 03:57:30 +01:00
|
|
|
let path = match path {
|
|
|
|
Some(p) => LibSource::Some(p),
|
|
|
|
None => {
|
2016-11-10 22:00:33 +01:00
|
|
|
if data.source.rmeta.is_some() {
|
2016-11-10 03:57:30 +01:00
|
|
|
LibSource::MetadataOnly
|
|
|
|
} else {
|
|
|
|
LibSource::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-10-28 07:56:06 +02:00
|
|
|
Some((cnum, path))
|
2016-10-23 05:02:37 +02:00
|
|
|
})
|
2015-01-06 17:46:07 +01:00
|
|
|
.collect::<Vec<_>>();
|
2014-03-14 02:47:43 +01:00
|
|
|
libs.sort_by(|&(a, _), &(b, _)| {
|
2015-07-08 17:33:13 +02:00
|
|
|
let a = ordering.iter().position(|x| *x == a);
|
|
|
|
let b = ordering.iter().position(|x| *x == b);
|
|
|
|
a.cmp(&b)
|
2014-03-14 02:47:43 +01:00
|
|
|
});
|
|
|
|
libs
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-11-01 00:40:13 +01:00
|
|
|
pub fn add_used_library(&self, lib: NativeLibrary) {
|
2016-11-16 11:52:37 +01:00
|
|
|
assert!(!lib.name.as_str().is_empty());
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-11-01 00:40:13 +01:00
|
|
|
self.used_libraries.borrow_mut().push(lib);
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:25:56 +02:00
|
|
|
|
rustc: Implement #[link(cfg(..))] and crt-static
This commit is an implementation of [RFC 1721] which adds a new target feature
to the compiler, `crt-static`, which can be used to select how the C runtime for
a target is linked. Most targets dynamically linke the C runtime by default with
the notable exception of some of the musl targets.
[RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
This commit first adds the new target-feature, `crt-static`. If enabled, then
the `cfg(target_feature = "crt-static")` will be available. Targets like musl
will have this enabled by default. This feature can be controlled through the
standard target-feature interface, `-C target-feature=+crt-static` or
`-C target-feature=-crt-static`.
Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
`crt-static` semantics we want with libc. The exact behavior of this attribute
is a little squishy, but it's intended to be a forever-unstable
implementation detail of the liblibc crate.
Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
directive is only active in a compilation unit if that `cfg` value is satisfied.
For example when compiling an rlib, these directives are just encoded and
ignored for dylibs, and all staticlibs are continued to be put into the rlib as
usual. When placing that rlib into a staticlib, executable, or dylib, however,
the `cfg` is evaluated *as if it were defined in the final artifact* and the
library is decided to be linked or not.
Essentially, what'll happen is:
* On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
linked to.
* On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
linked to.
* On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
are removed and `-lc` is passed instead.
* On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
are used and `-lc` is not passed.
This commit does **not** include an update to the liblibc module to implement
these changes. I plan to do that just after the 1.14.0 beta release is cut to
ensure we get ample time to test this feature.
cc #37406
2016-11-01 00:40:13 +01:00
|
|
|
pub fn get_used_libraries(&self) -> &RefCell<Vec<NativeLibrary>> {
|
2013-12-21 04:54:01 +01:00
|
|
|
&self.used_libraries
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2013-12-21 05:00:58 +01:00
|
|
|
pub fn add_used_link_args(&self, args: &str) {
|
2014-07-07 18:54:38 +02:00
|
|
|
for s in args.split(' ').filter(|s| !s.is_empty()) {
|
2014-05-25 12:17:19 +02:00
|
|
|
self.used_link_args.borrow_mut().push(s.to_string());
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2016-10-23 05:02:37 +02:00
|
|
|
pub fn get_used_link_args<'a>(&'a self) -> &'a RefCell<Vec<String>> {
|
2013-12-21 04:56:29 +01:00
|
|
|
&self.used_link_args
|
2013-12-25 21:08:04 +01:00
|
|
|
}
|
2011-07-08 03:33:59 +02:00
|
|
|
|
2016-10-23 05:02:37 +02:00
|
|
|
pub fn add_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId, cnum: CrateNum) {
|
2014-03-21 03:49:20 +01:00
|
|
|
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
|
2013-03-24 07:51:18 +01:00
|
|
|
}
|
2011-07-08 03:38:42 +02:00
|
|
|
|
2016-11-24 01:09:51 +01:00
|
|
|
pub fn add_statically_included_foreign_item(&self, id: DefIndex) {
|
2015-07-30 23:20:36 +02:00
|
|
|
self.statically_included_foreign_items.borrow_mut().insert(id);
|
|
|
|
}
|
|
|
|
|
2016-11-24 01:09:51 +01:00
|
|
|
pub fn do_is_statically_included_foreign_item(&self, def_id: DefId) -> bool {
|
|
|
|
assert!(def_id.krate == LOCAL_CRATE);
|
|
|
|
self.statically_included_foreign_items.borrow().contains(&def_id.index)
|
2015-07-30 23:20:36 +02:00
|
|
|
}
|
2015-11-25 16:02:59 +01:00
|
|
|
|
2016-10-23 05:02:37 +02:00
|
|
|
pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> {
|
2015-11-25 16:02:59 +01:00
|
|
|
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
|
|
|
|
}
|
2013-07-02 21:47:32 +02:00
|
|
|
}
|
|
|
|
|
2016-06-28 22:41:09 +02:00
|
|
|
impl CrateMetadata {
|
2016-11-16 11:52:37 +01:00
|
|
|
pub fn name(&self) -> Symbol {
|
|
|
|
self.root.name
|
2016-10-23 05:02:37 +02:00
|
|
|
}
|
|
|
|
pub fn hash(&self) -> Svh {
|
|
|
|
self.root.hash
|
|
|
|
}
|
2016-11-16 11:52:37 +01:00
|
|
|
pub fn disambiguator(&self) -> Symbol {
|
|
|
|
self.root.disambiguator
|
2016-10-23 05:02:37 +02:00
|
|
|
}
|
2015-06-25 19:07:01 +02:00
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn is_allocator(&self, dep_graph: &DepGraph) -> bool {
|
|
|
|
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
|
2015-06-25 19:07:01 +02:00
|
|
|
attr::contains_name(&attrs, "allocator")
|
|
|
|
}
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn needs_allocator(&self, dep_graph: &DepGraph) -> bool {
|
|
|
|
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
|
2015-06-25 19:07:01 +02:00
|
|
|
attr::contains_name(&attrs, "needs_allocator")
|
|
|
|
}
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-09 01:18:40 +02:00
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn is_panic_runtime(&self, dep_graph: &DepGraph) -> bool {
|
|
|
|
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-09 01:18:40 +02:00
|
|
|
attr::contains_name(&attrs, "panic_runtime")
|
|
|
|
}
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn needs_panic_runtime(&self, dep_graph: &DepGraph) -> bool {
|
|
|
|
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
|
rustc: Implement custom panic runtimes
This commit is an implementation of [RFC 1513] which allows applications to
alter the behavior of panics at compile time. A new compiler flag, `-C panic`,
is added and accepts the values `unwind` or `panic`, with the default being
`unwind`. This model affects how code is generated for the local crate, skipping
generation of landing pads with `-C panic=abort`.
[RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md
Panic implementations are then provided by crates tagged with
`#![panic_runtime]` and lazily required by crates with
`#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic
runtime must match the final product, and if the panic strategy is not `abort`
then the entire DAG must have the same panic strategy.
With the `-C panic=abort` strategy, users can expect a stable method to disable
generation of landing pads, improving optimization in niche scenarios,
decreasing compile time, and decreasing output binary size. With the `-C
panic=unwind` strategy users can expect the existing ability to isolate failure
in Rust code from the outside world.
Organizationally, this commit dismantles the `sys_common::unwind` module in
favor of some bits moving part of it to `libpanic_unwind` and the rest into the
`panicking` module in libstd. The custom panic runtime support is pretty similar
to the custom allocator support with the only major difference being how the
panic runtime is injected (takes the `-C panic` flag into account).
2016-04-09 01:18:40 +02:00
|
|
|
attr::contains_name(&attrs, "needs_panic_runtime")
|
|
|
|
}
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn is_compiler_builtins(&self, dep_graph: &DepGraph) -> bool {
|
|
|
|
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
|
2016-07-25 04:42:11 +02:00
|
|
|
attr::contains_name(&attrs, "compiler_builtins")
|
|
|
|
}
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn is_sanitizer_runtime(&self, dep_graph: &DepGraph) -> bool {
|
|
|
|
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
|
2016-12-30 05:28:11 +01:00
|
|
|
attr::contains_name(&attrs, "sanitizer_runtime")
|
|
|
|
}
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn is_no_builtins(&self, dep_graph: &DepGraph) -> bool {
|
|
|
|
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
|
2016-09-15 10:04:00 +02:00
|
|
|
attr::contains_name(&attrs, "no_builtins")
|
|
|
|
}
|
|
|
|
|
2017-04-27 16:12:57 +02:00
|
|
|
pub fn panic_strategy(&self, dep_graph: &DepGraph) -> PanicStrategy {
|
|
|
|
let def_id = DefId {
|
|
|
|
krate: self.cnum,
|
|
|
|
index: CRATE_DEF_INDEX,
|
|
|
|
};
|
|
|
|
let dep_node = DepNode::GlobalMetaData(def_id, GlobalMetaDataKind::Krate);
|
|
|
|
|
|
|
|
self.root
|
|
|
|
.panic_strategy
|
|
|
|
.get(dep_graph, dep_node)
|
|
|
|
.clone()
|
2013-12-18 23:10:28 +01:00
|
|
|
}
|
|
|
|
}
|