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