@@ -393,6 +393,27 @@ pub fn check_incompatible_options_for_ci_rustc(
393
393
Ok ( ( ) )
394
394
}
395
395
396
+ pub ( crate ) const VALID_CODEGEN_BACKENDS : & [ & str ] = & [ "llvm" , "cranelift" , "gcc" ] ;
397
+
398
+ pub ( crate ) fn validate_codegen_backends ( backends : Vec < String > , section : & str ) -> Vec < String > {
399
+ for backend in & backends {
400
+ if let Some ( stripped) = backend. strip_prefix ( CODEGEN_BACKEND_PREFIX ) {
401
+ panic ! (
402
+ "Invalid value '{backend}' for '{section}.codegen-backends'. \
403
+ Codegen backends are defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \
404
+ Please, use '{stripped}' instead."
405
+ )
406
+ }
407
+ if !VALID_CODEGEN_BACKENDS . contains ( & backend. as_str ( ) ) {
408
+ println ! (
409
+ "HELP: '{backend}' for '{section}.codegen-backends' might fail. \
410
+ List of known good values: {VALID_CODEGEN_BACKENDS:?}"
411
+ ) ;
412
+ }
413
+ }
414
+ backends
415
+ }
416
+
396
417
impl Config {
397
418
pub fn apply_rust_config (
398
419
& mut self ,
@@ -571,24 +592,10 @@ impl Config {
571
592
set ( & mut self . ehcont_guard , ehcont_guard) ;
572
593
self . llvm_libunwind_default =
573
594
llvm_libunwind. map ( |v| v. parse ( ) . expect ( "failed to parse rust.llvm-libunwind" ) ) ;
574
-
575
- if let Some ( ref backends) = codegen_backends {
576
- let available_backends = [ "llvm" , "cranelift" , "gcc" ] ;
577
-
578
- self . rust_codegen_backends = backends. iter ( ) . map ( |s| {
579
- if let Some ( backend) = s. strip_prefix ( CODEGEN_BACKEND_PREFIX ) {
580
- if available_backends. contains ( & backend) {
581
- panic ! ( "Invalid value '{s}' for 'rust.codegen-backends'. Instead, please use '{backend}'." ) ;
582
- } else {
583
- println ! ( "HELP: '{s}' for 'rust.codegen-backends' might fail. \
584
- Codegen backends are mostly defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \
585
- In this case, it would be referred to as '{backend}'.") ;
586
- }
587
- }
588
-
589
- s. clone ( )
590
- } ) . collect ( ) ;
591
- }
595
+ set (
596
+ & mut self . rust_codegen_backends ,
597
+ codegen_backends. map ( |backends| validate_codegen_backends ( backends, "rust" ) ) ,
598
+ ) ;
592
599
593
600
self . rust_codegen_units = codegen_units. map ( threads_from_config) ;
594
601
self . rust_codegen_units_std = codegen_units_std. map ( threads_from_config) ;
0 commit comments