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