Skip to content

Commit 7d87b53

Browse files
committed
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.
1 parent df102ef commit 7d87b53

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/librustc/driver/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub struct Options {
9797
pub color: ColorConfig,
9898
pub externs: HashMap<String, Vec<String>>,
9999
pub crate_name: Option<String>,
100+
pub alt_std_name: Option<String>
100101
}
101102

102103
/// Some reasonable defaults
@@ -124,6 +125,7 @@ pub fn basic_options() -> Options {
124125
color: Auto,
125126
externs: HashMap::new(),
126127
crate_name: None,
128+
alt_std_name: None,
127129
}
128130
}
129131

@@ -787,6 +789,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
787789
color: color,
788790
externs: externs,
789791
crate_name: crate_name,
792+
alt_std_name: None
790793
}
791794
}
792795

src/librustc/front/std_inject.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ struct StandardLibraryInjector<'a> {
6060

6161
impl<'a> fold::Folder for StandardLibraryInjector<'a> {
6262
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
63+
64+
// The name to use in `extern crate std = "name";`
65+
let actual_crate_name = match self.sess.opts.alt_std_name {
66+
Some(ref s) => token::intern_and_get_ident(s.as_slice()),
67+
None => token::intern_and_get_ident("std"),
68+
};
69+
6370
let mut vis = vec!(ast::ViewItem {
6471
node: ast::ViewItemExternCrate(token::str_to_ident("std"),
65-
None,
72+
Some((actual_crate_name, ast::CookedStr)),
6673
ast::DUMMY_NODE_ID),
6774
attrs: vec!(
6875
attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_list_item(

0 commit comments

Comments
 (0)