diff options
author | Pietro Albini <pietro.albini@ferrous-systems.com> | 2023-02-24 11:05:44 +0100 |
---|---|---|
committer | Pietro Albini <pietro.albini@ferrous-systems.com> | 2023-03-06 09:39:30 +0100 |
commit | b636da0a67185598bbe739ed2c20910e51514e4d (patch) | |
tree | 393a65873b417ceb86b8fd99dd2225d325a1379c | |
parent | f8a12ee0a4e96f830cdc765343aa60cbe27c5a4a (diff) | |
download | rust-libc-b636da0a67185598bbe739ed2c20910e51514e4d.tar.gz |
emit rustc-check-cfg in the build script when LIBC_CHECK_CFG=1
-rw-r--r-- | build.rs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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) { |