@@ -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+
825855fn 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
0 commit comments