Skip to content

Commit

Permalink
Require rust >= 1.25 and drop libc_align conditional
Browse files Browse the repository at this point in the history
This is mostly taken from Josh's work at [1], I just updated to account
for conflicts and new uses of `libc_align`.

[1]: rust-lang#2845

Co-authored-by: Josh Triplett <josh@joshtriplett.org>
  • Loading branch information
tgross35 and joshtriplett committed Nov 16, 2024
1 parent 5a43dd2 commit 34af772
Show file tree
Hide file tree
Showing 111 changed files with 1,769 additions and 2,861 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ rustc-std-workspace-core = { version = "1.0.0", optional = true }
[features]
default = ["std"]
std = []
align = []
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
extra_traits = []
const-extern-fn = []

# `align` is deprecated and no longer does anything
align = []

# use_std is deprecated, use `std` instead
use_std = ['std']

Expand Down
7 changes: 0 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"freebsd13",
"freebsd14",
"freebsd15",
"libc_align",
"libc_cfg_target_vendor",
"libc_const_extern_fn",
"libc_const_extern_fn_unstable",
Expand Down Expand Up @@ -51,7 +50,6 @@ fn main() {

let (rustc_minor_ver, is_nightly) = rustc_minor_nightly();
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 const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
let libc_ci = env::var("LIBC_CI").is_ok();
let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok() || rustc_minor_ver >= 80;
Expand Down Expand Up @@ -96,11 +94,6 @@ fn main() {
set_cfg("libc_deny_warnings");
}

// Rust >= 1.25 supports repr(align):
if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature {
set_cfg("libc_align");
}

// Rust >= 1.26 supports i128 and u128:
if rustc_minor_ver >= 26 || rustc_dep_of_std {
set_cfg("libc_int128");
Expand Down
7 changes: 1 addition & 6 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ fn do_ctest() {

fn ctest_cfg() -> ctest::TestGenerator {
let mut cfg = ctest::TestGenerator::new();
let libc_cfgs = [
"libc_align",
"libc_core_cvoid",
"libc_packedN",
"libc_thread_local",
];
let libc_cfgs = ["libc_core_cvoid", "libc_packedN", "libc_thread_local"];
for f in &libc_cfgs {
cfg.cfg(f, None);
}
Expand Down
142 changes: 0 additions & 142 deletions src/fuchsia/align.rs

This file was deleted.

162 changes: 140 additions & 22 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,35 @@ s! {
pub ipi6_addr: ::in6_addr,
pub ipi6_ifindex: ::c_uint,
}

#[cfg_attr(
any(
target_pointer_width = "32",
target_arch = "x86_64"
),
repr(align(4)))]
#[cfg_attr(
not(any(
target_pointer_width = "32",
target_arch = "x86_64"
)),
repr(align(8)))]
pub struct pthread_mutexattr_t {
size: [u8; ::__SIZEOF_PTHREAD_MUTEXATTR_T],
}

#[cfg_attr(target_pointer_width = "32",
repr(align(4)))]
#[cfg_attr(target_pointer_width = "64",
repr(align(8)))]
pub struct pthread_rwlockattr_t {
size: [u8; ::__SIZEOF_PTHREAD_RWLOCKATTR_T],
}

#[repr(align(4))]
pub struct pthread_condattr_t {
size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -979,6 +1008,42 @@ s_no_extra_traits! {
pub sigev_notify_attributes: *mut pthread_attr_t,
pub __pad: [::c_char; 56 - 3 * 8 /* 8 == sizeof(long) */],
}

#[cfg_attr(all(target_pointer_width = "32",
any(target_arch = "arm",
target_arch = "x86_64")),
repr(align(4)))]
#[cfg_attr(any(target_pointer_width = "64",
not(any(target_arch = "arm",
target_arch = "x86_64"))),
repr(align(8)))]
pub struct pthread_mutex_t {
size: [u8; ::__SIZEOF_PTHREAD_MUTEX_T],
}

#[cfg_attr(all(target_pointer_width = "32",
any(target_arch = "arm",
target_arch = "x86_64")),
repr(align(4)))]
#[cfg_attr(any(target_pointer_width = "64",
not(any(target_arch = "arm",
target_arch = "x86_64"))),
repr(align(8)))]
pub struct pthread_rwlock_t {
size: [u8; ::__SIZEOF_PTHREAD_RWLOCK_T],
}

#[cfg_attr(target_pointer_width = "32",
repr(align(4)))]
#[cfg_attr(target_pointer_width = "64",
repr(align(8)))]
#[cfg_attr(target_arch = "x86",
repr(align(4)))]
#[cfg_attr(not(target_arch = "x86"),
repr(align(8)))]
pub struct pthread_cond_t {
size: [u8; ::__SIZEOF_PTHREAD_COND_T],
}
}

cfg_if! {
Expand Down Expand Up @@ -1306,6 +1371,72 @@ cfg_if! {
self.sigev_notify_attributes.hash(state);
}
}

impl PartialEq for pthread_cond_t {
fn eq(&self, other: &pthread_cond_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_cond_t {}
impl ::fmt::Debug for pthread_cond_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_cond_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_cond_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}

impl PartialEq for pthread_mutex_t {
fn eq(&self, other: &pthread_mutex_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_mutex_t {}
impl ::fmt::Debug for pthread_mutex_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_mutex_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_mutex_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}

impl PartialEq for pthread_rwlock_t {
fn eq(&self, other: &pthread_rwlock_t) -> bool {
self.size
.iter()
.zip(other.size.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_rwlock_t {}
impl ::fmt::Debug for pthread_rwlock_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_rwlock_t")
// FIXME: .field("size", &self.size)
.finish()
}
}
impl ::hash::Hash for pthread_rwlock_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.size.hash(state);
}
}
}
}

Expand Down Expand Up @@ -2315,17 +2446,15 @@ pub const RTLD_NOW: ::c_int = 0x2;

pub const TCP_MD5SIG: ::c_int = 14;

align_const! {
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
size: [0; __SIZEOF_PTHREAD_MUTEX_T],
};
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
size: [0; __SIZEOF_PTHREAD_COND_T],
};
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
};
}
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
size: [0; __SIZEOF_PTHREAD_MUTEX_T],
};
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
size: [0; __SIZEOF_PTHREAD_COND_T],
};
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
};
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
Expand Down Expand Up @@ -4362,17 +4491,6 @@ cfg_if! {
}
}

cfg_if! {
if #[cfg(libc_align)] {
#[macro_use]
mod align;
} else {
#[macro_use]
mod no_align;
}
}
expand_align!();

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
Expand Down
Loading

0 comments on commit 34af772

Please sign in to comment.