@@ -20,7 +20,7 @@ use serde_derive::Deserialize;
2020
2121use crate :: builder:: crate_description;
2222use crate :: builder:: Cargo ;
23- use crate :: builder:: { Builder , Kind , RunConfig , ShouldRun , Step } ;
23+ use crate :: builder:: { Builder , Kind , PathSet , RunConfig , ShouldRun , Step , TaskPath } ;
2424use crate :: cache:: { Interned , INTERNER } ;
2525use crate :: config:: { LlvmLibunwind , RustcLto , TargetSelection } ;
2626use crate :: dist;
@@ -995,6 +995,44 @@ pub struct CodegenBackend {
995995 pub backend : Interned < String > ,
996996}
997997
998+ fn needs_codegen_config ( run : & RunConfig < ' _ > ) -> bool {
999+ let mut needs_codegen_cfg = false ;
1000+ for path_set in & run. paths {
1001+ needs_codegen_cfg = match path_set {
1002+ PathSet :: Set ( set) => set. iter ( ) . any ( |p| is_codegen_cfg_needed ( p, run) ) ,
1003+ PathSet :: Suite ( suite) => is_codegen_cfg_needed ( & suite, run) ,
1004+ }
1005+ }
1006+ needs_codegen_cfg
1007+ }
1008+
1009+ const CODEGEN_BACKEND_PREFIX : & str = "rustc_codegen_" ;
1010+
1011+ fn is_codegen_cfg_needed ( path : & TaskPath , run : & RunConfig < ' _ > ) -> bool {
1012+ if path. path . to_str ( ) . unwrap ( ) . contains ( & CODEGEN_BACKEND_PREFIX ) {
1013+ let mut needs_codegen_backend_config = true ;
1014+ for & backend in & run. builder . config . rust_codegen_backends {
1015+ if path
1016+ . path
1017+ . to_str ( )
1018+ . unwrap ( )
1019+ . ends_with ( & ( CODEGEN_BACKEND_PREFIX . to_owned ( ) + & backend) )
1020+ {
1021+ needs_codegen_backend_config = false ;
1022+ }
1023+ }
1024+ if needs_codegen_backend_config {
1025+ run. builder . info (
1026+ "Warning: no codegen-backends config matched the requested path to build a codegen backend. \
1027+ Help: add backend to codegen-backends in config.toml.",
1028+ ) ;
1029+ return true ;
1030+ }
1031+ }
1032+
1033+ return false ;
1034+ }
1035+
9981036impl Step for CodegenBackend {
9991037 type Output = ( ) ;
10001038 const ONLY_HOSTS : bool = true ;
@@ -1006,6 +1044,10 @@ impl Step for CodegenBackend {
10061044 }
10071045
10081046 fn make_run ( run : RunConfig < ' _ > ) {
1047+ if needs_codegen_config ( & run) {
1048+ return ;
1049+ }
1050+
10091051 for & backend in & run. builder . config . rust_codegen_backends {
10101052 if backend == "llvm" {
10111053 continue ; // Already built as part of rustc
0 commit comments