@@ -357,25 +357,28 @@ fn custom_linker_env() {
357
357
fn target_in_environment_contains_lower_case ( ) {
358
358
let p = project ( ) . file ( "src/main.rs" , "fn main() {}" ) . build ( ) ;
359
359
360
- let target_keys = [
361
- "CARGO_TARGET_X86_64_UNKNOWN_LINUX_musl_LINKER" ,
362
- "CARGO_TARGET_x86_64_unknown_linux_musl_LINKER" ,
363
- ] ;
364
-
365
- for target_key in & target_keys {
366
- let mut execs = p. cargo ( "build -v --target x86_64-unknown-linux-musl" ) ;
367
- execs. env ( target_key, "nonexistent-linker" ) . with_status ( 101 ) ;
368
- if cfg ! ( windows) {
369
- execs. with_stderr_does_not_contain ( "warning:[..]" ) ;
370
- } else {
371
- execs. with_stderr_contains ( format ! (
372
- "warning: Environment variables are expected to use uppercase letters and underscores, \
373
- the variable `{}` will be ignored and have no effect",
374
- target_key
375
- ) ) ;
376
- }
377
- execs. run ( ) ;
360
+ let target = rustc_host ( ) ;
361
+ let env_key = format ! (
362
+ "CARGO_TARGET_{}_LINKER" ,
363
+ target. to_lowercase( ) . replace( '-' , "_" )
364
+ ) ;
365
+
366
+ let mut execs = p. cargo ( "build -v --target" ) ;
367
+ execs. arg ( target) . env ( & env_key, "nonexistent-linker" ) ;
368
+ if cfg ! ( windows) {
369
+ // Windows env keys are case insensitive, so no warning, but it will
370
+ // fail due to the missing linker.
371
+ execs
372
+ . with_stderr_does_not_contain ( "warning:[..]" )
373
+ . with_status ( 101 ) ;
374
+ } else {
375
+ execs. with_stderr_contains ( format ! (
376
+ "warning: Environment variables are expected to use uppercase letters and underscores, \
377
+ the variable `{}` will be ignored and have no effect",
378
+ env_key
379
+ ) ) ;
378
380
}
381
+ execs. run ( ) ;
379
382
}
380
383
381
384
#[ cargo_test]
0 commit comments