@@ -233,8 +233,13 @@ pub struct LinkSelfContained {
233
233
/// Used for compatibility with the existing opt-in and target inference.
234
234
pub explicitly_set : Option < bool > ,
235
235
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 ,
238
243
}
239
244
240
245
impl LinkSelfContained {
@@ -247,11 +252,13 @@ impl LinkSelfContained {
247
252
// `explicitly_set` state.
248
253
if let Some ( component_to_enable) = component. strip_prefix ( '+' ) {
249
254
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) ?) ;
251
257
Some ( ( ) )
252
258
} else if let Some ( component_to_disable) = component. strip_prefix ( '-' ) {
253
259
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) ?) ;
255
262
Some ( ( ) )
256
263
} else {
257
264
None
@@ -262,11 +269,14 @@ impl LinkSelfContained {
262
269
/// purposes.
263
270
pub ( crate ) fn set_all_explicitly ( & mut self , enabled : bool ) {
264
271
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 ( ) ;
267
276
} else {
268
- LinkSelfContainedComponents :: empty ( )
269
- } ;
277
+ self . enabled_components = LinkSelfContainedComponents :: empty ( ) ;
278
+ self . disabled_components = LinkSelfContainedComponents :: all ( ) ;
279
+ }
270
280
}
271
281
272
282
/// Helper creating a fully enabled `LinkSelfContained` instance. Used in tests.
@@ -280,13 +290,21 @@ impl LinkSelfContained {
280
290
/// components was set individually. This would also require the `-Zunstable-options` flag, to
281
291
/// be allowed.
282
292
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 ( ) ;
284
295
self . explicitly_set . is_none ( ) && any_component_set
285
296
}
286
297
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 )
290
308
}
291
309
}
292
310
0 commit comments