From f8a12ee0a4e96f830cdc765343aa60cbe27c5a4a Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 14 Dec 2022 13:41:49 +0100 Subject: ensure all cfgs used are allowed --- build.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/build.rs b/build.rs index 9a52435e49..ab299b70ba 100644 --- a/build.rs +++ b/build.rs @@ -2,6 +2,33 @@ use std::env; use std::process::Command; use std::str; +// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we +// need to know all the possible cfgs that this script will set. If you need to set another cfg +// make sure to add it to this list as well. +const ALLOWED_CFGS: &[&str] = &[ + "freebsd10", + "freebsd11", + "freebsd12", + "freebsd13", + "freebsd14", + "libc_align", + "libc_cfg_target_vendor", + "libc_const_extern_fn", + "libc_const_extern_fn_unstable", + "libc_const_size_of", + "libc_core_cvoid", + "libc_deny_warnings", + "libc_int128", + "libc_long_array", + "libc_non_exhaustive", + "libc_packedN", + "libc_priv_mod_use", + "libc_ptr_addr_of", + "libc_thread_local", + "libc_underscore_const_names", + "libc_union", +]; + fn main() { // Avoid unnecessary re-building. println!("cargo:rerun-if-changed=build.rs"); @@ -181,5 +208,8 @@ fn which_freebsd() -> Option { } fn set_cfg(cfg: &str) { + if !ALLOWED_CFGS.contains(&cfg) { + panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg); + } println!("cargo:rustc-cfg={}", cfg); } -- cgit v1.2.1