2018-09-17 20:33:52 +02:00
|
|
|
use std::env;
|
|
|
|
use std::process::Command;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
fn main() {
|
2019-02-07 11:37:21 +01:00
|
|
|
let rustc_minor_ver =
|
|
|
|
rustc_minor_version().expect("Failed to get rustc version");
|
2019-07-11 03:03:24 +02:00
|
|
|
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();
|
2019-08-14 07:30:15 +02:00
|
|
|
let libc_ci = env::var("LIBC_CI").is_ok();
|
2019-02-07 11:37:21 +01:00
|
|
|
|
2019-07-11 03:03:24 +02:00
|
|
|
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
|
2019-05-24 13:22:03 +02:00
|
|
|
println!(
|
|
|
|
"cargo:warning=\"libc's use_std cargo feature is deprecated since libc 0.2.55; \
|
|
|
|
please consider using the `std` cargo feature instead\""
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-25 00:23:40 +02:00
|
|
|
// 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.
|
2019-08-14 07:30:15 +02:00
|
|
|
//
|
|
|
|
// 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() {
|
2019-08-25 00:23:40 +02:00
|
|
|
Some(10) if libc_ci || rustc_dep_of_std => {
|
|
|
|
println!("cargo:rustc-cfg=freebsd10")
|
|
|
|
}
|
2019-08-14 07:30:15 +02:00
|
|
|
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"),
|
2019-08-15 06:55:13 +02:00
|
|
|
Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
|
Add a FreeBSD 12 build job and test FreeBSD12 APIs
This commits adds a second FreeBSD 12 build job,
and splits the implementation of the FreeBSD module
into two modules, one for FreeBSD 11, and one for FreeBSD 12.
The FreeBSD 11 module is compiled always by default, and is
mostly forward compatible with FreeBSD 12 systems.
The FreeBSD 12 module is only built for now in libc's CI,
and uses FreeBSD 12 data types and APIs, linking to symbols
that are only available in FreeBSD 12.
Basically, when LIBC_CI env variable is defined, and the host
system is a FreeBSD 12 system, then the FreeBSD 12 module is
automatically built and tested. Conditional compilation is done
using a `cfg(freebsd12)` flag.
This commit also re-enables many tests, and documents why
some remain disabled.
2019-05-16 14:53:51 +02:00
|
|
|
}
|
|
|
|
|
2019-08-16 15:22:56 +02:00
|
|
|
// On CI: deny all warnings
|
|
|
|
if libc_ci {
|
|
|
|
println!("cargo:rustc-cfg=libc_deny_warnings");
|
|
|
|
}
|
|
|
|
|
2019-02-07 11:37:21 +01:00
|
|
|
// Rust >= 1.15 supports private module use:
|
|
|
|
if rustc_minor_ver >= 15 || rustc_dep_of_std {
|
|
|
|
println!("cargo:rustc-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");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rust >= 1.25 supports repr(align):
|
|
|
|
if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature {
|
|
|
|
println!("cargo:rustc-cfg=libc_align");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rust >= 1.33 supports repr(packed(N))
|
|
|
|
if rustc_minor_ver >= 33 || rustc_dep_of_std {
|
|
|
|
println!("cargo:rustc-cfg=libc_packedN");
|
2018-09-17 20:33:52 +02:00
|
|
|
}
|
2019-07-11 03:03:24 +02:00
|
|
|
|
|
|
|
// #[thread_local] is currently unstable
|
2019-07-15 07:10:05 +02:00
|
|
|
if rustc_dep_of_std {
|
2019-07-11 03:03:24 +02:00
|
|
|
println!("cargo:rustc-cfg=libc_thread_local");
|
|
|
|
}
|
2018-09-17 20:33:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn rustc_minor_version() -> Option<u32> {
|
|
|
|
macro_rules! otry {
|
|
|
|
($e:expr) => {
|
|
|
|
match $e {
|
|
|
|
Some(e) => e,
|
|
|
|
None => return None,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let rustc = otry!(env::var_os("RUSTC"));
|
|
|
|
let output = otry!(Command::new(rustc).arg("--version").output().ok());
|
|
|
|
let version = otry!(str::from_utf8(&output.stdout).ok());
|
|
|
|
let mut pieces = version.split('.');
|
|
|
|
|
|
|
|
if pieces.next() != Some("rustc 1") {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
otry!(pieces.next()).parse().ok()
|
|
|
|
}
|
Add a FreeBSD 12 build job and test FreeBSD12 APIs
This commits adds a second FreeBSD 12 build job,
and splits the implementation of the FreeBSD module
into two modules, one for FreeBSD 11, and one for FreeBSD 12.
The FreeBSD 11 module is compiled always by default, and is
mostly forward compatible with FreeBSD 12 systems.
The FreeBSD 12 module is only built for now in libc's CI,
and uses FreeBSD 12 data types and APIs, linking to symbols
that are only available in FreeBSD 12.
Basically, when LIBC_CI env variable is defined, and the host
system is a FreeBSD 12 system, then the FreeBSD 12 module is
automatically built and tested. Conditional compilation is done
using a `cfg(freebsd12)` flag.
This commit also re-enables many tests, and documents why
some remain disabled.
2019-05-16 14:53:51 +02:00
|
|
|
|
|
|
|
fn which_freebsd() -> Option<i32> {
|
|
|
|
let output = std::process::Command::new("freebsd-version").output().ok();
|
|
|
|
if output.is_none() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let output = output.unwrap();
|
|
|
|
if !output.status.success() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let stdout = String::from_utf8(output.stdout).ok();
|
|
|
|
if stdout.is_none() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let stdout = stdout.unwrap();
|
|
|
|
|
|
|
|
match &stdout {
|
2019-08-25 00:23:40 +02:00
|
|
|
s if s.starts_with("10") => Some(10),
|
Add a FreeBSD 12 build job and test FreeBSD12 APIs
This commits adds a second FreeBSD 12 build job,
and splits the implementation of the FreeBSD module
into two modules, one for FreeBSD 11, and one for FreeBSD 12.
The FreeBSD 11 module is compiled always by default, and is
mostly forward compatible with FreeBSD 12 systems.
The FreeBSD 12 module is only built for now in libc's CI,
and uses FreeBSD 12 data types and APIs, linking to symbols
that are only available in FreeBSD 12.
Basically, when LIBC_CI env variable is defined, and the host
system is a FreeBSD 12 system, then the FreeBSD 12 module is
automatically built and tested. Conditional compilation is done
using a `cfg(freebsd12)` flag.
This commit also re-enables many tests, and documents why
some remain disabled.
2019-05-16 14:53:51 +02:00
|
|
|
s if s.starts_with("11") => Some(11),
|
|
|
|
s if s.starts_with("12") => Some(12),
|
2019-07-21 17:49:08 +02:00
|
|
|
s if s.starts_with("13") => Some(13),
|
Add a FreeBSD 12 build job and test FreeBSD12 APIs
This commits adds a second FreeBSD 12 build job,
and splits the implementation of the FreeBSD module
into two modules, one for FreeBSD 11, and one for FreeBSD 12.
The FreeBSD 11 module is compiled always by default, and is
mostly forward compatible with FreeBSD 12 systems.
The FreeBSD 12 module is only built for now in libc's CI,
and uses FreeBSD 12 data types and APIs, linking to symbols
that are only available in FreeBSD 12.
Basically, when LIBC_CI env variable is defined, and the host
system is a FreeBSD 12 system, then the FreeBSD 12 module is
automatically built and tested. Conditional compilation is done
using a `cfg(freebsd12)` flag.
This commit also re-enables many tests, and documents why
some remain disabled.
2019-05-16 14:53:51 +02:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|