@@ -233,8 +233,13 @@ pub struct LinkSelfContained {
233233 /// Used for compatibility with the existing opt-in and target inference.
234234 pub explicitly_set : Option < bool > ,
235235
236- /// The components that are enabled.
237- components : LinkSelfContainedComponents ,
236+ /// The components that are enabled on the CLI, using the `+component` syntax or one of the
237+ /// `true` shorcuts.
238+ enabled_components : LinkSelfContainedComponents ,
239+
240+ /// The components that are disabled on the CLI, using the `-component` syntax or one of the
241+ /// `false` shortcuts.
242+ disabled_components : LinkSelfContainedComponents ,
238243}
239244
240245impl LinkSelfContained {
@@ -247,11 +252,13 @@ impl LinkSelfContained {
247252 // `explicitly_set` state.
248253 if let Some ( component_to_enable) = component. strip_prefix ( '+' ) {
249254 self . explicitly_set = None ;
250- self . components . insert ( LinkSelfContainedComponents :: from_str ( component_to_enable) ?) ;
255+ self . enabled_components
256+ . insert ( LinkSelfContainedComponents :: from_str ( component_to_enable) ?) ;
251257 Some ( ( ) )
252258 } else if let Some ( component_to_disable) = component. strip_prefix ( '-' ) {
253259 self . explicitly_set = None ;
254- self . components . remove ( LinkSelfContainedComponents :: from_str ( component_to_disable) ?) ;
260+ self . disabled_components
261+ . insert ( LinkSelfContainedComponents :: from_str ( component_to_disable) ?) ;
255262 Some ( ( ) )
256263 } else {
257264 None
@@ -262,11 +269,14 @@ impl LinkSelfContained {
262269 /// purposes.
263270 pub ( crate ) fn set_all_explicitly ( & mut self , enabled : bool ) {
264271 self . explicitly_set = Some ( enabled) ;
265- self . components = if enabled {
266- LinkSelfContainedComponents :: all ( )
272+
273+ if enabled {
274+ self . enabled_components = LinkSelfContainedComponents :: all ( ) ;
275+ self . disabled_components = LinkSelfContainedComponents :: empty ( ) ;
267276 } else {
268- LinkSelfContainedComponents :: empty ( )
269- } ;
277+ self . enabled_components = LinkSelfContainedComponents :: empty ( ) ;
278+ self . disabled_components = LinkSelfContainedComponents :: all ( ) ;
279+ }
270280 }
271281
272282 /// Helper creating a fully enabled `LinkSelfContained` instance. Used in tests.
@@ -280,13 +290,21 @@ impl LinkSelfContained {
280290 /// components was set individually. This would also require the `-Zunstable-options` flag, to
281291 /// be allowed.
282292 fn are_unstable_variants_set ( & self ) -> bool {
283- let any_component_set = !self . components . is_empty ( ) ;
293+ let any_component_set =
294+ !self . enabled_components . is_empty ( ) || !self . disabled_components . is_empty ( ) ;
284295 self . explicitly_set . is_none ( ) && any_component_set
285296 }
286297
287- /// Returns whether the self-contained linker component is enabled.
288- pub fn linker ( & self ) -> bool {
289- self . components . contains ( LinkSelfContainedComponents :: LINKER )
298+ /// Returns whether the self-contained linker component was enabled on the CLI, using the
299+ /// `-C link-self-contained=+linker` syntax, or one of the `true` shorcuts.
300+ pub fn is_linker_enabled ( & self ) -> bool {
301+ self . enabled_components . contains ( LinkSelfContainedComponents :: LINKER )
302+ }
303+
304+ /// Returns whether the self-contained linker component was disabled on the CLI, using the
305+ /// `-C link-self-contained=-linker` syntax, or one of the `false` shorcuts.
306+ pub fn is_linker_disabled ( & self ) -> bool {
307+ self . disabled_components . contains ( LinkSelfContainedComponents :: LINKER )
290308 }
291309}
292310
0 commit comments