Skip to content

Commit 70a79a9

Browse files
committed
Better dylib skipping based on Alex Crichton code
1 parent a49b765 commit 70a79a9

File tree

13 files changed

+125
-121
lines changed

13 files changed

+125
-121
lines changed

src/librustc/back/arm.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// except according to those terms.
1010

1111
use back::target_strs;
12-
use driver::config::cfg_os_to_meta_os;
13-
use metadata::loader::meta_section_name;
1412
use syntax::abi;
1513

1614
pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
@@ -22,9 +20,6 @@ pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs
2220
return target_strs::t {
2321
module_asm: "".to_string(),
2422

25-
meta_sect_name:
26-
meta_section_name(cfg_os_to_meta_os(target_os)).to_string(),
27-
2823
data_layout: match target_os {
2924
abi::OsMacos => {
3025
"e-p:32:32:32\

src/librustc/back/link.rs

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,10 @@ pub fn link_binary(sess: &Session,
806806
id: &CrateId) -> Vec<Path> {
807807
let mut out_filenames = Vec::new();
808808
for &crate_type in sess.crate_types.borrow().iter() {
809+
if invalid_output_for_target(sess, crate_type) {
810+
sess.bug(format!("invalid output type `{}` for target os `{}`",
811+
crate_type, sess.targ_cfg.os).as_slice());
812+
}
809813
let out_file = link_binary_output(sess, trans, crate_type, outputs, id);
810814
out_filenames.push(out_file);
811815
}
@@ -822,6 +826,32 @@ pub fn link_binary(sess: &Session,
822826
out_filenames
823827
}
824828

829+
830+
/// Returns default crate type for target
831+
///
832+
/// Default crate type is used when crate type isn't provided neither
833+
/// through cmd line arguments nor through crate attributes
834+
///
835+
/// It is CrateTypeExecutable for all platforms but iOS as there is no
836+
/// way to run iOS binaries anyway without jailbreaking and
837+
/// interaction with Rust code through static library is the only
838+
/// option for now
839+
pub fn default_output_for_target(sess: &Session) -> config::CrateType {
840+
match sess.targ_cfg.os {
841+
abi::OsiOS => config::CrateTypeStaticlib,
842+
_ => config::CrateTypeExecutable
843+
}
844+
}
845+
846+
/// Checks if target supports crate_type as output
847+
pub fn invalid_output_for_target(sess: &Session,
848+
crate_type: config::CrateType) -> bool {
849+
match (sess.targ_cfg.os, crate_type) {
850+
(abi::OsiOS, config::CrateTypeDylib) => true,
851+
_ => false
852+
}
853+
}
854+
825855
fn is_writeable(p: &Path) -> bool {
826856
match p.stat() {
827857
Err(..) => true,
@@ -837,23 +867,18 @@ pub fn filename_for_input(sess: &Session, crate_type: config::CrateType,
837867
out_filename.with_filename(format!("lib{}.rlib", libname))
838868
}
839869
config::CrateTypeDylib => {
840-
// There is no support of DyLibs on iOS
841-
if sess.targ_cfg.os == abi::OsiOS {
842-
out_filename.with_filename(format!("lib{}.a", libname))
843-
} else {
844-
let (prefix, suffix) = match sess.targ_cfg.os {
845-
abi::OsWin32 => (loader::WIN32_DLL_PREFIX, loader::WIN32_DLL_SUFFIX),
846-
abi::OsMacos => (loader::MACOS_DLL_PREFIX, loader::MACOS_DLL_SUFFIX),
847-
abi::OsLinux => (loader::LINUX_DLL_PREFIX, loader::LINUX_DLL_SUFFIX),
848-
abi::OsAndroid => (loader::ANDROID_DLL_PREFIX, loader::ANDROID_DLL_SUFFIX),
849-
abi::OsFreebsd => (loader::FREEBSD_DLL_PREFIX, loader::FREEBSD_DLL_SUFFIX),
850-
abi::OsiOS => unreachable!(),
851-
};
852-
out_filename.with_filename(format!("{}{}{}",
853-
prefix,
854-
libname,
855-
suffix))
856-
}
870+
let (prefix, suffix) = match sess.targ_cfg.os {
871+
abi::OsWin32 => (loader::WIN32_DLL_PREFIX, loader::WIN32_DLL_SUFFIX),
872+
abi::OsMacos => (loader::MACOS_DLL_PREFIX, loader::MACOS_DLL_SUFFIX),
873+
abi::OsLinux => (loader::LINUX_DLL_PREFIX, loader::LINUX_DLL_SUFFIX),
874+
abi::OsAndroid => (loader::ANDROID_DLL_PREFIX, loader::ANDROID_DLL_SUFFIX),
875+
abi::OsFreebsd => (loader::FREEBSD_DLL_PREFIX, loader::FREEBSD_DLL_SUFFIX),
876+
abi::OsiOS => unreachable!(),
877+
};
878+
out_filename.with_filename(format!("{}{}{}",
879+
prefix,
880+
libname,
881+
suffix))
857882
}
858883
config::CrateTypeStaticlib => {
859884
out_filename.with_filename(format!("lib{}.a", libname))
@@ -904,14 +929,7 @@ fn link_binary_output(sess: &Session,
904929
link_natively(sess, trans, false, &obj_filename, &out_filename);
905930
}
906931
config::CrateTypeDylib => {
907-
if sess.targ_cfg.os == abi::OsiOS {
908-
sess.warn(format!("No dylib for iOS -> saving static library {} to {}",
909-
obj_filename.display(), out_filename.display()).as_slice());
910-
link_staticlib(sess, &obj_filename, &out_filename);
911-
}
912-
else {
913-
link_natively(sess, trans, true, &obj_filename, &out_filename);
914-
}
932+
link_natively(sess, trans, true, &obj_filename, &out_filename);
915933
}
916934
}
917935

src/librustc/back/mips.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99
// except according to those terms.
1010

1111
use back::target_strs;
12-
use driver::config::cfg_os_to_meta_os;
13-
use metadata::loader::meta_section_name;
1412
use syntax::abi;
1513

1614
pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
1715
return target_strs::t {
1816
module_asm: "".to_string(),
1917

20-
meta_sect_name:
21-
meta_section_name(cfg_os_to_meta_os(target_os)).to_string(),
22-
2318
data_layout: match target_os {
2419
abi::OsMacos => {
2520
"E-p:32:32:32\

src/librustc/back/target_strs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
pub struct t {
1414
pub module_asm: String,
15-
pub meta_sect_name: String,
1615
pub data_layout: String,
1716
pub target_triple: String,
1817
pub cc_args: Vec<String> ,

src/librustc/back/x86.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010

1111

1212
use back::target_strs;
13-
use driver::config::cfg_os_to_meta_os;
14-
use metadata::loader::meta_section_name;
1513
use syntax::abi;
1614

1715
pub fn get_target_strs(target_triple: String, target_os: abi::Os)
1816
-> target_strs::t {
1917
return target_strs::t {
2018
module_asm: "".to_string(),
2119

22-
meta_sect_name:
23-
meta_section_name(cfg_os_to_meta_os(target_os)).to_string(),
24-
2520
data_layout: match target_os {
2621
abi::OsMacos => {
2722
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16\

src/librustc/back/x86_64.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010

1111

1212
use back::target_strs;
13-
use driver::config::cfg_os_to_meta_os;
14-
use metadata::loader::meta_section_name;
1513
use syntax::abi;
1614

1715
pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t {
1816
return target_strs::t {
1917
module_asm: "".to_string(),
2018

21-
meta_sect_name:
22-
meta_section_name(cfg_os_to_meta_os(target_os)).to_string(),
23-
2419
data_layout: match target_os {
2520
abi::OsMacos => {
2621
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\

src/librustc/driver/config.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use back;
1919
use back::link;
2020
use back::target_strs;
2121
use back::{arm, x86, x86_64, mips};
22-
use metadata;
2322
use middle::lint;
2423

2524
use syntax::abi;
@@ -36,6 +35,7 @@ use getopts::{optopt, optmulti, optflag, optflagopt};
3635
use getopts;
3736
use lib::llvm::llvm;
3837
use std::cell::{RefCell};
38+
use std::fmt;
3939

4040

4141
pub struct Config {
@@ -354,19 +354,6 @@ pub fn default_lib_output() -> CrateType {
354354
CrateTypeRlib
355355
}
356356

357-
pub fn cfg_os_to_meta_os(os: abi::Os) -> metadata::loader::Os {
358-
use metadata::loader;
359-
360-
match os {
361-
abi::OsWin32 => loader::OsWin32,
362-
abi::OsLinux => loader::OsLinux,
363-
abi::OsAndroid => loader::OsAndroid,
364-
abi::OsMacos => loader::OsMacos,
365-
abi::OsFreebsd => loader::OsFreebsd,
366-
abi::OsiOS => loader::OsiOS,
367-
}
368-
}
369-
370357
pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
371358
let tos = match sess.targ_cfg.os {
372359
abi::OsWin32 => InternedString::new("win32"),
@@ -775,6 +762,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
775762
}
776763
}
777764

765+
impl fmt::Show for CrateType {
766+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
767+
match *self {
768+
CrateTypeExecutable => "bin".fmt(f),
769+
CrateTypeDylib => "dylib".fmt(f),
770+
CrateTypeRlib => "rlib".fmt(f),
771+
CrateTypeStaticlib => "staticlib".fmt(f)
772+
}
773+
}
774+
}
778775

779776
#[cfg(test)]
780777
mod test {

src/librustc/driver/driver.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,17 +779,26 @@ pub fn collect_crate_types(session: &Session,
779779
// command line, then reuse the empty `base` Vec to hold the types that
780780
// will be found in crate attributes.
781781
let mut base = session.opts.crate_types.clone();
782-
if base.len() > 0 {
783-
return base
784-
} else {
782+
if base.len() == 0 {
785783
base.extend(attr_types.move_iter());
786784
if base.len() == 0 {
787-
base.push(config::CrateTypeExecutable);
785+
base.push(link::default_output_for_target(session));
788786
}
789787
base.as_mut_slice().sort();
790788
base.dedup();
791-
return base;
792789
}
790+
791+
base.move_iter().filter(|crate_type| {
792+
let res = !link::invalid_output_for_target(session, *crate_type);
793+
794+
if !res {
795+
session.warn(format!("dropping unsupported crate type `{}` \
796+
for target os `{}`",
797+
*crate_type, session.targ_cfg.os).as_slice());
798+
}
799+
800+
res
801+
}).collect()
793802
}
794803

795804
pub struct OutputFilenames {

src/librustc/driver/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ pub fn early_error(msg: &str) -> ! {
349349

350350
pub fn list_metadata(sess: &Session, path: &Path,
351351
out: &mut io::Writer) -> io::IoResult<()> {
352-
metadata::loader::list_file_metadata(
353-
config::cfg_os_to_meta_os(sess.targ_cfg.os), path, out)
352+
metadata::loader::list_file_metadata(sess.targ_cfg.os, path, out)
354353
}
355354

356355
/// Run a procedure which will detect failures in the compiler and print nicer

src/librustc/metadata/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn resolve_crate<'a>(e: &mut Env,
346346
id_hash: id_hash.as_slice(),
347347
hash: hash.map(|a| &*a),
348348
filesearch: e.sess.target_filesearch(),
349-
os: config::cfg_os_to_meta_os(e.sess.targ_cfg.os),
349+
os: e.sess.targ_cfg.os,
350350
triple: e.sess.targ_cfg.target_strs.target_triple.as_slice(),
351351
root: root,
352352
rejected_via_hash: vec!(),
@@ -410,7 +410,7 @@ impl<'a> PluginMetadataReader<'a> {
410410
hash: None,
411411
filesearch: self.env.sess.host_filesearch(),
412412
triple: driver::host_triple(),
413-
os: config::cfg_os_to_meta_os(os),
413+
os: os,
414414
root: &None,
415415
rejected_via_hash: vec!(),
416416
rejected_via_triple: vec!(),
@@ -421,7 +421,7 @@ impl<'a> PluginMetadataReader<'a> {
421421
// try loading from target crates (only valid if there are
422422
// no syntax extensions)
423423
load_ctxt.triple = target_triple;
424-
load_ctxt.os = config::cfg_os_to_meta_os(self.env.sess.targ_cfg.os);
424+
load_ctxt.os = self.env.sess.targ_cfg.os;
425425
load_ctxt.filesearch = self.env.sess.target_filesearch();
426426
let lib = load_ctxt.load_library_crate();
427427
if decoder::get_plugin_registrar_fn(lib.metadata.as_slice()).is_some() {

0 commit comments

Comments
 (0)