12
12
13
13
use cstore:: { self , CStore , CrateSource , MetadataBlob } ;
14
14
use locator:: { self , CratePaths } ;
15
+ use native_libs:: relevant_lib;
15
16
use schema:: { CrateRoot , Tracked } ;
16
17
17
18
use rustc:: hir:: def_id:: { CrateNum , DefIndex } ;
@@ -26,7 +27,6 @@ use rustc::middle;
26
27
use rustc:: middle:: cstore:: { CrateStore , validate_crate_name, ExternCrate } ;
27
28
use rustc:: util:: common:: record_time;
28
29
use rustc:: util:: nodemap:: FxHashSet ;
29
- use rustc:: middle:: cstore:: NativeLibrary ;
30
30
use rustc:: hir:: map:: Definitions ;
31
31
32
32
use std:: cell:: { RefCell , Cell } ;
@@ -36,10 +36,8 @@ use std::rc::Rc;
36
36
use std:: { cmp, fs} ;
37
37
38
38
use syntax:: ast;
39
- use syntax:: abi:: Abi ;
40
39
use syntax:: attr;
41
40
use syntax:: ext:: base:: SyntaxExtension ;
42
- use syntax:: feature_gate:: { self , GateIssue } ;
43
41
use syntax:: symbol:: Symbol ;
44
42
use syntax:: visit;
45
43
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -81,56 +79,6 @@ struct ExternCrateInfo {
81
79
dep_kind : DepKind ,
82
80
}
83
81
84
- fn register_native_lib ( sess : & Session ,
85
- cstore : & CStore ,
86
- span : Option < Span > ,
87
- lib : NativeLibrary ) {
88
- if lib. name . as_str ( ) . is_empty ( ) {
89
- match span {
90
- Some ( span) => {
91
- struct_span_err ! ( sess, span, E0454 ,
92
- "#[link(name = \" \" )] given with empty name" )
93
- . span_label ( span, "empty name given" )
94
- . emit ( ) ;
95
- }
96
- None => {
97
- sess. err ( "empty library name given via `-l`" ) ;
98
- }
99
- }
100
- return
101
- }
102
- let is_osx = sess. target . target . options . is_like_osx ;
103
- if lib. kind == cstore:: NativeFramework && !is_osx {
104
- let msg = "native frameworks are only available on macOS targets" ;
105
- match span {
106
- Some ( span) => span_err ! ( sess, span, E0455 , "{}" , msg) ,
107
- None => sess. err ( msg) ,
108
- }
109
- }
110
- if lib. cfg . is_some ( ) && !sess. features . borrow ( ) . link_cfg {
111
- feature_gate:: emit_feature_err ( & sess. parse_sess ,
112
- "link_cfg" ,
113
- span. unwrap ( ) ,
114
- GateIssue :: Language ,
115
- "is feature gated" ) ;
116
- }
117
- if lib. kind == cstore:: NativeStaticNobundle && !sess. features . borrow ( ) . static_nobundle {
118
- feature_gate:: emit_feature_err ( & sess. parse_sess ,
119
- "static_nobundle" ,
120
- span. unwrap ( ) ,
121
- GateIssue :: Language ,
122
- "kind=\" static-nobundle\" is feature gated" ) ;
123
- }
124
- cstore. add_used_library ( lib) ;
125
- }
126
-
127
- fn relevant_lib ( sess : & Session , lib : & NativeLibrary ) -> bool {
128
- match lib. cfg {
129
- Some ( ref cfg) => attr:: cfg_matches ( cfg, & sess. parse_sess , None ) ,
130
- None => true ,
131
- }
132
- }
133
-
134
82
// Extra info about a crate loaded for plugins or exported macros.
135
83
struct ExtensionCrate {
136
84
metadata : PMDSource ,
@@ -721,33 +669,6 @@ impl<'a> CrateLoader<'a> {
721
669
}
722
670
}
723
671
724
- fn get_foreign_items_of_kind ( & self , kind : cstore:: NativeLibraryKind ) -> Vec < DefIndex > {
725
- let mut items = vec ! [ ] ;
726
- let libs = self . cstore . get_used_libraries ( ) ;
727
- for lib in libs. borrow ( ) . iter ( ) {
728
- if relevant_lib ( self . sess , lib) && lib. kind == kind {
729
- items. extend ( & lib. foreign_items ) ;
730
- }
731
- }
732
- items
733
- }
734
-
735
- fn register_statically_included_foreign_items ( & mut self ) {
736
- for id in self . get_foreign_items_of_kind ( cstore:: NativeStatic ) {
737
- self . cstore . add_statically_included_foreign_item ( id) ;
738
- }
739
- for id in self . get_foreign_items_of_kind ( cstore:: NativeStaticNobundle ) {
740
- self . cstore . add_statically_included_foreign_item ( id) ;
741
- }
742
- }
743
-
744
- fn register_dllimport_foreign_items ( & mut self ) {
745
- let mut dllimports = self . cstore . dllimport_foreign_items . borrow_mut ( ) ;
746
- for id in self . get_foreign_items_of_kind ( cstore:: NativeUnknown ) {
747
- dllimports. insert ( id) ;
748
- }
749
- }
750
-
751
672
fn inject_panic_runtime ( & mut self , krate : & ast:: Crate ) {
752
673
// If we're only compiling an rlib, then there's no need to select a
753
674
// panic runtime, so we just skip this section entirely.
@@ -1152,84 +1073,6 @@ impl<'a> CrateLoader<'a> {
1152
1073
}
1153
1074
}
1154
1075
1155
- impl < ' a > CrateLoader < ' a > {
1156
- pub fn preprocess ( & mut self , krate : & ast:: Crate ) {
1157
- for attr in & krate. attrs {
1158
- if attr. path == "link_args" {
1159
- if let Some ( linkarg) = attr. value_str ( ) {
1160
- self . cstore . add_used_link_args ( & linkarg. as_str ( ) ) ;
1161
- }
1162
- }
1163
- }
1164
- }
1165
-
1166
- fn process_foreign_mod ( & mut self , i : & ast:: Item , fm : & ast:: ForeignMod ,
1167
- definitions : & Definitions ) {
1168
- if fm. abi == Abi :: Rust || fm. abi == Abi :: RustIntrinsic || fm. abi == Abi :: PlatformIntrinsic {
1169
- return ;
1170
- }
1171
-
1172
- // First, add all of the custom #[link_args] attributes
1173
- for m in i. attrs . iter ( ) . filter ( |a| a. check_name ( "link_args" ) ) {
1174
- if let Some ( linkarg) = m. value_str ( ) {
1175
- self . cstore . add_used_link_args ( & linkarg. as_str ( ) ) ;
1176
- }
1177
- }
1178
-
1179
- // Next, process all of the #[link(..)]-style arguments
1180
- for m in i. attrs . iter ( ) . filter ( |a| a. check_name ( "link" ) ) {
1181
- let items = match m. meta_item_list ( ) {
1182
- Some ( item) => item,
1183
- None => continue ,
1184
- } ;
1185
- let kind = items. iter ( ) . find ( |k| {
1186
- k. check_name ( "kind" )
1187
- } ) . and_then ( |a| a. value_str ( ) ) . map ( Symbol :: as_str) ;
1188
- let kind = match kind. as_ref ( ) . map ( |s| & s[ ..] ) {
1189
- Some ( "static" ) => cstore:: NativeStatic ,
1190
- Some ( "static-nobundle" ) => cstore:: NativeStaticNobundle ,
1191
- Some ( "dylib" ) => cstore:: NativeUnknown ,
1192
- Some ( "framework" ) => cstore:: NativeFramework ,
1193
- Some ( k) => {
1194
- struct_span_err ! ( self . sess, m. span, E0458 ,
1195
- "unknown kind: `{}`" , k)
1196
- . span_label ( m. span , "unknown kind" ) . emit ( ) ;
1197
- cstore:: NativeUnknown
1198
- }
1199
- None => cstore:: NativeUnknown
1200
- } ;
1201
- let n = items. iter ( ) . find ( |n| {
1202
- n. check_name ( "name" )
1203
- } ) . and_then ( |a| a. value_str ( ) ) ;
1204
- let n = match n {
1205
- Some ( n) => n,
1206
- None => {
1207
- struct_span_err ! ( self . sess, m. span, E0459 ,
1208
- "#[link(...)] specified without `name = \" foo\" `" )
1209
- . span_label ( m. span , "missing `name` argument" ) . emit ( ) ;
1210
- Symbol :: intern ( "foo" )
1211
- }
1212
- } ;
1213
- let cfg = items. iter ( ) . find ( |k| {
1214
- k. check_name ( "cfg" )
1215
- } ) . and_then ( |a| a. meta_item_list ( ) ) ;
1216
- let cfg = cfg. map ( |list| {
1217
- list[ 0 ] . meta_item ( ) . unwrap ( ) . clone ( )
1218
- } ) ;
1219
- let foreign_items = fm. items . iter ( )
1220
- . map ( |it| definitions. opt_def_index ( it. id ) . unwrap ( ) )
1221
- . collect ( ) ;
1222
- let lib = NativeLibrary {
1223
- name : n,
1224
- kind,
1225
- cfg,
1226
- foreign_items,
1227
- } ;
1228
- register_native_lib ( self . sess , self . cstore , Some ( m. span ) , lib) ;
1229
- }
1230
- }
1231
- }
1232
-
1233
1076
impl < ' a > middle:: cstore:: CrateLoader for CrateLoader < ' a > {
1234
1077
fn postprocess ( & mut self , krate : & ast:: Crate ) {
1235
1078
// inject the sanitizer runtime before the allocator runtime because all
@@ -1242,72 +1085,10 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
1242
1085
if log_enabled ! ( log:: LogLevel :: Info ) {
1243
1086
dump_crates ( & self . cstore ) ;
1244
1087
}
1245
-
1246
- // Process libs passed on the command line
1247
- // First, check for errors
1248
- let mut renames = FxHashSet ( ) ;
1249
- for & ( ref name, ref new_name, _) in & self . sess . opts . libs {
1250
- if let & Some ( ref new_name) = new_name {
1251
- if new_name. is_empty ( ) {
1252
- self . sess . err (
1253
- & format ! ( "an empty renaming target was specified for library `{}`" , name) ) ;
1254
- } else if !self . cstore . get_used_libraries ( ) . borrow ( ) . iter ( )
1255
- . any ( |lib| lib. name == name as & str ) {
1256
- self . sess . err ( & format ! ( "renaming of the library `{}` was specified, \
1257
- however this crate contains no #[link(...)] \
1258
- attributes referencing this library.", name) ) ;
1259
- } else if renames. contains ( name) {
1260
- self . sess . err ( & format ! ( "multiple renamings were specified for library `{}` ." ,
1261
- name) ) ;
1262
- } else {
1263
- renames. insert ( name) ;
1264
- }
1265
- }
1266
- }
1267
- // Update kind and, optionally, the name of all native libaries
1268
- // (there may be more than one) with the specified name.
1269
- for & ( ref name, ref new_name, kind) in & self . sess . opts . libs {
1270
- let mut found = false ;
1271
- for lib in self . cstore . get_used_libraries ( ) . borrow_mut ( ) . iter_mut ( ) {
1272
- if lib. name == name as & str {
1273
- let mut changed = false ;
1274
- if let Some ( k) = kind {
1275
- lib. kind = k;
1276
- changed = true ;
1277
- }
1278
- if let & Some ( ref new_name) = new_name {
1279
- lib. name = Symbol :: intern ( new_name) ;
1280
- changed = true ;
1281
- }
1282
- if !changed {
1283
- self . sess . warn ( & format ! ( "redundant linker flag specified for library `{}`" ,
1284
- name) ) ;
1285
- }
1286
-
1287
- found = true ;
1288
- }
1289
- }
1290
- if !found {
1291
- // Add if not found
1292
- let new_name = new_name. as_ref ( ) . map ( |s| & * * s) ; // &Option<String> -> Option<&str>
1293
- let lib = NativeLibrary {
1294
- name : Symbol :: intern ( new_name. unwrap_or ( name) ) ,
1295
- kind : if let Some ( k) = kind { k } else { cstore:: NativeUnknown } ,
1296
- cfg : None ,
1297
- foreign_items : Vec :: new ( ) ,
1298
- } ;
1299
- register_native_lib ( self . sess , self . cstore , None , lib) ;
1300
- }
1301
- }
1302
- self . register_statically_included_foreign_items ( ) ;
1303
- self . register_dllimport_foreign_items ( ) ;
1304
1088
}
1305
1089
1306
1090
fn process_item ( & mut self , item : & ast:: Item , definitions : & Definitions ) {
1307
1091
match item. node {
1308
- ast:: ItemKind :: ForeignMod ( ref fm) => {
1309
- self . process_foreign_mod ( item, fm, definitions)
1310
- } ,
1311
1092
ast:: ItemKind :: ExternCrate ( _) => {
1312
1093
let info = self . extract_crate_info ( item) . unwrap ( ) ;
1313
1094
let ( cnum, ..) = self . resolve_crate (
0 commit comments