Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove most version detection and conditionals for older versions of Rust #2845

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/workflows/bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ jobs:
stable,
beta,
nightly,
1.13.0,
1.19.0,
1.24.0,
1.25.0,
1.30.0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there still be CI for the remaining MSRV? And maybe also the further version steps that are still detected in the build script -- just 1.51?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cuviper I don't think we need the latter, but yes, I'll add 1.47 there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon me for unresolving, but AFAICT you haven't added 1.47 to CI yet.

]
steps:
- uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
Expand All @@ -234,11 +229,6 @@ jobs:
stable,
beta,
nightly,
1.13.0,
1.19.0,
1.24.0,
1.25.0,
1.30.0,
]
steps:
- uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
Expand All @@ -259,10 +249,6 @@ jobs:
fail-fast: true
matrix:
toolchain: [
1.19.0,
1.24.0,
1.25.0,
1.30.0,
stable,
]
steps:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude = ["/ci/*", "/.github/*", "/.cirrus.yml", "/triagebot.toml"]
description = """
Raw FFI bindings to platform libraries like libc.
"""
rust-version = "1.47"

[package.metadata.docs.rs]
features = ["const-extern-fn", "extra_traits"]
Expand All @@ -25,7 +26,7 @@ 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 = ['rustc-std-workspace-core']
extra_traits = []
const-extern-fn = []
# use_std is deprecated, use `std` instead
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,18 @@ libc = "0.2"

* **deprecated**: `use_std` is deprecated, and is equivalent to `std`.

* **deprecated**: `align` is deprecated (and always enabled).

## Rust version support

The minimum supported Rust toolchain version is currently **Rust 1.13.0**.
The minimum supported Rust toolchain version is currently **Rust 1.47.0** .
(libc does not currently have any policy regarding changes to the minimum
supported Rust version; such policy is a work in progress.) APIs requiring
newer Rust features are only available on newer Rust toolchains:

| Feature | Version |
|----------------------|---------|
| `union` | 1.19.0 |
| `const mem::size_of` | 1.24.0 |
| `repr(align)` | 1.25.0 |
| `extra_traits` | 1.25.0 |
| `core::ffi::c_void` | 1.30.0 |
| `repr(packed(N))` | 1.33.0 |
| `cfg(target_vendor)` | 1.33.0 |
| `const-extern-fn` | 1.62.0 |
| Feature | Version |
|-----------------------|---------|
| `const-extern-fn` | 1.62.0 |

## Platform support

Expand Down
56 changes: 0 additions & 56 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ fn main() {

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();
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() {
println!(
"cargo:warning=\"libc's use_std cargo feature is deprecated since libc 0.2.55; \
please consider using the `std` cargo feature instead\""
);
}

// 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.
//
Expand All @@ -40,58 +32,10 @@ fn main() {
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");
}

// 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.26 supports i128 and u128:
if rustc_minor_ver >= 26 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_int128");
}

// 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)) and cfg(target_vendor).
if rustc_minor_ver >= 33 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_packedN");
println!("cargo:rustc-cfg=libc_cfg_target_vendor");
}

// Rust >= 1.40 supports #[non_exhaustive].
if rustc_minor_ver >= 40 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_non_exhaustive");
}

if rustc_minor_ver >= 51 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_ptr_addr_of");
}

// Rust >= 1.37.0 allows underscores as anonymous constant names.
if rustc_minor_ver >= 37 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_underscore_const_names");
}

// #[thread_local] is currently unstable
if rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_thread_local");
Expand Down
17 changes: 0 additions & 17 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,15 @@ x86_64-unknown-freebsd \
x86_64-unknown-linux-gnu \
x86_64-unknown-linux-musl \
x86_64-unknown-netbsd \
"

RUST_GT_1_13_LINUX_TARGETS="\
arm-unknown-linux-musleabi \
arm-unknown-linux-musleabihf \
armv7-unknown-linux-musleabihf \
sparc64-unknown-linux-gnu \
wasm32-unknown-emscripten \
x86_64-linux-android \
"
RUST_GT_1_19_LINUX_TARGETS="\
aarch64-unknown-linux-musl \
sparcv9-sun-solaris \
wasm32-unknown-unknown \
"
RUST_GT_1_24_LINUX_TARGETS="\
i586-unknown-linux-musl \
"

Expand Down Expand Up @@ -174,16 +167,6 @@ case "${OS}" in
linux*)
TARGETS="${RUST_LINUX_TARGETS}"

if [ "${RUST}" != "1.13.0" ]; then
TARGETS="${TARGETS} ${RUST_GT_1_13_LINUX_TARGETS}"
if [ "${RUST}" != "1.19.0" ]; then
TARGETS="${TARGETS} ${RUST_GT_1_19_LINUX_TARGETS}"
if [ "${RUST}" != "1.24.0" ]; then
TARGETS="${TARGETS} ${RUST_GT_1_24_LINUX_TARGETS}"
fi
fi
fi

if [ "${RUST}" = "nightly" ]; then
TARGETS="${TARGETS} ${RUST_NIGHTLY_LINUX_TARGETS}"
fi
Expand Down
18 changes: 1 addition & 17 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ fn do_ctest() {

fn ctest_cfg() -> ctest::TestGenerator {
let mut cfg = ctest::TestGenerator::new();
let libc_cfgs = [
"libc_priv_mod_use",
"libc_union",
"libc_const_size_of",
"libc_align",
"libc_core_cvoid",
"libc_packedN",
"libc_thread_local",
];
let libc_cfgs = ["libc_thread_local"];
for f in &libc_cfgs {
cfg.cfg(f, None);
}
Expand Down Expand Up @@ -330,8 +322,6 @@ fn test_apple(target: &str) {
// FIXME: the array size has been changed since macOS 10.15 ([8] -> [7]).
("statfs", "f_reserved") => true,
("__darwin_arm_neon_state64", "__v") => true,
// MAXPATHLEN is too big for auto-derive traits on arrays.
("vnode_info_path", "vip_path") => true,
_ => false,
}
});
Expand Down Expand Up @@ -2250,8 +2240,6 @@ fn test_freebsd(target: &str) {
("umutex", "m_owner") => true,
// c_has_waiters field is a volatile int32_t
("ucond", "c_has_waiters") => true,
// is PATH_MAX long but tests can't accept multi array as equivalent.
("kinfo_vmentry", "kve_path") => true,

// a_un field is a union
("Elf32_Auxinfo", "a_un") => true,
Expand Down Expand Up @@ -2280,10 +2268,6 @@ fn test_freebsd(target: &str) {
// Anonymous type.
("filestat", "next") => true,

// We ignore this field because we needed to use a hack in order to make rust 1.19
// happy...
("kinfo_proc", "ki_sparestrings") => true,

// `__sem_base` is a private struct field
("semid_ds", "__sem_base") => true,

Expand Down
60 changes: 28 additions & 32 deletions src/fixed_width_ints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type uint32_t = u32;
pub type uint64_t = u64;

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

cfg_if! {
if #[cfg(libc_underscore_const_names)] {
macro_rules! static_assert_eq {
($a:expr, $b:expr) => {
const _: [(); $a] = [(); $b];
};
}
macro_rules! static_assert_eq {
($a:expr, $b:expr) => {
const _: [(); $a] = [(); $b];
};
}

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

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

static_assert_eq!(core::mem::size_of::<__uint128>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__uint128>(), _ALIGN_128);
static_assert_eq!(core::mem::size_of::<__uint128>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__uint128>(), _ALIGN_128);

static_assert_eq!(core::mem::size_of::<__int128_t>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__int128_t>(), _ALIGN_128);
static_assert_eq!(core::mem::size_of::<__int128_t>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__int128_t>(), _ALIGN_128);

static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
}
}
static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
}
}