summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.rs52
1 files changed, 27 insertions, 25 deletions
diff --git a/build.rs b/build.rs
index e97be1a6ab..9a52435e49 100644
--- a/build.rs
+++ b/build.rs
@@ -25,94 +25,92 @@ fn main() {
// On CI, we detect the actual FreeBSD version and match its ABI exactly,
// running tests to ensure that the ABI is correct.
match which_freebsd() {
- Some(10) if libc_ci || rustc_dep_of_std => {
- println!("cargo:rustc-cfg=freebsd10")
- }
- Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"),
- Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"),
- Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"),
- Some(14) if libc_ci => println!("cargo:rustc-cfg=freebsd14"),
- Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
+ Some(10) if libc_ci || rustc_dep_of_std => set_cfg("freebsd10"),
+ Some(11) if libc_ci => set_cfg("freebsd11"),
+ Some(12) if libc_ci => set_cfg("freebsd12"),
+ Some(13) if libc_ci => set_cfg("freebsd13"),
+ Some(14) if libc_ci => set_cfg("freebsd14"),
+ Some(_) | None => set_cfg("freebsd11"),
}
// On CI: deny all warnings
if libc_ci {
- println!("cargo:rustc-cfg=libc_deny_warnings");
+ set_cfg("libc_deny_warnings");
}
// Rust >= 1.15 supports private module use:
if rustc_minor_ver >= 15 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_priv_mod_use");
+ set_cfg("libc_priv_mod_use");
}
// Rust >= 1.19 supports unions:
if rustc_minor_ver >= 19 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_union");
+ set_cfg("libc_union");
}
// Rust >= 1.24 supports const mem::size_of:
if rustc_minor_ver >= 24 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_const_size_of");
+ set_cfg("libc_const_size_of");
}
// Rust >= 1.25 supports repr(align):
if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature {
- println!("cargo:rustc-cfg=libc_align");
+ set_cfg("libc_align");
}
// Rust >= 1.26 supports i128 and u128:
if rustc_minor_ver >= 26 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_int128");
+ set_cfg("libc_int128");
}
// Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it.
// Otherwise, it defines an incompatible type to retaining
// backwards-compatibility.
if rustc_minor_ver >= 30 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_core_cvoid");
+ set_cfg("libc_core_cvoid");
}
// Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor).
if rustc_minor_ver >= 33 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_packedN");
- println!("cargo:rustc-cfg=libc_cfg_target_vendor");
+ set_cfg("libc_packedN");
+ set_cfg("libc_cfg_target_vendor");
}
// Rust >= 1.40 supports #[non_exhaustive].
if rustc_minor_ver >= 40 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_non_exhaustive");
+ set_cfg("libc_non_exhaustive");
}
// Rust >= 1.47 supports long array:
if rustc_minor_ver >= 47 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_long_array");
+ set_cfg("libc_long_array");
}
if rustc_minor_ver >= 51 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_ptr_addr_of");
+ set_cfg("libc_ptr_addr_of");
}
// Rust >= 1.37.0 allows underscores as anonymous constant names.
if rustc_minor_ver >= 37 || rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_underscore_const_names");
+ set_cfg("libc_underscore_const_names");
}
// #[thread_local] is currently unstable
if rustc_dep_of_std {
- println!("cargo:rustc-cfg=libc_thread_local");
+ set_cfg("libc_thread_local");
}
// Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C".
if rustc_minor_ver >= 62 {
- println!("cargo:rustc-cfg=libc_const_extern_fn");
+ set_cfg("libc_const_extern_fn");
} else {
// Rust < 1.62.0 requires a crate feature and feature gate.
if const_extern_fn_cargo_feature {
if !is_nightly || rustc_minor_ver < 40 {
panic!("const-extern-fn requires a nightly compiler >= 1.40");
}
- println!("cargo:rustc-cfg=libc_const_extern_fn_unstable");
- println!("cargo:rustc-cfg=libc_const_extern_fn");
+ set_cfg("libc_const_extern_fn_unstable");
+ set_cfg("libc_const_extern_fn");
}
}
}
@@ -181,3 +179,7 @@ fn which_freebsd() -> Option<i32> {
_ => None,
}
}
+
+fn set_cfg(cfg: &str) {
+ println!("cargo:rustc-cfg={}", cfg);
+}