mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-03 13:37:37 +00:00
rustc: Allow the crate linked to as 'std' to be customized
This adds the alt_std_name field to the Session's Options type. I'm using this in an external tool to control which libraries a crate links to.
This commit is contained in:
parent
c88bf10c37
commit
ec0f1cb709
@ -97,6 +97,7 @@ pub struct Options {
|
|||||||
pub color: ColorConfig,
|
pub color: ColorConfig,
|
||||||
pub externs: HashMap<String, Vec<String>>,
|
pub externs: HashMap<String, Vec<String>>,
|
||||||
pub crate_name: Option<String>,
|
pub crate_name: Option<String>,
|
||||||
|
pub alt_std_name: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Some reasonable defaults
|
/// Some reasonable defaults
|
||||||
@ -124,6 +125,7 @@ pub fn basic_options() -> Options {
|
|||||||
color: Auto,
|
color: Auto,
|
||||||
externs: HashMap::new(),
|
externs: HashMap::new(),
|
||||||
crate_name: None,
|
crate_name: None,
|
||||||
|
alt_std_name: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,6 +789,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
|||||||
color: color,
|
color: color,
|
||||||
externs: externs,
|
externs: externs,
|
||||||
crate_name: crate_name,
|
crate_name: crate_name,
|
||||||
|
alt_std_name: None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,9 +60,16 @@ struct StandardLibraryInjector<'a> {
|
|||||||
|
|
||||||
impl<'a> fold::Folder for StandardLibraryInjector<'a> {
|
impl<'a> fold::Folder for StandardLibraryInjector<'a> {
|
||||||
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
|
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
|
||||||
|
|
||||||
|
// The name to use in `extern crate std = "name";`
|
||||||
|
let actual_crate_name = match self.sess.opts.alt_std_name {
|
||||||
|
Some(ref s) => token::intern_and_get_ident(s.as_slice()),
|
||||||
|
None => token::intern_and_get_ident("std"),
|
||||||
|
};
|
||||||
|
|
||||||
let mut vis = vec!(ast::ViewItem {
|
let mut vis = vec!(ast::ViewItem {
|
||||||
node: ast::ViewItemExternCrate(token::str_to_ident("std"),
|
node: ast::ViewItemExternCrate(token::str_to_ident("std"),
|
||||||
None,
|
Some((actual_crate_name, ast::CookedStr)),
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
attrs: vec!(
|
attrs: vec!(
|
||||||
attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_list_item(
|
attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_list_item(
|
||||||
|
Loading…
Reference in New Issue
Block a user