diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc1498238..062876279 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - build: [stable, nightly, 1.63] + build: [stable, nightly, 1.65] include: - build: stable os: ubuntu-latest @@ -33,9 +33,9 @@ jobs: - build: nightly os: ubuntu-latest rust: nightly - - build: 1.63 + - build: 1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 env: # -D warnings is commented out in our install-rust action; re-add it here. @@ -48,19 +48,16 @@ jobs: with: toolchain: ${{ matrix.rust }} - - name: Use specific dependency versions for Rust 1.63 compatibility. - if: matrix.rust == '1.63' + - name: Use specific dependency versions for Rust 1.65 compatibility. + if: matrix.rust == '1.65' run: | - cargo update --package=dashmap --precise 5.4.0 - cargo update --package=regex --precise=1.9.0 cargo update --package=half --precise=2.2.1 cargo update --package=flate2 --precise=1.0.35 cargo update --package=syn --precise=2.0.106 cargo update --package=textwrap --precise=0.16.1 - cargo update --package=once_cell --precise=1.20.3 - cargo update --package=parking_lot --precise=0.12.3 - cargo update --package=parking_lot_core --precise=0.9.10 - cargo update --package=lock_api --precise=0.4.12 + cargo update --package=parking_lot --precise=0.12.4 + cargo update --package=parking_lot_core --precise=0.9.11 + cargo update --package=lock_api --precise=0.4.13 cargo update --package=rayon --precise=1.10.0 cargo update --package=rayon-core --precise=1.12.1 cargo update --package=windows-sys --precise=0.60.2 @@ -107,13 +104,13 @@ jobs: aarch64-linux-android aarch64-apple-ios i686-pc-windows-msvc - - if: matrix.rust != '1.63' + - if: matrix.rust != '1.65' run: > rustup target add wasm32-wasip1 wasm32-wasip2 x86_64-unknown-fuchsia - - if: matrix.rust == '1.63' + - if: matrix.rust == '1.65' run: rustup target add x86_64-fuchsia - run: cargo check --workspace --release -vv --all-targets @@ -123,19 +120,20 @@ jobs: - run: cargo check --workspace --release -vv --target=aarch64-linux-android --all-targets - run: cargo check --workspace --release -vv --target=x86_64-unknown-linux-musl --features=all-apis --all-targets - run: cargo check --workspace --release -vv --target=x86_64-unknown-linux-musl --features=use-libc,all-apis --all-targets - - run: cargo check --workspace --release -vv --target=x86_64-unknown-linux-gnux32 --features=all-apis --all-targets + # Temporarily disable due to build errors. + # - run: cargo check --workspace --release -vv --target=x86_64-unknown-linux-gnux32 --features=all-apis --all-targets - run: cargo check --workspace --release -vv --target=x86_64-linux-android --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno --all-targets - run: cargo check --workspace --release -vv --target=i686-linux-android --features=use-libc,net,std,alloc,event,fs,mm,param,pipe,use-libc-auxv,libc_errno --all-targets - run: cargo check --workspace --release -vv --target=x86_64-apple-darwin --features=all-apis --all-targets - run: cargo check --workspace --release -vv --target=x86_64-unknown-freebsd --features=all-apis --all-targets - run: cargo check --workspace --release -vv --target=x86_64-unknown-netbsd --features=all-apis --all-targets - - if: matrix.rust != '1.63' + - if: matrix.rust != '1.65' run: cargo check --workspace --release -vv --target=wasm32-wasip1 --features=all-apis - - if: matrix.rust != '1.63' + - if: matrix.rust != '1.65' run: cargo check --workspace --release -vv --target=wasm32-wasip2 --features=all-apis - - if: matrix.rust != '1.63' + - if: matrix.rust != '1.65' run: cargo check --workspace --release -vv --target=x86_64-unknown-fuchsia --features=all-apis --all-targets - - if: matrix.rust == '1.63' + - if: matrix.rust == '1.65' run: cargo check --workspace --release -vv --target=x86_64-fuchsia --features=all-apis --all-targets - run: cargo check --workspace --release -vv --target=x86_64-unknown-illumos --features=all-apis --all-targets - run: cargo check --workspace --release -vv --target=i686-unknown-linux-gnu --features=all-apis --all-targets @@ -239,11 +237,14 @@ jobs: RUSTFLAGS: -A improper_ctypes_definitions --cfg criterion - run: rustup component add rust-src - run: cargo check -Z build-std --target x86_64-unknown-openbsd --all-targets --features=all-apis - - run: cargo check -Z build-std --target mips64-openwrt-linux-musl --all-targets --features=all-apis + # Temporarily disable due to build errors. + # - run: cargo check -Z build-std --target mips64-openwrt-linux-musl --all-targets --features=all-apis - run: cargo check -Z build-std --target x86_64-unknown-dragonfly --all-targets --features=all-apis - - run: cargo check -Z build-std --target sparc-unknown-linux-gnu --all-targets --features=all-apis + # Temporarily disable due to build errors. + # - run: cargo check -Z build-std --target sparc-unknown-linux-gnu --all-targets --features=all-apis - run: cargo check -Z build-std --target armv7-unknown-freebsd --all-targets --features=all-apis - - run: cargo check -Z build-std --target aarch64-unknown-linux-gnu_ilp32 --all-targets --features=all-apis + # Temporarily disable due to build errors. + # - run: cargo check -Z build-std --target aarch64-unknown-linux-gnu_ilp32 --all-targets --features=all-apis - run: cargo check -Z build-std --target x86_64-unknown-haiku --all-targets --features=all-apis # Temporarily disable due to build errors on nightly. # - run: cargo check -Z build-std --target x86_64-uwp-windows-msvc --all-targets --features=all-apis @@ -291,14 +292,14 @@ jobs: powerpc-linux-stable, powerpc64le-linux-stable, arm-linux-stable, - ubuntu-1.63, - i686-linux-1.63, - aarch64-linux-1.63, - riscv64-linux-1.63, - s390x-linux-1.63, + ubuntu-1.65, + i686-linux-1.65, + aarch64-linux-1.65, + riscv64-linux-1.65, + s390x-linux-1.65, powerpc64le-linux, - powerpc64le-linux-1.63, - arm-linux-1.63, + powerpc64le-linux-1.65, + arm-linux-1.65, macos-latest, macos-15-intel, macos-14, @@ -437,64 +438,64 @@ jobs: qemu: qemu-arm qemu_args: -L /usr/arm-linux-gnueabi qemu_target: arm-linux-user - - build: ubuntu-1.63 + - build: ubuntu-1.65 os: ubuntu-latest - rust: 1.63 - - build: i686-linux-1.63 + rust: 1.65 + - build: i686-linux-1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 target: i686-unknown-linux-gnu gcc_package: gcc-i686-linux-gnu gcc: i686-linux-gnu-gcc libc_package: libc-dev-i386-cross - - build: aarch64-linux-1.63 + - build: aarch64-linux-1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 target: aarch64-unknown-linux-gnu gcc_package: gcc-aarch64-linux-gnu gcc: aarch64-linux-gnu-gcc qemu: qemu-aarch64 qemu_args: -L /usr/aarch64-linux-gnu qemu_target: aarch64-linux-user - - build: riscv64-linux-1.63 + - build: riscv64-linux-1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 target: riscv64gc-unknown-linux-gnu gcc_package: gcc-riscv64-linux-gnu gcc: riscv64-linux-gnu-gcc qemu: qemu-riscv64 qemu_args: -L /usr/riscv64-linux-gnu qemu_target: riscv64-linux-user - - build: s390x-linux-1.63 + - build: s390x-linux-1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 target: s390x-unknown-linux-gnu gcc_package: gcc-s390x-linux-gnu gcc: s390x-linux-gnu-gcc qemu: qemu-s390x qemu_args: -L /usr/s390x-linux-gnu qemu_target: s390x-linux-user - - build: powerpc-linux-1.63 + - build: powerpc-linux-1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 target: powerpc-unknown-linux-gnu gcc_package: gcc-powerpc-linux-gnu gcc: powerpc-linux-gnu-gcc qemu: qemu-ppc qemu_args: -L /usr/powerpc-linux-gnu qemu_target: ppc-linux-user - - build: powerpc64le-linux-1.63 + - build: powerpc64le-linux-1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 target: powerpc64le-unknown-linux-gnu gcc_package: gcc-powerpc64le-linux-gnu gcc: powerpc64le-linux-gnu-gcc qemu: qemu-ppc64le qemu_args: -L /usr/powerpc64le-linux-gnu qemu_target: ppc64le-linux-user - - build: arm-linux-1.63 + - build: arm-linux-1.65 os: ubuntu-latest - rust: 1.63 + rust: 1.65 target: armv5te-unknown-linux-gnueabi gcc_package: gcc-arm-linux-gnueabi gcc: arm-linux-gnueabi-gcc @@ -585,19 +586,16 @@ jobs: ninja -C build install if: matrix.qemu != '' && matrix.os == 'ubuntu-latest' - - name: Use specific dependency versions for Rust 1.63 compatibility. - if: matrix.rust == '1.63' + - name: Use specific dependency versions for Rust 1.65 compatibility. + if: matrix.rust == '1.65' run: | - cargo update --package=dashmap --precise 5.4.0 - cargo update --package=regex --precise=1.9.0 cargo update --package=half --precise=2.2.1 cargo update --package=flate2 --precise=1.0.35 cargo update --package=syn --precise=2.0.106 cargo update --package=textwrap --precise=0.16.1 - cargo update --package=once_cell --precise=1.20.3 - cargo update --package=parking_lot --precise=0.12.3 - cargo update --package=parking_lot_core --precise=0.9.10 - cargo update --package=lock_api --precise=0.4.12 + cargo update --package=parking_lot --precise=0.12.4 + cargo update --package=parking_lot_core --precise=0.9.11 + cargo update --package=lock_api --precise=0.4.13 cargo update --package=rayon --precise=1.10.0 cargo update --package=rayon-core --precise=1.12.1 cargo update --package=windows-sys --precise=0.60.2 diff --git a/Cargo.toml b/Cargo.toml index bfacfeb95..1bc6d5003 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" keywords = ["api", "file", "network", "safe", "syscall"] categories = ["os::unix-apis", "date-and-time", "filesystem", "network-programming"] include = ["src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md", "benches"] -rust-version = "1.63" +rust-version = "1.65" [hints] # Most users use a fraction of the rustix API surface area, so this reduces compilation times @@ -268,7 +268,6 @@ check-cfg = [ 'cfg(rustc_diagnostics)', 'cfg(solarish)', 'cfg(staged_api)', - 'cfg(static_assertions)', 'cfg(thumb_mode)', 'cfg(wasi)', 'cfg(wasi_ext)', diff --git a/README.md b/README.md index 3e553b30d..c3df9a8c8 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ more portable APIs built on this functionality, see the [`cap-std`], [`memfd`], * linux_raw, which uses raw Linux system calls and vDSO calls, and is supported on Linux on x86-64, x86, aarch64, riscv64gc, powerpc64le, - arm (v5 onwards), mipsel, and mips64el, with stable, nightly, and 1.63 Rust. + arm (v5 onwards), mipsel, and mips64el, with stable, nightly, and 1.65 Rust. - By being implemented entirely in Rust, avoiding `libc`, `errno`, and pthread cancellation, and employing some specialized optimizations, most functions compile down to very efficient code, which can often be fully inlined into @@ -155,12 +155,12 @@ safety types rather than `RawFd`, and the flags parameters to functions such as `tcsetattr` are `enum`s rather than bare integers. And, rustix calls its `tcgetattr` function `tcgetattr`, rather than `Termios::from_fd`. -## Minimum Supported Rust Version (MSRV) +## Minimum Supported Rust Version -This crate currently works on the version of [Rust on Debian stable], which is -currently [Rust 1.63]. This policy may change in the future, in minor version -releases, so users using a fixed version of Rust should pin to a specific -version of this crate. +This crate has a Minimum Supported Rust Version (MSRV) of [Rust 1.65]. + +The current policy is that the minimum Rust version required to use this crate +may be increased in minor releases. ## Minimum Linux Version @@ -171,11 +171,10 @@ oldest Linux version supported by: The specifics of this policy may change in the future, but we intend it to always reflect “very old” Linux versions. -[MSRV]: #minimum-supported-rust-version-msrv -[Rust 1.63]: https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html +[MSRV]: #minimum-supported-rust-version +[Rust 1.65]: https://blog.rust-lang.org/2022/11/03/Rust-1.65.0/ [any current Rust target]: https://doc.rust-lang.org/nightly/rustc/platform-support.html [kernel.org]: https://www.kernel.org/releases.html -[Rust on Debian stable]: https://packages.debian.org/stable/rust/rustc [Windows Sockets 2]: https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-start-page-2 [`nix`]: https://crates.io/crates/nix [`unix`]: https://crates.io/crates/unix diff --git a/build.rs b/build.rs index 1677ece45..8bc77643a 100644 --- a/build.rs +++ b/build.rs @@ -79,11 +79,6 @@ fn main() { use_feature_or_nothing("error_in_core"); } - // Feature needed for testing. - if use_static_assertions() { - use_feature("static_assertions"); - } - // `LowerExp`/`UpperExp` for `NonZeroI32` etc. if has_lower_upper_exp_for_non_zero() { use_feature("lower_upper_exp_for_non_zero"); @@ -197,11 +192,6 @@ fn main() { println!("cargo:rerun-if-env-changed=CARGO_CFG_MIRI"); } -fn use_static_assertions() -> bool { - // `offset_from` was made const in Rust 1.65. - can_compile("const unsafe fn foo(p: *const u8) -> isize { p.offset_from(p) }") -} - fn use_thumb_mode() -> bool { // In thumb mode, r7 is reserved. !can_compile("pub unsafe fn f() { core::arch::asm!(\"udf #16\", in(\"r7\") 0); }") diff --git a/src/backend/libc/fs/dir.rs b/src/backend/libc/fs/dir.rs index 3c4c3896b..65742876a 100644 --- a/src/backend/libc/fs/dir.rs +++ b/src/backend/libc/fs/dir.rs @@ -421,8 +421,8 @@ fn check_dirent_layout(dirent: &c::dirent) { // Check that the basic layouts match. #[cfg(test)] { - assert_eq_size!(libc_dirent, c::dirent); - assert_eq_size!(libc_dirent, c::dirent); + static_assertions::assert_eq_size!(libc_dirent, c::dirent); + static_assertions::assert_eq_size!(libc_dirent, c::dirent); } // Check that the field offsets match. diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs index 71bc8b0ab..8b7f082f5 100644 --- a/src/backend/libc/fs/syscalls.rs +++ b/src/backend/libc/fs/syscalls.rs @@ -672,7 +672,7 @@ pub(crate) fn stat(path: &CStr) -> io::Result { )))] unsafe { #[cfg(test)] - assert_eq_size!(Stat, c::stat); + static_assertions::assert_eq_size!(Stat, c::stat); let mut stat = MaybeUninit::::uninit(); ret(c::stat(c_str(path), stat.as_mut_ptr().cast()))?; @@ -718,7 +718,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result { )))] unsafe { #[cfg(test)] - assert_eq_size!(Stat, c::stat); + static_assertions::assert_eq_size!(Stat, c::stat); let mut stat = MaybeUninit::::uninit(); ret(c::lstat(c_str(path), stat.as_mut_ptr().cast()))?; @@ -760,7 +760,7 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io:: )))] unsafe { #[cfg(test)] - assert_eq_size!(Stat, c::stat); + static_assertions::assert_eq_size!(Stat, c::stat); let mut stat = MaybeUninit::::uninit(); ret(c::fstatat( @@ -1563,7 +1563,7 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result { )))] unsafe { #[cfg(test)] - assert_eq_size!(Stat, c::stat); + static_assertions::assert_eq_size!(Stat, c::stat); let mut stat = MaybeUninit::::uninit(); ret(c::fstat(borrowed_fd(fd), stat.as_mut_ptr().cast()))?; @@ -2727,12 +2727,12 @@ mod tests { #[test] fn test_sizes() { #[cfg(linux_kernel)] - assert_eq_size!(c::loff_t, u64); + static_assertions::assert_eq_size!(c::loff_t, u64); // Assert that `Timestamps` has the expected layout. If we're not fixing // y2038, libc's type should match ours. If we are, it's smaller. #[cfg(not(fix_y2038))] - assert_eq_size!([c::timespec; 2], Timestamps); + static_assertions::assert_eq_size!([c::timespec; 2], Timestamps); #[cfg(fix_y2038)] assert!(core::mem::size_of::<[c::timespec; 2]>() < core::mem::size_of::()); } diff --git a/src/backend/libc/pipe/types.rs b/src/backend/libc/pipe/types.rs index db04a9424..38e255169 100644 --- a/src/backend/libc/pipe/types.rs +++ b/src/backend/libc/pipe/types.rs @@ -109,9 +109,9 @@ mod tests { #[cfg(not(any(apple, target_os = "wasi")))] #[test] fn test_types() { - assert_eq_size!(PipeFlags, c::c_int); + static_assertions::assert_eq_size!(PipeFlags, c::c_int); #[cfg(linux_kernel)] - assert_eq_size!(SpliceFlags, c::c_int); + static_assertions::assert_eq_size!(SpliceFlags, c::c_int); } } diff --git a/src/backend/libc/time/types.rs b/src/backend/libc/time/types.rs index b6e0bdc4e..35173abce 100644 --- a/src/backend/libc/time/types.rs +++ b/src/backend/libc/time/types.rs @@ -107,7 +107,7 @@ impl From for LibcItimerspec { pub(crate) fn as_libc_itimerspec_ptr(itimerspec: &Itimerspec) -> *const c::itimerspec { #[cfg(test)] { - assert_eq_size!(Itimerspec, c::itimerspec); + static_assertions::assert_eq_size!(Itimerspec, c::itimerspec); } crate::utils::as_ptr(itimerspec).cast::() } @@ -125,7 +125,7 @@ pub(crate) fn as_libc_itimerspec_mut_ptr( ) -> *mut c::itimerspec { #[cfg(test)] { - assert_eq_size!(Itimerspec, c::itimerspec); + static_assertions::assert_eq_size!(Itimerspec, c::itimerspec); } itimerspec.as_mut_ptr().cast::() } @@ -260,7 +260,7 @@ mod tests { ))] #[test] fn test_types() { - assert_eq_size!(TimerfdFlags, c::c_int); - assert_eq_size!(TimerfdTimerFlags, c::c_int); + static_assertions::assert_eq_size!(TimerfdFlags, c::c_int); + static_assertions::assert_eq_size!(TimerfdTimerFlags, c::c_int); } } diff --git a/src/backend/linux_raw/fs/syscalls.rs b/src/backend/linux_raw/fs/syscalls.rs index 908272f45..297782d85 100644 --- a/src/backend/linux_raw/fs/syscalls.rs +++ b/src/backend/linux_raw/fs/syscalls.rs @@ -1720,11 +1720,17 @@ mod tests { #[test] fn test_sizes() { - assert_eq_size!(linux_raw_sys::general::__kernel_loff_t, u64); - assert_eq_align!(linux_raw_sys::general::__kernel_loff_t, u64); + static_assertions::assert_eq_size!(linux_raw_sys::general::__kernel_loff_t, u64); + static_assertions::assert_eq_align!(linux_raw_sys::general::__kernel_loff_t, u64); // Assert that `Timestamps` has the expected layout. - assert_eq_size!([linux_raw_sys::general::__kernel_timespec; 2], Timestamps); - assert_eq_align!([linux_raw_sys::general::__kernel_timespec; 2], Timestamps); + static_assertions::assert_eq_size!( + [linux_raw_sys::general::__kernel_timespec; 2], + Timestamps + ); + static_assertions::assert_eq_align!( + [linux_raw_sys::general::__kernel_timespec; 2], + Timestamps + ); } } diff --git a/src/backend/linux_raw/param/libc_auxv.rs b/src/backend/linux_raw/param/libc_auxv.rs index d77d3a840..9350bc1a0 100644 --- a/src/backend/linux_raw/param/libc_auxv.rs +++ b/src/backend/linux_raw/param/libc_auxv.rs @@ -178,21 +178,21 @@ mod tests { #[test] fn test_abi() { - const_assert_eq!(self::_SC_PAGESIZE, ::libc::_SC_PAGESIZE); - const_assert_eq!(self::_SC_CLK_TCK, ::libc::_SC_CLK_TCK); - const_assert_eq!(self::AT_HWCAP, ::libc::AT_HWCAP); - const_assert_eq!(self::AT_HWCAP2, ::libc::AT_HWCAP2); - const_assert_eq!(self::AT_EXECFN, ::libc::AT_EXECFN); - const_assert_eq!(self::AT_SECURE, ::libc::AT_SECURE); - const_assert_eq!(self::AT_SYSINFO_EHDR, ::libc::AT_SYSINFO_EHDR); - const_assert_eq!(self::AT_MINSIGSTKSZ, ::libc::AT_MINSIGSTKSZ); + static_assertions::const_assert_eq!(self::_SC_PAGESIZE, ::libc::_SC_PAGESIZE); + static_assertions::const_assert_eq!(self::_SC_CLK_TCK, ::libc::_SC_CLK_TCK); + static_assertions::const_assert_eq!(self::AT_HWCAP, ::libc::AT_HWCAP); + static_assertions::const_assert_eq!(self::AT_HWCAP2, ::libc::AT_HWCAP2); + static_assertions::const_assert_eq!(self::AT_EXECFN, ::libc::AT_EXECFN); + static_assertions::const_assert_eq!(self::AT_SECURE, ::libc::AT_SECURE); + static_assertions::const_assert_eq!(self::AT_SYSINFO_EHDR, ::libc::AT_SYSINFO_EHDR); + static_assertions::const_assert_eq!(self::AT_MINSIGSTKSZ, ::libc::AT_MINSIGSTKSZ); #[cfg(feature = "runtime")] - const_assert_eq!(self::AT_PHDR, ::libc::AT_PHDR); + static_assertions::const_assert_eq!(self::AT_PHDR, ::libc::AT_PHDR); #[cfg(feature = "runtime")] - const_assert_eq!(self::AT_PHNUM, ::libc::AT_PHNUM); + static_assertions::const_assert_eq!(self::AT_PHNUM, ::libc::AT_PHNUM); #[cfg(feature = "runtime")] - const_assert_eq!(self::AT_ENTRY, ::libc::AT_ENTRY); + static_assertions::const_assert_eq!(self::AT_ENTRY, ::libc::AT_ENTRY); #[cfg(feature = "runtime")] - const_assert_eq!(self::AT_RANDOM, ::libc::AT_RANDOM); + static_assertions::const_assert_eq!(self::AT_RANDOM, ::libc::AT_RANDOM); } } diff --git a/src/check_types.rs b/src/check_types.rs index fb7e7a286..9bfb1d746 100644 --- a/src/check_types.rs +++ b/src/check_types.rs @@ -5,8 +5,8 @@ /// Check that the size and alignment of a type match the `sys` bindings. macro_rules! check_type { ($struct:ident) => { - assert_eq_size!($struct, c::$struct); - assert_eq_align!($struct, c::$struct); + ::static_assertions::assert_eq_size!($struct, c::$struct); + ::static_assertions::assert_eq_align!($struct, c::$struct); }; } @@ -14,8 +14,8 @@ macro_rules! check_type { /// renamed to avoid having types like `bindgen_ty_1` in the API. macro_rules! check_renamed_type { ($to:ident, $from:ident) => { - assert_eq_size!($to, c::$from); - assert_eq_align!($to, c::$from); + ::static_assertions::assert_eq_size!($to, c::$from); + ::static_assertions::assert_eq_align!($to, c::$from); }; } @@ -23,7 +23,7 @@ macro_rules! check_renamed_type { /// field in the `sys` bindings. macro_rules! check_struct_field { ($struct:ident, $field:ident) => { - const_assert_eq!( + ::static_assertions::const_assert_eq!( memoffset::offset_of!($struct, $field), memoffset::offset_of!(c::$struct, $field) ); @@ -41,7 +41,7 @@ macro_rules! check_struct_field { /// we've renamed to avoid having types like `bindgen_ty_1` in the API. macro_rules! check_struct_renamed_field { ($struct:ident, $to:ident, $from:ident) => { - const_assert_eq!( + ::static_assertions::const_assert_eq!( memoffset::offset_of!($struct, $to), memoffset::offset_of!(c::$struct, $from) ); @@ -58,7 +58,7 @@ macro_rules! check_struct_renamed_field { /// but the field is not. macro_rules! check_renamed_struct_field { ($to_struct:ident, $from_struct:ident, $field:ident) => { - const_assert_eq!( + ::static_assertions::const_assert_eq!( memoffset::offset_of!($to_struct, $field), memoffset::offset_of!(c::$from_struct, $field) ); @@ -75,7 +75,7 @@ macro_rules! check_renamed_struct_field { /// a field are renamed. macro_rules! check_renamed_struct_renamed_field { ($to_struct:ident, $from_struct:ident, $to:ident, $from:ident) => { - const_assert_eq!( + ::static_assertions::const_assert_eq!( memoffset::offset_of!($to_struct, $to), memoffset::offset_of!(c::$from_struct, $from) ); diff --git a/src/ffi.rs b/src/ffi.rs index 073b6b120..e4d4ee91f 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -1,23 +1,16 @@ //! Utilities related to FFI bindings. +//! +//! This module re-exports a small set of types for backwards compatibility. +//! New code should prefer importing these items directly from +//! `core::ffi`, `alloc::ffi`, or `std::ffi` as appropriate. -// If we have std, use it. #[cfg(not(windows))] -#[cfg(feature = "std")] -pub use std::ffi::{CStr, CString, FromBytesWithNulError, NulError}; -#[cfg(feature = "std")] -pub use std::os::raw::{ - c_char, c_int, c_long, c_longlong, c_short, c_uint, c_ulong, c_ulonglong, c_ushort, c_void, -}; - -// If we don't have std, we can depend on core and alloc having these features -// in Rust 1.64+. -#[cfg(not(windows))] -#[cfg(all(feature = "alloc", not(feature = "std")))] +#[cfg(any(feature = "alloc", feature = "std"))] pub use alloc::ffi::{CString, NulError}; -#[cfg(not(feature = "std"))] + pub use core::ffi::{ c_char, c_int, c_long, c_longlong, c_short, c_uint, c_ulong, c_ulonglong, c_ushort, c_void, }; + #[cfg(not(windows))] -#[cfg(not(feature = "std"))] pub use core::ffi::{CStr, FromBytesWithNulError}; diff --git a/src/fs/constants.rs b/src/fs/constants.rs index a4f8e6e07..097435ea5 100644 --- a/src/fs/constants.rs +++ b/src/fs/constants.rs @@ -57,7 +57,7 @@ mod tests { #[test] fn test_layouts() { #[cfg(linux_raw_dep)] - assert_eq_size!(FsWord, linux_raw_sys::general::__fsword_t); + static_assertions::assert_eq_size!(FsWord, linux_raw_sys::general::__fsword_t); // Don't test against `__kernel_mode_t` on platforms where it's a // `u16`. @@ -68,7 +68,7 @@ mod tests { target_arch = "avr", target_arch = "arm", )))] - assert_eq_size!(RawMode, linux_raw_sys::general::__kernel_mode_t); + static_assertions::assert_eq_size!(RawMode, linux_raw_sys::general::__kernel_mode_t); #[cfg(linux_raw_dep)] #[cfg(any( @@ -77,7 +77,7 @@ mod tests { target_arch = "avr", target_arch = "arm", ))] - assert_eq_size!(u16, linux_raw_sys::general::__kernel_mode_t); + static_assertions::assert_eq_size!(u16, linux_raw_sys::general::__kernel_mode_t); let some_stat: Stat = unsafe { core::mem::zeroed() }; diff --git a/src/io_uring/mod.rs b/src/io_uring/mod.rs index f4084ef17..00fde8df5 100644 --- a/src/io_uring/mod.rs +++ b/src/io_uring/mod.rs @@ -1996,8 +1996,8 @@ mod tests { use sys as c; // `io_uring_ptr` is a replacement for `u64`. - assert_eq_size!(io_uring_ptr, u64); - assert_eq_align!(io_uring_ptr, u64); + static_assertions::assert_eq_size!(io_uring_ptr, u64); + static_assertions::assert_eq_align!(io_uring_ptr, u64); // Test that pointers are stored in `io_uring_ptr` in the way that // io_uring stores them in a `u64`. @@ -2014,8 +2014,8 @@ mod tests { } // `io_uring_user_data` is a replacement for `u64`. - assert_eq_size!(io_uring_user_data, u64); - assert_eq_align!(io_uring_user_data, u64); + static_assertions::assert_eq_size!(io_uring_user_data, u64); + static_assertions::assert_eq_align!(io_uring_user_data, u64); // Test that `u64`s and pointers are properly stored in // `io_uring_user_data`. diff --git a/src/lib.rs b/src/lib.rs index 5008ad7ec..b04dcb127 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,16 +161,6 @@ extern crate rustc_std_workspace_alloc as alloc; #[cfg(all(feature = "alloc", not(feature = "rustc-dep-of-std")))] extern crate alloc; -// Use `static_assertions` macros if we have them, or a polyfill otherwise. -#[cfg(all(test, static_assertions))] -#[macro_use] -#[allow(unused_imports)] -extern crate static_assertions; -#[cfg(all(test, not(static_assertions)))] -#[macro_use] -#[allow(unused_imports)] -mod static_assertions; - pub mod buffer; #[cfg(not(windows))] #[macro_use] diff --git a/src/net/addr.rs b/src/net/addr.rs index 13e5c24ff..0dcc4d1e8 100644 --- a/src/net/addr.rs +++ b/src/net/addr.rs @@ -169,7 +169,7 @@ mod tests { #[test] fn test_layouts() { - assert_eq_size!(SocketAddrLen, c::socklen_t); + static_assertions::assert_eq_size!(SocketAddrLen, c::socklen_t); #[cfg(not(any(windows, target_os = "redox")))] assert_eq!( diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index 796a114be..20cbbefe5 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -1814,6 +1814,6 @@ mod tests { // Backend code needs to cast these to `c_int` so make sure that cast // isn't lossy. - assert_eq_size!(Timeout, c_int); + static_assertions::assert_eq_size!(Timeout, c_int); } } diff --git a/src/net/types.rs b/src/net/types.rs index 370f2468f..6f9ba9f07 100644 --- a/src/net/types.rs +++ b/src/net/types.rs @@ -2114,14 +2114,14 @@ mod tests { // Backend code needs to cast these to `c_int` so make sure that cast isn't // lossy. - assert_eq_size!(RawProtocol, c_int); - assert_eq_size!(Protocol, c_int); - assert_eq_size!(Option, c_int); - assert_eq_size!(Option, c_int); - assert_eq_size!(RawSocketType, c_int); - assert_eq_size!(SocketType, c_int); - assert_eq_size!(SocketFlags, c_int); - assert_eq_size!(SocketAddrStorage, c::sockaddr_storage); + static_assertions::assert_eq_size!(RawProtocol, c_int); + static_assertions::assert_eq_size!(Protocol, c_int); + static_assertions::assert_eq_size!(Option, c_int); + static_assertions::assert_eq_size!(Option, c_int); + static_assertions::assert_eq_size!(RawSocketType, c_int); + static_assertions::assert_eq_size!(SocketType, c_int); + static_assertions::assert_eq_size!(SocketFlags, c_int); + static_assertions::assert_eq_size!(SocketAddrStorage, c::sockaddr_storage); // Rustix doesn't depend on `Option` matching the ABI of a raw // integer for correctness, but it should work nonetheless. @@ -2135,13 +2135,13 @@ mod tests { } #[cfg(linux_kernel)] - assert_eq_size!(UCred, libc::ucred); + static_assertions::assert_eq_size!(UCred, libc::ucred); #[cfg(target_os = "linux")] - assert_eq_size!(super::xdp::XdpUmemReg, c::xdp_umem_reg); + static_assertions::assert_eq_size!(super::xdp::XdpUmemReg, c::xdp_umem_reg); #[cfg(target_os = "linux")] - assert_eq_size!(super::xdp::XdpOptions, c::xdp_options); + static_assertions::assert_eq_size!(super::xdp::XdpOptions, c::xdp_options); #[cfg(target_os = "linux")] - assert_eq_size!(super::xdp::XdpDesc, c::xdp_desc); + static_assertions::assert_eq_size!(super::xdp::XdpDesc, c::xdp_desc); } } diff --git a/src/pid.rs b/src/pid.rs index fc0dc9e68..d984c28e3 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -148,16 +148,16 @@ mod tests { fn test_sizes() { use core::mem::transmute; - assert_eq_size!(RawPid, NonZeroI32); - assert_eq_size!(RawPid, Pid); - assert_eq_size!(RawPid, Option); + static_assertions::assert_eq_size!(RawPid, NonZeroI32); + static_assertions::assert_eq_size!(RawPid, Pid); + static_assertions::assert_eq_size!(RawPid, Option); // Rustix doesn't depend on `Option` matching the ABI of a raw integer // for correctness, but it should work nonetheless. - const_assert_eq!(0 as RawPid, unsafe { + static_assertions::const_assert_eq!(0 as RawPid, unsafe { transmute::, RawPid>(None) }); - const_assert_eq!(4567 as RawPid, unsafe { + static_assertions::const_assert_eq!(4567 as RawPid, unsafe { transmute::, RawPid>(Some(Pid::from_raw_unchecked(4567))) }); } diff --git a/src/runtime.rs b/src/runtime.rs index 9b612b8ba..698f44f2c 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -822,8 +822,8 @@ mod tests { // check_types macros because we want to test compatibility with actual // libc, not the `crate::backend::c` which might be our own // implementation. - assert_eq_size!(Siginfo, libc::siginfo_t); - assert_eq_align!(Siginfo, libc::siginfo_t); + static_assertions::assert_eq_size!(Siginfo, libc::siginfo_t); + static_assertions::assert_eq_align!(Siginfo, libc::siginfo_t); assert_eq!( memoffset::span_of!(Siginfo, ..), memoffset::span_of!(Siginfo, __bindgen_anon_1) @@ -842,8 +842,8 @@ mod tests { ); // c-scape assumes rustix's `Stack` matches libc's. Similar to above. - assert_eq_size!(Stack, libc::stack_t); - assert_eq_align!(Stack, libc::stack_t); + static_assertions::assert_eq_size!(Stack, libc::stack_t); + static_assertions::assert_eq_align!(Stack, libc::stack_t); assert_eq!( memoffset::span_of!(Stack, ss_sp), memoffset::span_of!(libc::stack_t, ss_sp) @@ -900,8 +900,8 @@ mod tests { sa_flags, sa_mask ); - assert_eq_size!(KernelSigactionFlags, crate::ffi::c_ulong); - assert_eq_align!(KernelSigactionFlags, crate::ffi::c_ulong); + static_assertions::assert_eq_size!(KernelSigactionFlags, crate::ffi::c_ulong); + static_assertions::assert_eq_align!(KernelSigactionFlags, crate::ffi::c_ulong); check_renamed_type!(KernelSigrestore, __sigrestore_t); check_renamed_type!(KernelSighandler, __kernel_sighandler_t); diff --git a/src/static_assertions.rs b/src/static_assertions.rs deleted file mode 100644 index 3d0711811..000000000 --- a/src/static_assertions.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! Workarounds for Rust 1.63 where some things in the `static_assertions` -//! crate do things that don't work in const contexts. We want to call them in -//! const contexts in Rust versions where that's supported so that problems are -//! caught at compile time, and fall back to dynamic asserts in Rust 1.63. - -#![allow(unused_macros)] - -macro_rules! assert_eq_size { - ($x:ty, $y:ty) => { - assert_eq!(core::mem::size_of::<$x>(), core::mem::size_of::<$y>()); - }; -} - -macro_rules! assert_eq_align { - ($x:ty, $y:ty) => { - assert_eq!(core::mem::align_of::<$x>(), core::mem::align_of::<$y>()); - }; -} - -macro_rules! const_assert_eq { - ($x:expr, $y:expr) => { - assert_eq!($x, $y); - }; -} - -macro_rules! const_assert_ne { - ($x:expr, $y:expr) => { - assert_ne!($x, $y); - }; -} - -macro_rules! const_assert { - ($x:expr) => { - assert!($x); - }; -} diff --git a/src/termios/types.rs b/src/termios/types.rs index 899fa74b6..71d9fb80b 100644 --- a/src/termios/types.rs +++ b/src/termios/types.rs @@ -1453,8 +1453,8 @@ mod tests { check_renamed_type!(OutputModes, tcflag_t); check_renamed_type!(ControlModes, tcflag_t); check_renamed_type!(LocalModes, tcflag_t); - assert_eq_size!(u8, libc::cc_t); - assert_eq_size!(types::tcflag_t, libc::tcflag_t); + static_assertions::assert_eq_size!(u8, libc::cc_t); + static_assertions::assert_eq_size!(types::tcflag_t, libc::tcflag_t); check_renamed_struct!(Winsize, winsize, ws_row, ws_col, ws_xpixel, ws_ypixel); @@ -1482,14 +1482,14 @@ mod tests { // On everything except PowerPC, `termios` matches `termios2` except // for the addition of `c_ispeed` and `c_ospeed`. #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] - const_assert_eq!( + static_assertions::const_assert_eq!( memoffset::offset_of!(Termios, input_speed), core::mem::size_of::() ); // On PowerPC, `termios2` is `termios`. #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] - assert_eq_size!(c::termios2, c::termios); + static_assertions::assert_eq_size!(c::termios2, c::termios); } #[cfg(not(linux_raw))] @@ -1525,7 +1525,9 @@ mod tests { )), not(all(libc, target_os = "android")) )))] - const_assert!(core::mem::size_of::() >= core::mem::size_of::()); + static_assertions::const_assert!( + core::mem::size_of::() >= core::mem::size_of::() + ); check_renamed_struct_renamed_field!(Termios, termios, input_modes, c_iflag); check_renamed_struct_renamed_field!(Termios, termios, output_modes, c_oflag); @@ -1572,8 +1574,8 @@ mod tests { )))] fn termios_legacy() { // Check that our doc aliases above are correct. - const_assert_eq!(c::EXTA, c::B19200); - const_assert_eq!(c::EXTB, c::B38400); + static_assertions::const_assert_eq!(c::EXTA, c::B19200); + static_assertions::const_assert_eq!(c::EXTB, c::B38400); } #[cfg(bsd)] @@ -1581,10 +1583,10 @@ mod tests { fn termios_bsd() { // On BSD platforms we can assume that the `B*` constants have their // arbitrary integer speed value. Confirm this. - const_assert_eq!(c::B0, 0); - const_assert_eq!(c::B50, 50); - const_assert_eq!(c::B19200, 19200); - const_assert_eq!(c::B38400, 38400); + static_assertions::const_assert_eq!(c::B0, 0); + static_assertions::const_assert_eq!(c::B50, 50); + static_assertions::const_assert_eq!(c::B19200, 19200); + static_assertions::const_assert_eq!(c::B38400, 38400); } #[test] @@ -1612,13 +1614,13 @@ mod tests { // When using `termios2`, we assume that we can add the optional actions // value to the ioctl request code. Test this assumption. - const_assert_eq!(c::TCSETS2, c::TCSETS2 + 0); - const_assert_eq!(c::TCSETSW2, c::TCSETS2 + 1); - const_assert_eq!(c::TCSETSF2, c::TCSETS2 + 2); + static_assertions::const_assert_eq!(c::TCSETS2, c::TCSETS2 + 0); + static_assertions::const_assert_eq!(c::TCSETSW2, c::TCSETS2 + 1); + static_assertions::const_assert_eq!(c::TCSETSF2, c::TCSETS2 + 2); - const_assert_eq!(c::TCSANOW - c::TCSANOW, 0); - const_assert_eq!(c::TCSADRAIN - c::TCSANOW, 1); - const_assert_eq!(c::TCSAFLUSH - c::TCSANOW, 2); + static_assertions::const_assert_eq!(c::TCSANOW - c::TCSANOW, 0); + static_assertions::const_assert_eq!(c::TCSADRAIN - c::TCSANOW, 1); + static_assertions::const_assert_eq!(c::TCSAFLUSH - c::TCSANOW, 2); // MIPS is different here. #[cfg(any( @@ -1639,9 +1641,9 @@ mod tests { target_arch = "mips64r6" )))] { - const_assert_eq!(c::TCSANOW, 0); - const_assert_eq!(c::TCSADRAIN, 1); - const_assert_eq!(c::TCSAFLUSH, 2); + static_assertions::const_assert_eq!(c::TCSANOW, 0); + static_assertions::const_assert_eq!(c::TCSADRAIN, 1); + static_assertions::const_assert_eq!(c::TCSAFLUSH, 2); } } @@ -1649,6 +1651,6 @@ mod tests { #[test] fn termios_cibaud() { // Test an assumption. - const_assert_eq!(c::CIBAUD, c::CBAUD << c::IBSHIFT); + static_assertions::const_assert_eq!(c::CIBAUD, c::CBAUD << c::IBSHIFT); } } diff --git a/src/timespec.rs b/src/timespec.rs index a6458bbca..44721958f 100644 --- a/src/timespec.rs +++ b/src/timespec.rs @@ -307,7 +307,7 @@ impl From for LibcTimespec { pub(crate) fn as_libc_timespec_ptr(timespec: &Timespec) -> *const c::timespec { #[cfg(test)] { - assert_eq_size!(Timespec, c::timespec); + static_assertions::assert_eq_size!(Timespec, c::timespec); } crate::utils::as_ptr(timespec).cast::() } @@ -318,7 +318,7 @@ pub(crate) fn as_libc_timespec_mut_ptr( ) -> *mut c::timespec { #[cfg(test)] { - assert_eq_size!(Timespec, c::timespec); + static_assertions::assert_eq_size!(Timespec, c::timespec); } timespec.as_mut_ptr().cast::() } @@ -376,9 +376,11 @@ mod tests { #[test] fn test_sizes() { - assert_eq_size!(Secs, u64); - const_assert!(core::mem::size_of::() >= core::mem::size_of::<(u64, u32)>()); - const_assert!(core::mem::size_of::() >= 4); + static_assertions::assert_eq_size!(Secs, u64); + static_assertions::const_assert!( + core::mem::size_of::() >= core::mem::size_of::<(u64, u32)>() + ); + static_assertions::const_assert!(core::mem::size_of::() >= 4); let mut t = Timespec { tv_sec: 0, @@ -399,7 +401,7 @@ mod tests { #[test] #[allow(deprecated)] fn test_fix_y2038() { - assert_eq_size!(libc::time_t, u32); + static_assertions::assert_eq_size!(libc::time_t, u32); } // Test that our workarounds are not needed. @@ -414,8 +416,8 @@ mod tests { #[cfg(linux_raw_dep)] #[test] fn test_against_kernel_timespec() { - assert_eq_size!(Timespec, linux_raw_sys::general::__kernel_timespec); - assert_eq_align!(Timespec, linux_raw_sys::general::__kernel_timespec); + static_assertions::assert_eq_size!(Timespec, linux_raw_sys::general::__kernel_timespec); + static_assertions::assert_eq_align!(Timespec, linux_raw_sys::general::__kernel_timespec); assert_eq!( memoffset::span_of!(Timespec, tv_sec), memoffset::span_of!(linux_raw_sys::general::__kernel_timespec, tv_sec) diff --git a/src/ugid.rs b/src/ugid.rs index 11edb19b3..6e5f5cf0b 100644 --- a/src/ugid.rs +++ b/src/ugid.rs @@ -185,9 +185,9 @@ mod tests { #[test] fn test_sizes() { - assert_eq_size!(RawUid, u32); - assert_eq_size!(RawGid, u32); - assert_eq_size!(RawUid, libc::uid_t); - assert_eq_size!(RawGid, libc::gid_t); + static_assertions::assert_eq_size!(RawUid, u32); + static_assertions::assert_eq_size!(RawGid, u32); + static_assertions::assert_eq_size!(RawUid, libc::uid_t); + static_assertions::assert_eq_size!(RawGid, libc::gid_t); } } diff --git a/src/utils.rs b/src/utils.rs index 77eb26c14..ba7663775 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -68,7 +68,7 @@ macro_rules! default_union { core::mem::size_of_val(&u), core::mem::size_of_val(&field_value) ); - const_assert_eq!(memoffset::offset_of_union!($union, $field), 0); + static_assertions::const_assert_eq!(memoffset::offset_of_union!($union, $field), 0); } u