summaryrefslogtreecommitdiff
path: root/libc/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'libc/build.rs')
-rw-r--r--libc/build.rs43
1 files changed, 37 insertions, 6 deletions
diff --git a/libc/build.rs b/libc/build.rs
index efc95b6..f447c0e 100644
--- a/libc/build.rs
+++ b/libc/build.rs
@@ -3,11 +3,12 @@ use std::process::Command;
use std::str;
fn main() {
- let rustc_minor_ver =
- rustc_minor_version().expect("Failed to get rustc version");
+ let (rustc_minor_ver, is_nightly) =
+ rustc_minor_nightly().expect("Failed to get rustc version");
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
- #[allow(unused)]
+ let const_extern_fn_cargo_feature =
+ env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
let libc_ci = env::var("LIBC_CI").is_ok();
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
@@ -17,17 +18,26 @@ fn main() {
);
}
- // The ABI of libc is backward compatible with FreeBSD 11.
+ // The ABI of libc used by libstd is backward compatible with FreeBSD 10.
+ // The ABI of libc from crates.io is backward compatible with FreeBSD 11.
//
// 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(_) | None => println!("cargo:rustc-cfg=freebsd11"),
}
+ // On CI: deny all warnings
+ if libc_ci {
+ println!("cargo:rustc-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");
@@ -64,9 +74,16 @@ fn main() {
if rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_thread_local");
}
+
+ 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");
+ }
}
-fn rustc_minor_version() -> Option<u32> {
+fn rustc_minor_nightly() -> Option<(u32, bool)> {
macro_rules! otry {
($e:expr) => {
match $e {
@@ -85,7 +102,20 @@ fn rustc_minor_version() -> Option<u32> {
return None;
}
- otry!(pieces.next()).parse().ok()
+ let minor = pieces.next();
+
+ // If `rustc` was built from a tarball, its version string
+ // will have neither a git hash nor a commit date
+ // (e.g. "rustc 1.39.0"). Treat this case as non-nightly,
+ // since a nightly build should either come from CI
+ // or a git checkout
+ let nightly_raw = otry!(pieces.next()).split('-').nth(1);
+ let nightly = nightly_raw
+ .map(|raw| raw.starts_with("dev") || raw.starts_with("nightly"))
+ .unwrap_or(false);
+ let minor = otry!(otry!(minor).parse().ok());
+
+ Some((minor, nightly))
}
fn which_freebsd() -> Option<i32> {
@@ -105,6 +135,7 @@ fn which_freebsd() -> Option<i32> {
let stdout = stdout.unwrap();
match &stdout {
+ s if s.starts_with("10") => Some(10),
s if s.starts_with("11") => Some(11),
s if s.starts_with("12") => Some(12),
s if s.starts_with("13") => Some(13),