Skip to content

Commit 4ccb290

Browse files
committed
Remove cfg hacks for old MSRV
1 parent 77fb037 commit 4ccb290

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1224
-3072
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exclude = ["/ci/*", "/.github/*", "/.cirrus.yml", "/triagebot.toml"]
1414
description = """
1515
Raw FFI bindings to platform libraries like libc.
1616
"""
17+
rust-version = "1.71.0"
1718

1819
[package.metadata.docs.rs]
1920
features = ["const-extern-fn", "extra_traits"]

README.md

+2-14
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,9 @@ libc = "0.2"
5151

5252
## Rust version support
5353

54-
The minimum supported Rust toolchain version is currently **Rust 1.13.0**.
54+
The minimum supported Rust toolchain version is currently **Rust 1.71.0**
5555
(libc does not currently have any policy regarding changes to the minimum
56-
supported Rust version; such policy is a work in progress.) APIs requiring
57-
newer Rust features are only available on newer Rust toolchains:
58-
59-
| Feature | Version |
60-
|----------------------|---------|
61-
| `union` | 1.19.0 |
62-
| `const mem::size_of` | 1.24.0 |
63-
| `repr(align)` | 1.25.0 |
64-
| `extra_traits` | 1.25.0 |
65-
| `core::ffi::c_void` | 1.30.0 |
66-
| `repr(packed(N))` | 1.33.0 |
67-
| `cfg(target_vendor)` | 1.33.0 |
68-
| `const-extern-fn` | 1.62.0 |
56+
supported Rust version; such policy is a work in progress).
6957

7058
## Platform support
7159

build.rs

+1-88
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
1414
"freebsd13",
1515
"freebsd14",
1616
"freebsd15",
17-
"libc_align",
18-
"libc_cfg_target_vendor",
19-
"libc_const_extern_fn",
20-
"libc_const_extern_fn_unstable",
21-
"libc_const_size_of",
22-
"libc_core_cvoid",
2317
"libc_deny_warnings",
24-
"libc_int128",
25-
"libc_long_array",
26-
"libc_non_exhaustive",
27-
"libc_packedN",
28-
"libc_priv_mod_use",
29-
"libc_ptr_addr_of",
3018
"libc_thread_local",
31-
"libc_underscore_const_names",
32-
"libc_union",
3319
];
3420

3521
// Extra values to allow for check-cfg.
@@ -46,10 +32,8 @@ fn main() {
4632
// Avoid unnecessary re-building.
4733
println!("cargo:rerun-if-changed=build.rs");
4834

49-
let (rustc_minor_ver, is_nightly) = rustc_minor_nightly();
35+
let (rustc_minor_ver, _) = rustc_minor_nightly();
5036
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
51-
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
52-
let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
5337
let libc_ci = env::var("LIBC_CI").is_ok();
5438
let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok();
5539

@@ -86,82 +70,11 @@ fn main() {
8670
set_cfg("libc_deny_warnings");
8771
}
8872

89-
// Rust >= 1.15 supports private module use:
90-
if rustc_minor_ver >= 15 || rustc_dep_of_std {
91-
set_cfg("libc_priv_mod_use");
92-
}
93-
94-
// Rust >= 1.19 supports unions:
95-
if rustc_minor_ver >= 19 || rustc_dep_of_std {
96-
set_cfg("libc_union");
97-
}
98-
99-
// Rust >= 1.24 supports const mem::size_of:
100-
if rustc_minor_ver >= 24 || rustc_dep_of_std {
101-
set_cfg("libc_const_size_of");
102-
}
103-
104-
// Rust >= 1.25 supports repr(align):
105-
if rustc_minor_ver >= 25 || rustc_dep_of_std || align_cargo_feature {
106-
set_cfg("libc_align");
107-
}
108-
109-
// Rust >= 1.26 supports i128 and u128:
110-
if rustc_minor_ver >= 26 || rustc_dep_of_std {
111-
set_cfg("libc_int128");
112-
}
113-
114-
// Rust >= 1.30 supports `core::ffi::c_void`, so libc can just re-export it.
115-
// Otherwise, it defines an incompatible type to retaining
116-
// backwards-compatibility.
117-
if rustc_minor_ver >= 30 || rustc_dep_of_std {
118-
set_cfg("libc_core_cvoid");
119-
}
120-
121-
// Rust >= 1.33 supports repr(packed(N)) and cfg(target_vendor).
122-
if rustc_minor_ver >= 33 || rustc_dep_of_std {
123-
set_cfg("libc_packedN");
124-
set_cfg("libc_cfg_target_vendor");
125-
}
126-
127-
// Rust >= 1.40 supports #[non_exhaustive].
128-
if rustc_minor_ver >= 40 || rustc_dep_of_std {
129-
set_cfg("libc_non_exhaustive");
130-
}
131-
132-
// Rust >= 1.47 supports long array:
133-
if rustc_minor_ver >= 47 || rustc_dep_of_std {
134-
set_cfg("libc_long_array");
135-
}
136-
137-
if rustc_minor_ver >= 51 || rustc_dep_of_std {
138-
set_cfg("libc_ptr_addr_of");
139-
}
140-
141-
// Rust >= 1.37.0 allows underscores as anonymous constant names.
142-
if rustc_minor_ver >= 37 || rustc_dep_of_std {
143-
set_cfg("libc_underscore_const_names");
144-
}
145-
14673
// #[thread_local] is currently unstable
14774
if rustc_dep_of_std {
14875
set_cfg("libc_thread_local");
14976
}
15077

151-
// Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C".
152-
if rustc_minor_ver >= 62 {
153-
set_cfg("libc_const_extern_fn");
154-
} else {
155-
// Rust < 1.62.0 requires a crate feature and feature gate.
156-
if const_extern_fn_cargo_feature {
157-
if !is_nightly || rustc_minor_ver < 40 {
158-
panic!("const-extern-fn requires a nightly compiler >= 1.40");
159-
}
160-
set_cfg("libc_const_extern_fn_unstable");
161-
set_cfg("libc_const_extern_fn");
162-
}
163-
}
164-
16578
// check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the
16679
// codebase. libc can configure it if the appropriate environment variable is passed. Since
16780
// rust-lang/rust enforces it, this is useful when using a custom libc fork there.

libc-test/build.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,7 @@ fn do_ctest() {
6868

6969
fn ctest_cfg() -> ctest::TestGenerator {
7070
let mut cfg = ctest::TestGenerator::new();
71-
let libc_cfgs = [
72-
"libc_priv_mod_use",
73-
"libc_union",
74-
"libc_const_size_of",
75-
"libc_align",
76-
"libc_core_cvoid",
77-
"libc_packedN",
78-
"libc_thread_local",
79-
];
71+
let libc_cfgs = ["libc_thread_local"];
8072
for f in &libc_cfgs {
8173
cfg.cfg(f, None);
8274
}

src/fixed_width_ints.rs

+28-32
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub type uint32_t = u32;
2020
pub type uint64_t = u64;
2121

2222
cfg_if! {
23-
if #[cfg(all(libc_int128, target_arch = "aarch64", not(target_os = "windows")))] {
23+
if #[cfg(all(target_arch = "aarch64", not(target_os = "windows")))] {
2424
// This introduces partial support for FFI with __int128 and
2525
// equivalent types on platforms where Rust's definition is validated
2626
// to match the standard C ABI of that platform.
@@ -59,41 +59,37 @@ cfg_if! {
5959
/// C __uint128_t (alternate name for [__uint128][])
6060
pub type __uint128_t = u128;
6161

62-
cfg_if! {
63-
if #[cfg(libc_underscore_const_names)] {
64-
macro_rules! static_assert_eq {
65-
($a:expr, $b:expr) => {
66-
const _: [(); $a] = [(); $b];
67-
};
68-
}
62+
macro_rules! static_assert_eq {
63+
($a:expr, $b:expr) => {
64+
const _: [(); $a] = [(); $b];
65+
};
66+
}
6967

70-
// NOTE: if you add more platforms to here, you may need to cfg
71-
// these consts. They should always match the platform's values
72-
// for `sizeof(__int128)` and `_Alignof(__int128)`.
73-
const _SIZE_128: usize = 16;
74-
const _ALIGN_128: usize = 16;
68+
// NOTE: if you add more platforms to here, you may need to cfg
69+
// these consts. They should always match the platform's values
70+
// for `sizeof(__int128)` and `_Alignof(__int128)`.
71+
const _SIZE_128: usize = 16;
72+
const _ALIGN_128: usize = 16;
7573

76-
// Since Rust doesn't officially guarantee that these types
77-
// have compatible ABIs, we const assert that these values have the
78-
// known size/align of the target platform's libc. If rustc ever
79-
// tries to regress things, it will cause a compilation error.
80-
//
81-
// This isn't a bullet-proof solution because e.g. it doesn't
82-
// catch the fact that llvm and gcc disagree on how x64 __int128
83-
// is actually *passed* on the stack (clang underaligns it for
84-
// the same reason that rustc *never* properly aligns it).
85-
static_assert_eq!(core::mem::size_of::<__int128>(), _SIZE_128);
86-
static_assert_eq!(core::mem::align_of::<__int128>(), _ALIGN_128);
74+
// Since Rust doesn't officially guarantee that these types
75+
// have compatible ABIs, we const assert that these values have the
76+
// known size/align of the target platform's libc. If rustc ever
77+
// tries to regress things, it will cause a compilation error.
78+
//
79+
// This isn't a bullet-proof solution because e.g. it doesn't
80+
// catch the fact that llvm and gcc disagree on how x64 __int128
81+
// is actually *passed* on the stack (clang underaligns it for
82+
// the same reason that rustc *never* properly aligns it).
83+
static_assert_eq!(core::mem::size_of::<__int128>(), _SIZE_128);
84+
static_assert_eq!(core::mem::align_of::<__int128>(), _ALIGN_128);
8785

88-
static_assert_eq!(core::mem::size_of::<__uint128>(), _SIZE_128);
89-
static_assert_eq!(core::mem::align_of::<__uint128>(), _ALIGN_128);
86+
static_assert_eq!(core::mem::size_of::<__uint128>(), _SIZE_128);
87+
static_assert_eq!(core::mem::align_of::<__uint128>(), _ALIGN_128);
9088

91-
static_assert_eq!(core::mem::size_of::<__int128_t>(), _SIZE_128);
92-
static_assert_eq!(core::mem::align_of::<__int128_t>(), _ALIGN_128);
89+
static_assert_eq!(core::mem::size_of::<__int128_t>(), _SIZE_128);
90+
static_assert_eq!(core::mem::align_of::<__int128_t>(), _ALIGN_128);
9391

94-
static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
95-
static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
96-
}
97-
}
92+
static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
93+
static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
9894
}
9995
}

src/fuchsia/mod.rs

+13-39
Original file line numberDiff line numberDiff line change
@@ -2315,17 +2315,15 @@ pub const RTLD_NOW: ::c_int = 0x2;
23152315

23162316
pub const TCP_MD5SIG: ::c_int = 14;
23172317

2318-
align_const! {
2319-
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
2320-
size: [0; __SIZEOF_PTHREAD_MUTEX_T],
2321-
};
2322-
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
2323-
size: [0; __SIZEOF_PTHREAD_COND_T],
2324-
};
2325-
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
2326-
size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
2327-
};
2328-
}
2318+
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
2319+
size: [0; __SIZEOF_PTHREAD_MUTEX_T],
2320+
};
2321+
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
2322+
size: [0; __SIZEOF_PTHREAD_COND_T],
2323+
};
2324+
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
2325+
size: [0; __SIZEOF_PTHREAD_RWLOCK_T],
2326+
};
23292327
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
23302328
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
23312329
pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 2;
@@ -4361,33 +4359,9 @@ cfg_if! {
43614359
}
43624360
}
43634361

4364-
cfg_if! {
4365-
if #[cfg(libc_align)] {
4366-
#[macro_use]
4367-
mod align;
4368-
} else {
4369-
#[macro_use]
4370-
mod no_align;
4371-
}
4372-
}
4362+
#[macro_use]
4363+
mod align;
4364+
43734365
expand_align!();
43744366

4375-
cfg_if! {
4376-
if #[cfg(libc_core_cvoid)] {
4377-
pub use ::ffi::c_void;
4378-
} else {
4379-
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
4380-
// enable more optimization opportunities around it recognizing things
4381-
// like malloc/free.
4382-
#[repr(u8)]
4383-
#[allow(missing_copy_implementations)]
4384-
#[allow(missing_debug_implementations)]
4385-
pub enum c_void {
4386-
// Two dummy variants so the #[repr] attribute can be used.
4387-
#[doc(hidden)]
4388-
__variant1,
4389-
#[doc(hidden)]
4390-
__variant2,
4391-
}
4392-
}
4393-
}
4367+
pub use ffi::c_void;

0 commit comments

Comments
 (0)