@@ -370,12 +370,34 @@ impl LinkSelfContained {
370370 }
371371
372372 /// 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 {
376- let any_component_set =
377- !self . enabled_components . is_empty ( ) || !self . disabled_components . is_empty ( ) ;
378- self . explicitly_set . is_none ( ) && any_component_set
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+ if self . explicitly_set . is_some ( ) {
377+ return Ok ( ( ) ) ;
378+ }
379+
380+ // `-C link-self-contained=-linker` is only stable on x64 linux.
381+ let has_minus_linker = self . disabled_components . is_linker_enabled ( ) ;
382+ if has_minus_linker && target_tuple. tuple ( ) != "x86_64-unknown-linux-gnu" {
383+ return Err ( format ! (
384+ "`-C link-self-contained=-linker` is unstable on the `{target_tuple}` \
385+ target. The `-Z unstable-options` flag must also be passed to use it on this target",
386+ ) ) ;
387+ }
388+
389+ // Any `+linker` or other component used is unstable, and that's an error.
390+ let unstable_enabled = self . enabled_components ;
391+ let unstable_disabled = self . disabled_components - LinkSelfContainedComponents :: LINKER ;
392+ if !unstable_enabled. union ( unstable_disabled) . is_empty ( ) {
393+ return Err ( String :: from (
394+ "only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off`/`-linker` \
395+ are stable, the `-Z unstable-options` flag must also be passed to use \
396+ the unstable values",
397+ ) ) ;
398+ }
399+
400+ Ok ( ( ) )
379401 }
380402
381403 /// Returns whether the self-contained linker component was enabled on the CLI, using the
@@ -2679,17 +2701,13 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26792701 )
26802702 }
26812703
2682- // For testing purposes, until we have more feedback about these options: ensure `-Z
2683- // unstable-options` is required when using the unstable `-C link-self-contained` and `-C
2684- // linker-flavor` options.
2704+ let target_triple = parse_target_triple ( early_dcx, matches) ;
2705+
2706+ // Ensure `-Z unstable-options` is required when using the unstable `-C link-self-contained` and
2707+ // `-C linker-flavor` options.
26852708 if !unstable_options_enabled {
2686- let uses_unstable_self_contained_option =
2687- cg. link_self_contained . are_unstable_variants_set ( ) ;
2688- if uses_unstable_self_contained_option {
2689- early_dcx. early_fatal (
2690- "only `-C link-self-contained` values `y`/`yes`/`on`/`n`/`no`/`off` are stable, \
2691- the `-Z unstable-options` flag must also be passed to use the unstable values",
2692- ) ;
2709+ if let Err ( error) = cg. link_self_contained . check_unstable_variants ( & target_triple) {
2710+ early_dcx. early_fatal ( error) ;
26932711 }
26942712
26952713 if let Some ( flavor) = cg. linker_flavor {
@@ -2729,7 +2747,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27292747
27302748 let cg = cg;
27312749
2732- let target_triple = parse_target_triple ( early_dcx, matches) ;
27332750 let opt_level = parse_opt_level ( early_dcx, matches, & cg) ;
27342751 // The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able
27352752 // to use them interchangeably. See the note above (regarding `-O` and `-C opt-level`)
0 commit comments