@@ -30,17 +30,18 @@ use rustc_target::spec::{
30
30
} ;
31
31
use tracing:: debug;
32
32
33
+ pub use crate :: config:: cfg:: { Cfg , CheckCfg , ExpectedValues } ;
34
+ use crate :: config:: native_libs:: parse_native_libs;
33
35
use crate :: errors:: FileWriteFail ;
34
36
pub use crate :: options:: * ;
35
37
use crate :: search_paths:: SearchPath ;
36
- use crate :: utils:: { CanonicalizedPath , NativeLib , NativeLibKind } ;
38
+ use crate :: utils:: CanonicalizedPath ;
37
39
use crate :: { EarlyDiagCtxt , HashStableContext , Session , filesearch, lint} ;
38
40
39
41
mod cfg;
42
+ mod native_libs;
40
43
pub mod sigpipe;
41
44
42
- pub use cfg:: { Cfg , CheckCfg , ExpectedValues } ;
43
-
44
45
/// The different settings that the `-C strip` flag can have.
45
46
#[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
46
47
pub enum Strip {
@@ -2134,143 +2135,6 @@ fn parse_assert_incr_state(
2134
2135
}
2135
2136
}
2136
2137
2137
- fn parse_native_lib_kind (
2138
- early_dcx : & EarlyDiagCtxt ,
2139
- matches : & getopts:: Matches ,
2140
- kind : & str ,
2141
- ) -> ( NativeLibKind , Option < bool > ) {
2142
- let ( kind, modifiers) = match kind. split_once ( ':' ) {
2143
- None => ( kind, None ) ,
2144
- Some ( ( kind, modifiers) ) => ( kind, Some ( modifiers) ) ,
2145
- } ;
2146
-
2147
- let kind = match kind {
2148
- "static" => NativeLibKind :: Static { bundle : None , whole_archive : None } ,
2149
- "dylib" => NativeLibKind :: Dylib { as_needed : None } ,
2150
- "framework" => NativeLibKind :: Framework { as_needed : None } ,
2151
- "link-arg" => {
2152
- if !nightly_options:: is_unstable_enabled ( matches) {
2153
- let why = if nightly_options:: match_is_nightly_build ( matches) {
2154
- " and only accepted on the nightly compiler"
2155
- } else {
2156
- ", the `-Z unstable-options` flag must also be passed to use it"
2157
- } ;
2158
- early_dcx. early_fatal ( format ! ( "library kind `link-arg` is unstable{why}" ) )
2159
- }
2160
- NativeLibKind :: LinkArg
2161
- }
2162
- _ => early_dcx. early_fatal ( format ! (
2163
- "unknown library kind `{kind}`, expected one of: static, dylib, framework, link-arg"
2164
- ) ) ,
2165
- } ;
2166
- match modifiers {
2167
- None => ( kind, None ) ,
2168
- Some ( modifiers) => parse_native_lib_modifiers ( early_dcx, kind, modifiers, matches) ,
2169
- }
2170
- }
2171
-
2172
- fn parse_native_lib_modifiers (
2173
- early_dcx : & EarlyDiagCtxt ,
2174
- mut kind : NativeLibKind ,
2175
- modifiers : & str ,
2176
- matches : & getopts:: Matches ,
2177
- ) -> ( NativeLibKind , Option < bool > ) {
2178
- let mut verbatim = None ;
2179
- for modifier in modifiers. split ( ',' ) {
2180
- let ( modifier, value) = match modifier. strip_prefix ( [ '+' , '-' ] ) {
2181
- Some ( m) => ( m, modifier. starts_with ( '+' ) ) ,
2182
- None => early_dcx. early_fatal (
2183
- "invalid linking modifier syntax, expected '+' or '-' prefix \
2184
- before one of: bundle, verbatim, whole-archive, as-needed",
2185
- ) ,
2186
- } ;
2187
-
2188
- let report_unstable_modifier = || {
2189
- if !nightly_options:: is_unstable_enabled ( matches) {
2190
- let why = if nightly_options:: match_is_nightly_build ( matches) {
2191
- " and only accepted on the nightly compiler"
2192
- } else {
2193
- ", the `-Z unstable-options` flag must also be passed to use it"
2194
- } ;
2195
- early_dcx. early_fatal ( format ! ( "linking modifier `{modifier}` is unstable{why}" ) )
2196
- }
2197
- } ;
2198
- let assign_modifier = |dst : & mut Option < bool > | {
2199
- if dst. is_some ( ) {
2200
- let msg = format ! ( "multiple `{modifier}` modifiers in a single `-l` option" ) ;
2201
- early_dcx. early_fatal ( msg)
2202
- } else {
2203
- * dst = Some ( value) ;
2204
- }
2205
- } ;
2206
- match ( modifier, & mut kind) {
2207
- ( "bundle" , NativeLibKind :: Static { bundle, .. } ) => assign_modifier ( bundle) ,
2208
- ( "bundle" , _) => early_dcx. early_fatal (
2209
- "linking modifier `bundle` is only compatible with `static` linking kind" ,
2210
- ) ,
2211
-
2212
- ( "verbatim" , _) => assign_modifier ( & mut verbatim) ,
2213
-
2214
- ( "whole-archive" , NativeLibKind :: Static { whole_archive, .. } ) => {
2215
- assign_modifier ( whole_archive)
2216
- }
2217
- ( "whole-archive" , _) => early_dcx. early_fatal (
2218
- "linking modifier `whole-archive` is only compatible with `static` linking kind" ,
2219
- ) ,
2220
-
2221
- ( "as-needed" , NativeLibKind :: Dylib { as_needed } )
2222
- | ( "as-needed" , NativeLibKind :: Framework { as_needed } ) => {
2223
- report_unstable_modifier ( ) ;
2224
- assign_modifier ( as_needed)
2225
- }
2226
- ( "as-needed" , _) => early_dcx. early_fatal (
2227
- "linking modifier `as-needed` is only compatible with \
2228
- `dylib` and `framework` linking kinds",
2229
- ) ,
2230
-
2231
- // Note: this error also excludes the case with empty modifier
2232
- // string, like `modifiers = ""`.
2233
- _ => early_dcx. early_fatal ( format ! (
2234
- "unknown linking modifier `{modifier}`, expected one \
2235
- of: bundle, verbatim, whole-archive, as-needed"
2236
- ) ) ,
2237
- }
2238
- }
2239
-
2240
- ( kind, verbatim)
2241
- }
2242
-
2243
- fn parse_libs ( early_dcx : & EarlyDiagCtxt , matches : & getopts:: Matches ) -> Vec < NativeLib > {
2244
- matches
2245
- . opt_strs ( "l" )
2246
- . into_iter ( )
2247
- . map ( |s| {
2248
- // Parse string of the form "[KIND[:MODIFIERS]=]lib[:new_name]",
2249
- // where KIND is one of "dylib", "framework", "static", "link-arg" and
2250
- // where MODIFIERS are a comma separated list of supported modifiers
2251
- // (bundle, verbatim, whole-archive, as-needed). Each modifier is prefixed
2252
- // with either + or - to indicate whether it is enabled or disabled.
2253
- // The last value specified for a given modifier wins.
2254
- let ( name, kind, verbatim) = match s. split_once ( '=' ) {
2255
- None => ( s, NativeLibKind :: Unspecified , None ) ,
2256
- Some ( ( kind, name) ) => {
2257
- let ( kind, verbatim) = parse_native_lib_kind ( early_dcx, matches, kind) ;
2258
- ( name. to_string ( ) , kind, verbatim)
2259
- }
2260
- } ;
2261
-
2262
- let ( name, new_name) = match name. split_once ( ':' ) {
2263
- None => ( name, None ) ,
2264
- Some ( ( name, new_name) ) => ( name. to_string ( ) , Some ( new_name. to_owned ( ) ) ) ,
2265
- } ;
2266
- if name. is_empty ( ) {
2267
- early_dcx. early_fatal ( "library name must not be empty" ) ;
2268
- }
2269
- NativeLib { name, new_name, kind, verbatim }
2270
- } )
2271
- . collect ( )
2272
- }
2273
-
2274
2138
pub fn parse_externs (
2275
2139
early_dcx : & EarlyDiagCtxt ,
2276
2140
matches : & getopts:: Matches ,
@@ -2644,7 +2508,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2644
2508
let debuginfo = select_debuginfo ( matches, & cg) ;
2645
2509
let debuginfo_compression = unstable_opts. debuginfo_compression ;
2646
2510
2647
- let libs = parse_libs ( early_dcx, matches) ;
2511
+ let crate_name = matches. opt_str ( "crate-name" ) ;
2512
+ let unstable_features = UnstableFeatures :: from_environment ( crate_name. as_deref ( ) ) ;
2513
+ // Parse any `-l` flags, which link to native libraries.
2514
+ let libs = parse_native_libs ( early_dcx, & unstable_opts, unstable_features, matches) ;
2648
2515
2649
2516
let test = matches. opt_present ( "test" ) ;
2650
2517
@@ -2659,8 +2526,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2659
2526
2660
2527
let externs = parse_externs ( early_dcx, matches, & unstable_opts) ;
2661
2528
2662
- let crate_name = matches. opt_str ( "crate-name" ) ;
2663
-
2664
2529
let remap_path_prefix = parse_remap_path_prefix ( early_dcx, matches, & unstable_opts) ;
2665
2530
2666
2531
let pretty = parse_pretty ( early_dcx, & unstable_opts) ;
@@ -2734,7 +2599,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2734
2599
error_format,
2735
2600
diagnostic_width,
2736
2601
externs,
2737
- unstable_features : UnstableFeatures :: from_environment ( crate_name . as_deref ( ) ) ,
2602
+ unstable_features,
2738
2603
crate_name,
2739
2604
libs,
2740
2605
debug_assertions,
0 commit comments