@@ -239,3 +239,65 @@ fn cfg_paradox() {
239
239
. with_stderr_contains ( "[..]--cfg=bertrand[..]" )
240
240
. run ( ) ;
241
241
}
242
+
243
+ /// This test checks how Cargo handles rustc cfgs which are defined both with
244
+ /// and without a value. The expected behavior is that the environment variable
245
+ /// is going to contain all the values.
246
+ ///
247
+ /// For example, this configuration:
248
+ /// ```
249
+ /// target_has_atomic
250
+ /// target_has_atomic="16"
251
+ /// target_has_atomic="32"
252
+ /// target_has_atomic="64"
253
+ /// target_has_atomic="8"
254
+ /// target_has_atomic="ptr"
255
+ /// ```
256
+ ///
257
+ /// Should result in the following environment variable:
258
+ ///
259
+ /// ```
260
+ /// CARGO_CFG_TARGET_HAS_ATOMIC=16,32,64,8,ptr
261
+ /// ```
262
+ ///
263
+ /// On the other hand, configuration symbols without any value should result in
264
+ /// an empty string.
265
+ ///
266
+ /// For example, this configuration:
267
+ ///
268
+ /// ```
269
+ /// target_thread_local
270
+ /// ```
271
+ ///
272
+ /// Should result in the following environment variable:
273
+ ///
274
+ /// ```
275
+ /// CARGO_CFG_TARGET_THREAD_LOCAL=
276
+ /// ```
277
+ #[ cargo_test( nightly, reason = "affected rustc cfg is unstable" ) ]
278
+ #[ cfg( target_arch = "x86_64" ) ]
279
+ fn rustc_cfg_with_and_without_value ( ) {
280
+ let build_rs = r#"
281
+ fn main() {
282
+ let cfg = std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC");
283
+ eprintln!("CARGO_CFG_TARGET_HAS_ATOMIC={cfg:?}");
284
+ let cfg = std::env::var("CARGO_CFG_WINDOWS");
285
+ eprintln!("CARGO_CFG_WINDOWS={cfg:?}");
286
+ let cfg = std::env::var("CARGO_CFG_UNIX");
287
+ eprintln!("CARGO_CFG_UNIX={cfg:?}");
288
+ }
289
+ "# ;
290
+ let p = project ( )
291
+ . file ( "src/lib.rs" , r#""# )
292
+ . file ( "build.rs" , build_rs)
293
+ . build ( ) ;
294
+
295
+ let mut check = p. cargo ( "check -vv" ) ;
296
+ #[ cfg( target_has_atomic = "64" ) ]
297
+ check. with_stderr_contains ( "[foo 0.0.1] CARGO_CFG_TARGET_HAS_ATOMIC=Ok(\" [..]64[..]\" )" ) ;
298
+ #[ cfg( windows) ]
299
+ check. with_stderr_contains ( "[foo 0.0.1] CARGO_CFG_WINDOWS=Ok(\" \" )" ) ;
300
+ #[ cfg( unix) ]
301
+ check. with_stderr_contains ( "[foo 0.0.1] CARGO_CFG_UNIX=Ok(\" \" )" ) ;
302
+ check. run ( ) ;
303
+ }
0 commit comments