@@ -18,7 +18,7 @@ use rustc_feature::UnstableFeatures;
1818use rustc_span:: edition:: { Edition , DEFAULT_EDITION , EDITION_NAME_LIST , LATEST_STABLE_EDITION } ;
1919use rustc_span:: source_map:: FilePathMapping ;
2020use rustc_span:: { FileName , FileNameDisplayPreference , RealFileName , SourceFileHashAlgorithm } ;
21- use rustc_target:: spec:: LinkSelfContainedComponents ;
21+ use rustc_target:: spec:: { LinkSelfContainedComponents , LinkerFeatures } ;
2222use rustc_target:: spec:: { SplitDebuginfo , Target , TargetTriple } ;
2323use std:: collections:: btree_map:: {
2424 Iter as BTreeMapIter , Keys as BTreeMapKeysIter , Values as BTreeMapValuesIter ,
@@ -292,6 +292,48 @@ impl LinkSelfContained {
292292 }
293293}
294294
295+ /// The different values that `-Z linker-features` can take on the CLI: a list of individually
296+ /// enabled or disabled features used during linking.
297+ ///
298+ /// There is no need to enable or disable them in bulk. Each feature is fine-grained, and can be
299+ /// used to turn `LinkerFeatures` on or off, without needing to change the linker flavor:
300+ /// - using the system lld, or the self-contained `rust-lld` linker
301+ /// - using a C/C++ compiler to drive the linker (not yet exposed on the CLI)
302+ /// - etc.
303+ #[ derive( Default , Copy , Clone , PartialEq , Debug ) ]
304+ pub struct LinkerFeaturesCli {
305+ /// The linker features that are enabled on the CLI, using the `+feature` syntax.
306+ pub enabled : LinkerFeatures ,
307+
308+ /// The linker features that are disabled on the CLI, using the `-feature` syntax.
309+ pub disabled : LinkerFeatures ,
310+ }
311+
312+ impl LinkerFeaturesCli {
313+ /// Accumulates an enabled or disabled feature as specified on the CLI, if possible.
314+ /// For example: `+lld`, and `-lld`.
315+ pub ( crate ) fn handle_cli_feature ( & mut self , feature : & str ) -> Option < ( ) > {
316+ // Duplicate flags are reduced as we go, the last occurrence wins:
317+ // `+feature,-feature,+feature` only enables the feature, and does not record it as both
318+ // enabled and disabled on the CLI.
319+ // We also only expose `+/-lld` at the moment, as it's currenty the only implemented linker
320+ // feature and toggling `LinkerFeatures::CC` would be a noop.
321+ match feature {
322+ "+lld" => {
323+ self . enabled . insert ( LinkerFeatures :: LLD ) ;
324+ self . disabled . remove ( LinkerFeatures :: LLD ) ;
325+ Some ( ( ) )
326+ }
327+ "-lld" => {
328+ self . disabled . insert ( LinkerFeatures :: LLD ) ;
329+ self . enabled . remove ( LinkerFeatures :: LLD ) ;
330+ Some ( ( ) )
331+ }
332+ _ => None ,
333+ }
334+ }
335+ }
336+
295337/// Used with `-Z assert-incr-state`.
296338#[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
297339pub enum IncrementalStateAssertion {
0 commit comments