From b636da0a67185598bbe739ed2c20910e51514e4d Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Fri, 24 Feb 2023 11:05:44 +0100 Subject: [PATCH] emit rustc-check-cfg in the build script when LIBC_CHECK_CFG=1 --- build.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.rs b/build.rs index ab299b70baa2a..cb70d6e238291 100644 --- a/build.rs +++ b/build.rs @@ -38,6 +38,7 @@ fn main() { let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok(); let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok(); let libc_ci = env::var("LIBC_CI").is_ok(); + let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok(); if env::var("CARGO_FEATURE_USE_STD").is_ok() { println!( @@ -140,6 +141,17 @@ fn main() { set_cfg("libc_const_extern_fn"); } } + + // check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the + // codebase. libc can configure it if the appropriate environment variable is passed. Since + // rust-lang/rust enforces it, this is useful when using a custom libc fork there. + // + // https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg + if libc_check_cfg { + for cfg in ALLOWED_CFGS { + println!("cargo:rustc-check-cfg=values({})", cfg); + } + } } fn rustc_minor_nightly() -> (u32, bool) {