@@ -367,17 +367,40 @@ impl LinkSelfContained {
367
367
}
368
368
369
369
/// To help checking CLI usage while some of the values are unstable: returns whether one of the
370
- /// components was set individually. This would also require the `-Zunstable-options` flag, to
371
- /// be allowed.
372
- fn are_unstable_variants_set ( & self ) -> bool {
370
+ /// unstable components was set individually, for the given `TargetTuple`. This would also
371
+ /// require the `-Zunstable-options` flag, to be allowed.
372
+ fn check_unstable_variants ( & self , target_tuple : & TargetTuple ) -> Result < ( ) , String > {
373
373
if self . explicitly_set . is_some ( ) {
374
- return false ;
374
+ return Ok ( ( ) ) ;
375
375
}
376
376
377
- // Only the linker component is stable, anything else is thus unstable.
378
- let mentioned_components = self . enabled_components . union ( self . disabled_components ) ;
379
- let unstable_components = mentioned_components - LinkSelfContainedComponents :: LINKER ;
380
- !unstable_components. is_empty ( )
377
+ // `-C link-self-contained=[-+]linker` is only stable on x64 linux.
378
+ let check_linker = |components : LinkSelfContainedComponents , polarity : & str | {
379
+ let has_linker = components. is_linker_enabled ( ) ;
380
+ if has_linker && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
381
+ return Err ( format ! (
382
+ "`-C link-self-contained={polarity}linker` is unstable on the `{target_tuple}` \
383
+ target. The `-Z unstable-options` flag must also be passed to use it on this target",
384
+ ) ) ;
385
+ }
386
+ Ok ( ( ) )
387
+ } ;
388
+ check_linker ( self . enabled_components , "+" ) ?;
389
+ check_linker ( self . disabled_components , "-" ) ?;
390
+
391
+ // Since only the linker component is stable, any other component used is unstable, and
392
+ // that's an error.
393
+ let unstable_enabled = self . enabled_components - LinkSelfContainedComponents :: LINKER ;
394
+ let unstable_disabled = self . disabled_components - LinkSelfContainedComponents :: LINKER ;
395
+ if !unstable_enabled. union ( unstable_disabled) . is_empty ( ) {
396
+ return Err ( String :: from (
397
+ "only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`\
398
+ /`+linker` are stable, the `-Z unstable-options` flag must also be passed to use \
399
+ the unstable values",
400
+ ) ) ;
401
+ }
402
+
403
+ Ok ( ( ) )
381
404
}
382
405
383
406
/// Returns whether the self-contained linker component was enabled on the CLI, using the
@@ -2646,17 +2669,13 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2646
2669
)
2647
2670
}
2648
2671
2649
- // For testing purposes, until we have more feedback about these options: ensure `-Z
2650
- // unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2651
- // linker-flavor` options.
2672
+ let target_triple = parse_target_triple ( early_dcx, matches) ;
2673
+
2674
+ // Ensure `-Z unstable-options` is required when using the unstable `-C link-self-contained` and
2675
+ // `-C linker-flavor` options.
2652
2676
if !unstable_options_enabled {
2653
- let uses_unstable_self_contained_option =
2654
- cg. link_self_contained . are_unstable_variants_set ( ) ;
2655
- if uses_unstable_self_contained_option {
2656
- early_dcx. early_fatal (
2657
- "only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker`/`+linker` are stable, \
2658
- the `-Z unstable-options` flag must also be passed to use the unstable values",
2659
- ) ;
2677
+ if let Err ( error) = cg. link_self_contained . check_unstable_variants ( & target_triple) {
2678
+ early_dcx. early_fatal ( error) ;
2660
2679
}
2661
2680
2662
2681
if let Some ( flavor) = cg. linker_flavor {
@@ -2688,7 +2707,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
2688
2707
let cg = cg;
2689
2708
2690
2709
let sysroot_opt = matches. opt_str ( "sysroot" ) . map ( |m| PathBuf :: from ( & m) ) ;
2691
- let target_triple = parse_target_triple ( early_dcx, matches) ;
2692
2710
let opt_level = parse_opt_level ( early_dcx, matches, & cg) ;
2693
2711
// The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able
2694
2712
// to use them interchangeably. See the note above (regarding `-O` and `-C opt-level`)
0 commit comments