@@ -30,17 +30,18 @@ use rustc_target::spec::{
3030} ;
3131use tracing:: debug;
3232
33+ pub use crate :: config:: cfg:: { Cfg , CheckCfg , ExpectedValues } ;
34+ use crate :: config:: native_libs:: parse_libs;
3335use crate :: errors:: FileWriteFail ;
3436pub use crate :: options:: * ;
3537use crate :: search_paths:: SearchPath ;
36- use crate :: utils:: { CanonicalizedPath , NativeLib , NativeLibKind } ;
38+ use crate :: utils:: CanonicalizedPath ;
3739use crate :: { EarlyDiagCtxt , HashStableContext , Session , filesearch, lint} ;
3840
3941mod cfg;
42+ mod native_libs;
4043pub mod sigpipe;
4144
42- pub use cfg:: { Cfg , CheckCfg , ExpectedValues } ;
43-
4445/// The different settings that the `-C strip` flag can have.
4546#[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
4647pub enum Strip {
@@ -2134,143 +2135,6 @@ fn parse_assert_incr_state(
21342135 }
21352136}
21362137
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-
22742138pub fn parse_externs (
22752139 early_dcx : & EarlyDiagCtxt ,
22762140 matches : & getopts:: Matches ,
0 commit comments