Add libc_thread_local cfg and unstable feature

This commit is contained in:
Joe Richey 2019-07-10 18:03:24 -07:00
parent 956ba42753
commit 3fa021d7ab
6 changed files with 35 additions and 15 deletions

View File

@ -26,8 +26,9 @@ rustc-std-workspace-core = { version = "1.0.0", optional = true }
default = ["std"]
std = []
align = []
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
rustc-dep-of-std = ['align', 'rustc-std-workspace-core', 'unstable']
extra_traits = []
unstable = []
# use_std is deprecated, use `std` instead
use_std = [ 'std' ]

View File

@ -35,6 +35,9 @@ libc = "0.2"
* `extra_traits`: all `struct`s implemented in `libc` are `Copy` and `Clone`.
This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`.
* `unstable`: enable currently unstable bindings. Right now, this just allows
bindings to `#[thread_local]` statics on certain platforms. Requires nightly.
* **deprecated**: `use_std` is deprecated, and is equivalent to `std`.
## Rust version support

View File

@ -5,18 +5,18 @@ use std::str;
fn main() {
let rustc_minor_ver =
rustc_minor_version().expect("Failed to get rustc version");
let rustc_dep_of_std =
std::env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
let align_cargo_feature = std::env::var("CARGO_FEATURE_ALIGN").is_ok();
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();
let unstable_cargo_feature = env::var("CARGO_FEATURE_UNSTABLE").is_ok();
if std::env::var("CARGO_FEATURE_USE_STD").is_ok() {
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
println!(
"cargo:warning=\"libc's use_std cargo feature is deprecated since libc 0.2.55; \
please consider using the `std` cargo feature instead\""
);
}
if std::env::var("LIBC_CI").is_ok() {
if env::var("LIBC_CI").is_ok() {
if let Some(12) = which_freebsd() {
println!("cargo:rustc-cfg=freebsd12");
}
@ -53,6 +53,11 @@ fn main() {
if rustc_minor_ver >= 33 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_packedN");
}
// #[thread_local] is currently unstable
if unstable_cargo_feature || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_thread_local");
}
}
fn rustc_minor_version() -> Option<u32> {

View File

@ -21,6 +21,7 @@
feature = "rustc-dep-of-std",
feature(cfg_target_vendor, link_cfg, no_core)
)]
#![cfg_attr(libc_thread_local, feature(thread_local))]
// Enable extra lints:
#![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))]
#![deny(missing_copy_implementations, safe_packed_borrows)]

View File

@ -0,0 +1,12 @@
// DragonFlyBSD's __error function is declared with "static inline", so it must
// be implemented in the libc crate, as a pointer to a static thread_local.
f! {
pub fn __error() -> *mut ::c_int {
&mut errno
}
}
extern {
#[thread_local]
pub static mut errno: ::c_int;
}

View File

@ -1036,18 +1036,9 @@ f! {
(_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) +
_CMSG_ALIGN(length as usize)) as ::c_uint
}
#[cfg(libc_thread_local)]
pub fn __error() -> *mut ::c_int {
&mut errno
}
}
extern {
#[cfg(libc_thread_local)]
#[thread_local]
static mut errno: ::c_int;
pub fn setgrent();
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
@ -1069,3 +1060,10 @@ extern {
pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int;
pub fn uname(buf: *mut ::utsname) -> ::c_int;
}
cfg_if! {
if #[cfg(libc_thread_local)] {
mod errno;
pub use self::errno::*;
}
}