@@ -370,17 +370,40 @@ impl LinkSelfContained {
370
370
}
371
371
372
372
/// To help checking CLI usage while some of the values are unstable: returns whether one of the
373
- /// components was set individually. This would also require the `-Zunstable-options` flag, to
374
- /// be allowed.
375
- fn are_unstable_variants_set ( & self ) -> bool {
373
+ /// unstable components was set individually, for the given `TargetTuple`. This would also
374
+ /// require the `-Zunstable-options` flag, to be allowed.
375
+ fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
376
376
if self . explicitly_set . is_some ( ) {
377
- return false ;
377
+ return Ok ( ( ) ) ;
378
378
}
379
379
380
- // Only the linker component is stable, anything else is thus unstable.
381
- let mentioned_components = self . enabled_components . union ( self . disabled_components ) ;
382
- let unstable_components = mentioned_components - LinkSelfContainedComponents :: LINKER ;
383
- !unstable_components. is_empty ( )
380
+ // `-C link-self-contained=[-+]linker` is only stable on x64 linux.
381
+ let check_linker = |components : LinkSelfContainedComponents , polarity : & str | {
382
+ let has_linker = components. is_linker_enabled ( ) ;
383
+ if has_linker && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
384
+ return Err ( format ! (
385
+ "`-C link-self-contained={polarity}linker` is unstable on the `{target_tuple}` \
386
+ target. The `-Z unstable-options` flag must also be passed to use it on this target",
387
+ ) ) ;
388
+ }
389
+ Ok ( ( ) )
390
+ } ;
391
+ check_linker ( self . enabled_components , "+" ) ?;
392
+ check_linker ( self . disabled_components , "-" ) ?;
393
+
394
+ // Since only the linker component is stable, any other component used is unstable, and
395
+ // that's an error.
396
+ let unstable_enabled = self . enabled_components - LinkSelfContainedComponents :: LINKER ;
397
+ let unstable_disabled = self . disabled_components - LinkSelfContainedComponents :: LINKER ;
398
+ if !unstable_enabled. union ( unstable_disabled) . is_empty ( ) {
399
+ return Err ( String :: from (
400
+ "only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`\
401
+ /`+linker` are stable, the `-Z unstable-options` flag must also be passed to use \
402
+ the unstable values",
403
+ ) ) ;
404
+ }
405
+
406
+ Ok ( ( ) )
384
407
}
385
408
386
409
/// Returns whether the self-contained linker component was enabled on the CLI, using the
@@ -2689,17 +2712,13 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2689
2712
)
2690
2713
}
2691
2714
2692
- // For testing purposes, until we have more feedback about these options: ensure `-Z
2693
- // unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2694
- // linker-flavor` options.
2715
+ let target_triple = parse_target_triple ( early_dcx, matches) ;
2716
+
2717
+ // Ensure `-Z unstable-options` is required when using the unstable `-C link-self-contained` and
2718
+ // `-C linker-flavor` options.
2695
2719
if !unstable_options_enabled {
2696
- let uses_unstable_self_contained_option =
2697
- cg. link_self_contained . are_unstable_variants_set ( ) ;
2698
- if uses_unstable_self_contained_option {
2699
- early_dcx. early_fatal (
2700
- "only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, \
2701
- the `-Z unstable-options` flag must also be passed to use the unstable values",
2702
- ) ;
2720
+ if let Err ( error) = cg. link_self_contained . check_unstable_variants ( & target_triple) {
2721
+ early_dcx. early_fatal ( error) ;
2703
2722
}
2704
2723
2705
2724
if let Some ( flavor) = cg. linker_flavor {
@@ -2739,7 +2758,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2739
2758
2740
2759
let cg = cg;
2741
2760
2742
- let target_triple = parse_target_triple ( early_dcx, matches) ;
2743
2761
let opt_level = parse_opt_level ( early_dcx, matches, & cg) ;
2744
2762
// The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able
2745
2763
// to use them interchangeably. See the note above (regarding `-O` and `-C opt-level`)
0 commit comments