@@ -1040,6 +1040,98 @@ fn target_runner_does_not_apply_to_build_script() {
10401040 . run ( ) ;
10411041}
10421042
1043+ #[ cargo_test]
1044+ fn target_runner_build_script_with_target ( ) {
1045+ let target = rustc_host ( ) ;
1046+ let p = project ( )
1047+ . file (
1048+ ".cargo/config.toml" ,
1049+ & format ! (
1050+ r#"
1051+ [target.{target}]
1052+ runner = "nonexistent-runner"
1053+ [target.'cfg(all())']
1054+ runner = "nonexistent-cfg-runner"
1055+ "# ,
1056+ ) ,
1057+ )
1058+ . file ( "build.rs" , "fn main() {}" )
1059+ . file ( "src/lib.rs" , "" )
1060+ . build ( ) ;
1061+
1062+ p. cargo ( "check -v --target" )
1063+ . arg ( & target)
1064+ . with_stderr_data ( str![ [ r#"
1065+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
1066+ [RUNNING] `rustc --crate-name build_script_build [..]`
1067+ [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
1068+ [RUNNING] `rustc --crate-name foo [..]`
1069+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1070+
1071+ "# ] ] )
1072+ . run ( ) ;
1073+ }
1074+
1075+ #[ cargo_test]
1076+ fn target_cfg_runner_build_script_with_host_config_and_target ( ) {
1077+ let target = rustc_host ( ) ;
1078+ let p = project ( )
1079+ . file (
1080+ ".cargo/config.toml" ,
1081+ r#"
1082+ [target.'cfg(all())']
1083+ runner = "nonexistent-cfg-runner"
1084+ "# ,
1085+ )
1086+ . file ( "build.rs" , "fn main() {}" )
1087+ . file ( "src/lib.rs" , "" )
1088+ . build ( ) ;
1089+
1090+ p. cargo ( "check -v -Ztarget-applies-to-host -Zhost-config --target" )
1091+ . arg ( & target)
1092+ . masquerade_as_nightly_cargo ( & [ "target-applies-to-host" , "host-config" ] )
1093+ . with_stderr_data ( str![ [ r#"
1094+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
1095+ [RUNNING] `rustc --crate-name build_script_build [..]`
1096+ [RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
1097+ [RUNNING] `rustc --crate-name foo [..]`
1098+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1099+
1100+ "# ] ] )
1101+ . run ( ) ;
1102+ }
1103+
1104+ #[ cargo_test]
1105+ fn host_runner_build_script_without_target ( ) {
1106+ let p = project ( )
1107+ . file (
1108+ ".cargo/config.toml" ,
1109+ r#"
1110+ [host]
1111+ runner = "nonexistent-host-runner"
1112+ "# ,
1113+ )
1114+ . file ( "build.rs" , "fn main() {}" )
1115+ . file ( "src/lib.rs" , "" )
1116+ . build ( ) ;
1117+
1118+ p. cargo ( "check -Ztarget-applies-to-host -Zhost-config" )
1119+ . masquerade_as_nightly_cargo ( & [ "target-applies-to-host" , "host-config" ] )
1120+ . with_status ( 101 )
1121+ . with_stderr_data ( str![ [ r#"
1122+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
1123+ [ERROR] failed to run custom build command for `foo v0.0.1 ([ROOT]/foo)`
1124+
1125+ Caused by:
1126+ could not execute process `nonexistent-host-runner [ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` (never executed)
1127+
1128+ Caused by:
1129+ [NOT_FOUND]
1130+
1131+ "# ] ] )
1132+ . run ( ) ;
1133+ }
1134+
10431135#[ cargo_test]
10441136fn custom_build_script_wrong_rustc_flags ( ) {
10451137 let p = project ( )
0 commit comments