Skip to content

Commit b636da0

Browse files
committed
emit rustc-check-cfg in the build script when LIBC_CHECK_CFG=1
1 parent f8a12ee commit b636da0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

build.rs

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn main() {
3838
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
3939
let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
4040
let libc_ci = env::var("LIBC_CI").is_ok();
41+
let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok();
4142

4243
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
4344
println!(
@@ -140,6 +141,17 @@ fn main() {
140141
set_cfg("libc_const_extern_fn");
141142
}
142143
}
144+
145+
// check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the
146+
// codebase. libc can configure it if the appropriate environment variable is passed. Since
147+
// rust-lang/rust enforces it, this is useful when using a custom libc fork there.
148+
//
149+
// https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg
150+
if libc_check_cfg {
151+
for cfg in ALLOWED_CFGS {
152+
println!("cargo:rustc-check-cfg=values({})", cfg);
153+
}
154+
}
143155
}
144156

145157
fn rustc_minor_nightly() -> (u32, bool) {

0 commit comments

Comments
 (0)