Skip to content

Commit 708352d

Browse files
committed
rerun the build script if the environment changes
1 parent 3f90313 commit 708352d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ 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();
42+
43+
println!("cargo:rerun-if-env-changed=LIBC_CI");
44+
println!("cargo:rerun-if-env-changed=LIBC_CHECK_CFG");
4145

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

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

0 commit comments

Comments
 (0)