@@ -130,6 +130,8 @@ one detailed below.
130
130
compiler.
131
131
* [ ` cargo::rustc-cfg=KEY[="VALUE"] ` ] ( #rustc-cfg ) --- Enables compile-time ` cfg `
132
132
settings.
133
+ * [ ` cargo::rustc-check-cfg=CHECK_CFG ` ] ( #rustc-check-cfg ) -- Enables compile-time
134
+ checking of configs.
133
135
* [ ` cargo::rustc-env=VAR=VALUE ` ] ( #rustc-env ) --- Sets an environment variable.
134
136
* [ ` cargo::rustc-cdylib-link-arg=FLAG ` ] ( #rustc-cdylib-link-arg ) --- Passes custom
135
137
flags to a linker for cdylib crates.
@@ -233,7 +235,9 @@ equivalent to using [`rustc-link-lib`](#rustc-link-lib) and
233
235
234
236
The ` rustc-cfg ` instruction tells Cargo to pass the given value to the
235
237
[ ` --cfg ` flag] [ option-cfg ] to the compiler. This may be used for compile-time
236
- detection of features to enable [ conditional compilation] .
238
+ detection of features to enable [ conditional compilation] . Each custom cfgs
239
+ must ** always** be declared using the [ ` cargo::rustc-check-cfg ` ] ( #rustc-check-cfg )
240
+ instruction.
237
241
238
242
Note that this does * not* affect Cargo's dependency resolution. This cannot be
239
243
used to enable an optional dependency, or enable other Cargo features.
@@ -250,6 +254,39 @@ identifier, the value should be a string.
250
254
[ conditional compilation ] : ../../reference/conditional-compilation.md
251
255
[ option-cfg ] : ../../rustc/command-line-arguments.md#option-cfg
252
256
257
+ ### ` cargo::rustc-check-cfg=CHECK_CFG ` {#rustc-check-cfg}
258
+
259
+ The ` rustc-check-cfg ` instruction tells Cargo to pass the given expected
260
+ configs to the [ ` --check-cfg ` flag] [ option-check-cfg ] to the compiler. This is
261
+ used for compile-time detection of unexpected [ conditional compilation] configs.
262
+
263
+ You can use the instruction like this:
264
+
265
+ ``` rust,no_run
266
+ // build.rs
267
+ println!("cargo::rustc-check-cfg=cfg(foo, values(\"bar\"))");
268
+ ```
269
+
270
+ Be aware that the [ ` --check-cfg ` flag] [ option-check-cfg ] expected all possible
271
+ configs, regardless of which is currently enabled to ** always** be passed.
272
+
273
+ One way to achieve this is to group the check-cfg and cfg instruction as much as
274
+ possible.
275
+
276
+ <details >
277
+
278
+ ``` rust,no_run
279
+ // build.rs
280
+ println!("cargo::rustc-check-cfg=cfg(foo, values(\"bar\"))");
281
+ if foo_bar_condition {
282
+ println!("cargo::rustc-cfg=foo=\"bar\"");
283
+ }
284
+ ```
285
+
286
+ </details >
287
+
288
+ [ option-cfg ] : ../../rustc/command-line-arguments.md#option-check-cfg
289
+
253
290
### ` cargo::rustc-env=VAR=VALUE ` {#rustc-env}
254
291
255
292
The ` rustc-env ` instruction tells Cargo to set the given environment variable
0 commit comments