@@ -55,7 +55,6 @@ fn env_rustflags_normal_source() {
55
55
fn env_rustflags_build_script ( ) {
56
56
// RUSTFLAGS should be passed to rustc for build scripts
57
57
// when --target is not specified.
58
- // In this test if --cfg foo is passed the build will fail.
59
58
let p = project ( )
60
59
. file (
61
60
"Cargo.toml" ,
@@ -70,9 +69,7 @@ fn env_rustflags_build_script() {
70
69
. file (
71
70
"build.rs" ,
72
71
r#"
73
- fn main() { }
74
- #[cfg(not(foo))]
75
- fn main() { }
72
+ fn main() { assert!(cfg!(foo)); }
76
73
"# ,
77
74
)
78
75
. build ( ) ;
@@ -243,7 +240,6 @@ fn env_rustflags_normal_source_with_target() {
243
240
fn env_rustflags_build_script_with_target ( ) {
244
241
// RUSTFLAGS should not be passed to rustc for build scripts
245
242
// when --target is specified.
246
- // In this test if --cfg foo is passed the build will fail.
247
243
let p = project ( )
248
244
. file (
249
245
"Cargo.toml" ,
@@ -258,9 +254,7 @@ fn env_rustflags_build_script_with_target() {
258
254
. file (
259
255
"build.rs" ,
260
256
r#"
261
- fn main() { }
262
- #[cfg(foo)]
263
- fn main() { }
257
+ fn main() { assert!(!cfg!(foo)); }
264
258
"# ,
265
259
)
266
260
. build ( ) ;
@@ -276,7 +270,6 @@ fn env_rustflags_build_script_with_target() {
276
270
fn env_rustflags_build_script_with_target_doesnt_apply_to_host_kind ( ) {
277
271
// RUSTFLAGS should *not* be passed to rustc for build scripts when --target is specified as the
278
272
// host triple even if target-applies-to-host-kind is enabled, to match legacy Cargo behavior.
279
- // In this test if --cfg foo is passed the build will fail.
280
273
let p = project ( )
281
274
. file (
282
275
"Cargo.toml" ,
@@ -291,9 +284,7 @@ fn env_rustflags_build_script_with_target_doesnt_apply_to_host_kind() {
291
284
. file (
292
285
"build.rs" ,
293
286
r#"
294
- fn main() { }
295
- #[cfg(foo)]
296
- fn main() { }
287
+ fn main() { assert!(!cfg!(foo)); }
297
288
"# ,
298
289
)
299
290
. file (
@@ -519,7 +510,6 @@ fn build_rustflags_normal_source() {
519
510
fn build_rustflags_build_script ( ) {
520
511
// RUSTFLAGS should be passed to rustc for build scripts
521
512
// when --target is not specified.
522
- // In this test if --cfg foo is passed the build will fail.
523
513
let p = project ( )
524
514
. file (
525
515
"Cargo.toml" ,
@@ -534,9 +524,7 @@ fn build_rustflags_build_script() {
534
524
. file (
535
525
"build.rs" ,
536
526
r#"
537
- fn main() { }
538
- #[cfg(not(foo))]
539
- fn main() { }
527
+ fn main() { assert!(cfg!(foo)); }
540
528
"# ,
541
529
)
542
530
. file (
@@ -737,7 +725,6 @@ fn build_rustflags_normal_source_with_target() {
737
725
fn build_rustflags_build_script_with_target ( ) {
738
726
// RUSTFLAGS should not be passed to rustc for build scripts
739
727
// when --target is specified.
740
- // In this test if --cfg foo is passed the build will fail.
741
728
let p = project ( )
742
729
. file (
743
730
"Cargo.toml" ,
@@ -752,9 +739,7 @@ fn build_rustflags_build_script_with_target() {
752
739
. file (
753
740
"build.rs" ,
754
741
r#"
755
- fn main() { }
756
- #[cfg(foo)]
757
- fn main() { }
742
+ fn main() { assert!(!cfg!(foo)); }
758
743
"# ,
759
744
)
760
745
. file (
@@ -1041,9 +1026,7 @@ fn target_rustflags_also_for_build_scripts() {
1041
1026
. file (
1042
1027
"build.rs" ,
1043
1028
r#"
1044
- fn main() { }
1045
- #[cfg(not(foo))]
1046
- fn main() { }
1029
+ fn main() { assert!(cfg!(foo)); }
1047
1030
"# ,
1048
1031
)
1049
1032
. file (
@@ -1069,9 +1052,7 @@ fn target_rustflags_not_for_build_scripts_with_target() {
1069
1052
. file (
1070
1053
"build.rs" ,
1071
1054
r#"
1072
- fn main() { }
1073
- #[cfg(foo)]
1074
- fn main() { }
1055
+ fn main() { assert!(!cfg!(foo)); }
1075
1056
"# ,
1076
1057
)
1077
1058
. file (
@@ -1124,9 +1105,7 @@ fn build_rustflags_for_build_scripts() {
1124
1105
. file (
1125
1106
"build.rs" ,
1126
1107
r#"
1127
- fn main() { }
1128
- #[cfg(foo)]
1129
- fn main() { }
1108
+ fn main() { assert!(cfg!(foo)); }
1130
1109
"# ,
1131
1110
)
1132
1111
. file (
@@ -1139,25 +1118,26 @@ fn build_rustflags_for_build_scripts() {
1139
1118
. build ( ) ;
1140
1119
1141
1120
// With "legacy" behavior, build.rustflags should apply to build scripts without --target
1142
- p. cargo ( "build" )
1143
- . with_status ( 101 )
1144
- . with_stderr_contains ( "[..]previous definition of the value `main` here[..]" )
1145
- . run ( ) ;
1121
+ p. cargo ( "build" ) . run ( ) ;
1146
1122
1147
1123
// But should _not_ apply _with_ --target
1148
- p. cargo ( "build --target" ) . arg ( host) . run ( ) ;
1124
+ p. cargo ( "build --target" )
1125
+ . arg ( host)
1126
+ . with_status ( 101 )
1127
+ . with_stderr_contains ( "[..]assertion failed[..]" )
1128
+ . run ( ) ;
1149
1129
1150
1130
// Enabling -Ztarget-applies-to-host should not make a difference without the config setting
1151
1131
p. cargo ( "build" )
1152
1132
. masquerade_as_nightly_cargo ( )
1153
1133
. arg ( "-Ztarget-applies-to-host" )
1154
- . with_status ( 101 )
1155
- . with_stderr_contains ( "[..]previous definition of the value `main` here[..]" )
1156
1134
. run ( ) ;
1157
1135
p. cargo ( "build --target" )
1158
1136
. arg ( host)
1159
1137
. masquerade_as_nightly_cargo ( )
1160
1138
. arg ( "-Ztarget-applies-to-host" )
1139
+ . with_status ( 101 )
1140
+ . with_stderr_contains ( "[..]assertion failed[..]" )
1161
1141
. run ( ) ;
1162
1142
1163
1143
// When set to false though, the "proper" behavior where host artifacts _only_ pick up on
@@ -1174,11 +1154,15 @@ fn build_rustflags_for_build_scripts() {
1174
1154
p. cargo ( "build" )
1175
1155
. masquerade_as_nightly_cargo ( )
1176
1156
. arg ( "-Ztarget-applies-to-host" )
1157
+ . with_status ( 101 )
1158
+ . with_stderr_contains ( "[..]assertion failed[..]" )
1177
1159
. run ( ) ;
1178
1160
p. cargo ( "build --target" )
1179
1161
. arg ( host)
1180
1162
. masquerade_as_nightly_cargo ( )
1181
1163
. arg ( "-Ztarget-applies-to-host" )
1164
+ . with_status ( 101 )
1165
+ . with_stderr_contains ( "[..]assertion failed[..]" )
1182
1166
. run ( ) ;
1183
1167
}
1184
1168
0 commit comments