Skip to content

Commit f8a12ee

Browse files
committed
ensure all cfgs used are allowed
1 parent 88b7f0d commit f8a12ee

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

build.rs

+30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@ use std::env;
22
use std::process::Command;
33
use std::str;
44

5+
// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
6+
// need to know all the possible cfgs that this script will set. If you need to set another cfg
7+
// make sure to add it to this list as well.
8+
const ALLOWED_CFGS: &[&str] = &[
9+
"freebsd10",
10+
"freebsd11",
11+
"freebsd12",
12+
"freebsd13",
13+
"freebsd14",
14+
"libc_align",
15+
"libc_cfg_target_vendor",
16+
"libc_const_extern_fn",
17+
"libc_const_extern_fn_unstable",
18+
"libc_const_size_of",
19+
"libc_core_cvoid",
20+
"libc_deny_warnings",
21+
"libc_int128",
22+
"libc_long_array",
23+
"libc_non_exhaustive",
24+
"libc_packedN",
25+
"libc_priv_mod_use",
26+
"libc_ptr_addr_of",
27+
"libc_thread_local",
28+
"libc_underscore_const_names",
29+
"libc_union",
30+
];
31+
532
fn main() {
633
// Avoid unnecessary re-building.
734
println!("cargo:rerun-if-changed=build.rs");
@@ -181,5 +208,8 @@ fn which_freebsd() -> Option<i32> {
181208
}
182209

183210
fn set_cfg(cfg: &str) {
211+
if !ALLOWED_CFGS.contains(&cfg) {
212+
panic!("trying to set cfg {}, but it is not in ALLOWED_CFGS", cfg);
213+
}
184214
println!("cargo:rustc-cfg={}", cfg);
185215
}

0 commit comments

Comments
 (0)