@@ -5,7 +5,6 @@ use std::str::FromStr;
5
5
6
6
use serde:: { Deserialize , Deserializer } ;
7
7
8
- use crate :: core:: build_steps:: compile:: CODEGEN_BACKEND_PREFIX ;
9
8
use crate :: core:: config:: toml:: TomlConfig ;
10
9
use crate :: core:: config:: {
11
10
DebuginfoLevel , Merge , ReplaceOpt , RustcLto , StringOrBool , set, threads_from_config,
@@ -394,6 +393,23 @@ pub fn check_incompatible_options_for_ci_rustc(
394
393
Ok ( ( ) )
395
394
}
396
395
396
+ pub ( crate ) const VALID_CODEGEN_BACKENDS : & [ & str ] = & [ "llvm" , "cranelift" , "gcc" ] ;
397
+
398
+ pub ( crate ) fn validate_codegen_backends (
399
+ backends : Vec < String > ,
400
+ section : impl FnOnce ( ) -> String ,
401
+ ) -> Vec < String > {
402
+ for backend in & backends {
403
+ if !VALID_CODEGEN_BACKENDS . contains ( & & * * backend) {
404
+ let section = section ( ) ;
405
+ panic ! (
406
+ "Invalid value '{backend}' for '{section}.codegen-backends'. Permitted values: {VALID_CODEGEN_BACKENDS:?}."
407
+ ) ;
408
+ }
409
+ }
410
+ backends
411
+ }
412
+
397
413
impl Config {
398
414
pub fn apply_rust_config (
399
415
& mut self ,
@@ -572,24 +588,11 @@ impl Config {
572
588
set ( & mut self . ehcont_guard , ehcont_guard) ;
573
589
self . llvm_libunwind_default =
574
590
llvm_libunwind. map ( |v| v. parse ( ) . expect ( "failed to parse rust.llvm-libunwind" ) ) ;
575
-
576
- if let Some ( ref backends) = codegen_backends {
577
- let available_backends = [ "llvm" , "cranelift" , "gcc" ] ;
578
-
579
- self . rust_codegen_backends = backends. iter ( ) . map ( |s| {
580
- if let Some ( backend) = s. strip_prefix ( CODEGEN_BACKEND_PREFIX ) {
581
- if available_backends. contains ( & backend) {
582
- panic ! ( "Invalid value '{s}' for 'rust.codegen-backends'. Instead, please use '{backend}'." ) ;
583
- } else {
584
- println ! ( "HELP: '{s}' for 'rust.codegen-backends' might fail. \
585
- Codegen backends are mostly defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \
586
- In this case, it would be referred to as '{backend}'.") ;
587
- }
588
- }
589
-
590
- s. clone ( )
591
- } ) . collect ( ) ;
592
- }
591
+ set (
592
+ & mut self . rust_codegen_backends ,
593
+ codegen_backends
594
+ . map ( |backends| validate_codegen_backends ( backends, || "rust" . into ( ) ) ) ,
595
+ ) ;
593
596
594
597
self . rust_codegen_units = codegen_units. map ( threads_from_config) ;
595
598
self . rust_codegen_units_std = codegen_units_std. map ( threads_from_config) ;
0 commit comments