Skip to content

Commit e9ac49a

Browse files
notgullsunfishcode
authored andcommitted
Patch low-hanging fruit semver removals for libc and linux-raw-sys (#1063)
* break: Remove low-hanging fruit for linux-raw-sys exposure linux-raw-sys is exposed as a public dependency. This commit removes many of the instances where it is publicly exposed. There are a few places that are more difficult and require greater discussion. I've left these in for now. This is checked using this command: $ cargo public-api --features all-apis | grep -i linux_raw_sys The remaining APIs that expose linux_raw_sys are as follows: pub type rustix::fs::FsWord = linux_raw_sys::general::__fsword_t pub type rustix::fs::RawMode = linux_raw_sys::general::__kernel_mode_t pub type rustix::fs::Stat = linux_raw_sys::general::stat pub type rustix::fs::StatFs = linux_raw_sys::general::statfs64 pub type rustix::fs::Statx = linux_raw_sys::general::statx pub type rustix::fs::StatxTimestamp = linux_raw_sys::general::statx_timestamp pub rustix::io_uring::io_uring_cqe::big_cqe: linux_raw_sys::io_uring::__IncompleteArrayField<u64> pub rustix::io_uring::io_uring_probe::ops: linux_raw_sys::io_uring::__IncompleteArrayField<rustix::io_uring::io_uring_probe_op> pub type rustix::io_uring::Statx = linux_raw_sys::general::statx pub type rustix::net::SocketAddrStorage = linux_raw_sys::net::sockaddr pub const fn rustix::process::WaitidStatus::as_raw(&self) -> &linux_raw_sys::general::siginfo_t pub type rustix::system::Sysinfo = linux_raw_sys::system::sysinfo pub type rustix::termios::Winsize = linux_raw_sys::general::winsize Signed-off-by: John Nunley <[email protected]> * break: Low-hanging fruit for removing libc from public API Similarly to the last commit, this one removes libc types from the public API. Again there are libc types that are harder to remove so I've skipped them for now. This can be checked with: $ cargo public-api --features all-apis,use-libc | grep -i libc The remaining API's are: pub type rustix::fs::Dev = libc::unix::linux_like::linux::dev_t pub type rustix::fs::FsWord = libc::unix::linux_like::linux::gnu::b64::__fsword_t pub type rustix::fs::RawMode = libc::unix::linux_like::linux::mode_t pub type rustix::fs::Stat = libc::unix::linux_like::linux::gnu::b64::x86_64::stat64 pub type rustix::fs::StatFs = libc::unix::linux_like::linux::gnu::b64::x86_64::statfs64 pub type rustix::fs::Statx = libc::unix::linux_like::linux::gnu::statx pub type rustix::fs::StatxTimestamp = libc::unix::linux_like::linux::gnu::statx pub type rustix::io_uring::Statx = libc::unix::linux_like::linux::gnu::statx pub type rustix::net::SocketAddrStorage = libc::unix::linux_like::sockaddr_storage pub const fn rustix::process::WaitidStatus::as_raw(&self) -> &libc::unix::linux_like::linux::gnu::b64::x86_64::siginfo_t pub type rustix::system::Sysinfo = libc::unix::linux_like::linux::gnu::b64::sysinfo pub type rustix::termios::Winsize = libc::unix::winsize Signed-off-by: John Nunley <[email protected]> --------- Signed-off-by: John Nunley <[email protected]>
1 parent c5529aa commit e9ac49a

File tree

25 files changed

+95
-59
lines changed

25 files changed

+95
-59
lines changed

src/backend/libc/event/epoll.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ use crate::backend::c;
7474
use crate::backend::conv::ret_u32;
7575
use crate::backend::conv::{ret, ret_owned_fd};
7676
use crate::fd::{AsFd, AsRawFd, OwnedFd};
77+
use crate::ffi;
7778
use crate::io;
7879
use crate::utils::as_mut_ptr;
7980
#[cfg(feature = "alloc")]
@@ -287,7 +288,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
287288
/// [Linux]: https://man7.org/linux/man-pages/man2/epoll_wait.2.html
288289
#[cfg(feature = "alloc")]
289290
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
290-
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
291+
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
291292
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
292293
// behaves.
293294
unsafe {

src/backend/libc/event/poll_fd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::backend::conv::borrowed_fd;
33
use crate::backend::fd::{AsFd, AsRawFd, BorrowedFd, LibcFd};
44
#[cfg(windows)]
55
use crate::backend::fd::{AsSocket, RawFd};
6+
use crate::ffi;
67
use bitflags::bitflags;
78
use core::fmt;
89
use core::marker::PhantomData;
@@ -13,7 +14,7 @@ bitflags! {
1314
/// [`poll`]: crate::event::poll
1415
#[repr(transparent)]
1516
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
16-
pub struct PollFlags: c::c_short {
17+
pub struct PollFlags: ffi::c_short {
1718
/// `POLLIN`
1819
const IN = c::POLLIN;
1920
/// `POLLPRI`

src/backend/libc/fs/types.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::backend::c;
2+
use crate::ffi;
23
use bitflags::bitflags;
34

45
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
@@ -8,7 +9,7 @@ bitflags! {
89
/// [`accessat`]: fn.accessat.html
910
#[repr(transparent)]
1011
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
11-
pub struct Access: c::c_int {
12+
pub struct Access: ffi::c_int {
1213
/// `R_OK`
1314
const READ_OK = c::R_OK;
1415

@@ -378,7 +379,7 @@ bitflags! {
378379
/// [`fcopyfile`]: crate::fs::fcopyfile
379380
#[repr(transparent)]
380381
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
381-
pub struct CopyfileFlags: c::c_uint {
382+
pub struct CopyfileFlags: ffi::c_uint {
382383
/// `COPYFILE_ACL`
383384
const ACL = copyfile::ACL;
384385

@@ -443,7 +444,7 @@ bitflags! {
443444
/// [`renameat_with`]: crate::fs::renameat_with
444445
#[repr(transparent)]
445446
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
446-
pub struct RenameFlags: c::c_uint {
447+
pub struct RenameFlags: ffi::c_uint {
447448
/// `RENAME_EXCHANGE`
448449
const EXCHANGE = bitcast!(c::RENAME_EXCHANGE);
449450

@@ -598,7 +599,7 @@ bitflags! {
598599
/// [`memfd_create`]: crate::fs::memfd_create
599600
#[repr(transparent)]
600601
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
601-
pub struct MemfdFlags: c::c_uint {
602+
pub struct MemfdFlags: ffi::c_uint {
602603
/// `MFD_CLOEXEC`
603604
const CLOEXEC = c::MFD_CLOEXEC;
604605

@@ -1127,15 +1128,15 @@ pub type RawMode = c::mode_t;
11271128

11281129
/// `mode_t`
11291130
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
1130-
pub type RawMode = c::c_uint;
1131+
pub type RawMode = ffi::c_uint;
11311132

11321133
/// `dev_t`
11331134
#[cfg(not(all(target_os = "android", target_pointer_width = "32")))]
11341135
pub type Dev = c::dev_t;
11351136

11361137
/// `dev_t`
11371138
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
1138-
pub type Dev = c::c_ulonglong;
1139+
pub type Dev = ffi::c_ulonglong;
11391140

11401141
/// `__fsword_t`
11411142
#[cfg(all(

src/backend/libc/pipe/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(linux_kernel)]
22
use core::marker::PhantomData;
33
#[cfg(not(any(apple, target_os = "wasi")))]
4-
use {crate::backend::c, bitflags::bitflags};
4+
use {crate::backend::c, crate::ffi, bitflags::bitflags};
55

66
#[cfg(not(any(apple, target_os = "wasi")))]
77
bitflags! {
@@ -43,7 +43,7 @@ bitflags! {
4343
/// [`tee`]: crate::pipe::tee
4444
#[repr(transparent)]
4545
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
46-
pub struct SpliceFlags: c::c_uint {
46+
pub struct SpliceFlags: ffi::c_uint {
4747
/// `SPLICE_F_MOVE`
4848
const MOVE = c::SPLICE_F_MOVE;
4949
/// `SPLICE_F_NONBLOCK`

src/backend/libc/termios/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub(crate) mod syscalls;
2+
pub(crate) mod types;

src/backend/libc/termios/types.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[cfg(not(target_os = "redox"))]
2+
use crate::ffi;
3+
4+
// We don't want to use tcflag_t directly so we don't expose libc
5+
// publicly. Redox uses u32, apple uses c_ulong, everything else
6+
// seems to use c_uint.
7+
8+
#[cfg(apple)]
9+
pub type tcflag_t = ffi::c_ulong;
10+
#[cfg(target_os = "redox")]
11+
pub type tcflag_t = u32;
12+
#[cfg(not(any(apple, target_os = "redox")))]
13+
pub type tcflag_t = ffi::c_uint;

src/backend/linux_raw/event/epoll.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
7272
#![allow(unsafe_code)]
7373

74-
use crate::backend::c;
7574
use crate::backend::event::syscalls;
7675
use crate::fd::{AsFd, AsRawFd, OwnedFd};
76+
use crate::ffi;
7777
use crate::io;
7878
#[cfg(feature = "alloc")]
7979
use alloc::vec::Vec;
@@ -86,7 +86,7 @@ bitflags! {
8686
/// `EPOLL_*` for use with [`create`].
8787
#[repr(transparent)]
8888
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
89-
pub struct CreateFlags: c::c_uint {
89+
pub struct CreateFlags: ffi::c_uint {
9090
/// `EPOLL_CLOEXEC`
9191
const CLOEXEC = linux_raw_sys::general::EPOLL_CLOEXEC;
9292

@@ -267,7 +267,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
267267
#[cfg(feature = "alloc")]
268268
#[cfg_attr(docsrs, doc(cfg(feature = "alloc"), alias = "epoll_wait"))]
269269
#[inline]
270-
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
270+
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
271271
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
272272
// behaves.
273273
unsafe {
@@ -493,6 +493,8 @@ impl<'a> IntoIterator for &'a EventVec {
493493

494494
#[test]
495495
fn test_epoll_layouts() {
496+
use crate::backend::c;
497+
496498
check_renamed_type!(Event, epoll_event);
497499
check_renamed_type!(Event, epoll_event);
498500
check_renamed_struct_renamed_field!(Event, epoll_event, flags, events);

src/backend/linux_raw/event/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::backend::c;
1+
use crate::ffi;
22
use bitflags::bitflags;
33

44
bitflags! {
@@ -7,7 +7,7 @@ bitflags! {
77
/// [`eventfd`]: crate::event::eventfd
88
#[repr(transparent)]
99
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
10-
pub struct EventfdFlags: c::c_uint {
10+
pub struct EventfdFlags: ffi::c_uint {
1111
/// `EFD_CLOEXEC`
1212
const CLOEXEC = linux_raw_sys::general::EFD_CLOEXEC;
1313
/// `EFD_NONBLOCK`

src/backend/linux_raw/fs/inotify.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! inotify support for working with inotifies
22
33
use crate::backend::c;
4+
use crate::ffi;
45
use bitflags::bitflags;
56

67
bitflags! {
@@ -9,7 +10,7 @@ bitflags! {
910
/// [`inotify_init`]: crate::fs::inotify::inotify_init
1011
#[repr(transparent)]
1112
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
12-
pub struct CreateFlags: c::c_uint {
13+
pub struct CreateFlags: ffi::c_uint {
1314
/// `IN_CLOEXEC`
1415
const CLOEXEC = linux_raw_sys::general::IN_CLOEXEC;
1516
/// `IN_NONBLOCK`
@@ -26,7 +27,7 @@ bitflags! {
2627
/// [`inotify_add_watch`]: crate::fs::inotify::inotify_add_watch
2728
#[repr(transparent)]
2829
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
29-
pub struct WatchFlags: c::c_uint {
30+
pub struct WatchFlags: ffi::c_uint {
3031
/// `IN_ACCESS`
3132
const ACCESS = linux_raw_sys::general::IN_ACCESS;
3233
/// `IN_ATTRIB`

src/backend/linux_raw/fs/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::backend::c;
1+
use crate::ffi;
22
use bitflags::bitflags;
33

44
bitflags! {
@@ -7,7 +7,7 @@ bitflags! {
77
/// [`accessat`]: fn.accessat.html
88
#[repr(transparent)]
99
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
10-
pub struct Access: c::c_uint {
10+
pub struct Access: ffi::c_uint {
1111
/// `R_OK`
1212
const READ_OK = linux_raw_sys::general::R_OK;
1313

@@ -33,7 +33,7 @@ bitflags! {
3333
/// [`statat`]: crate::fs::statat
3434
#[repr(transparent)]
3535
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
36-
pub struct AtFlags: c::c_uint {
36+
pub struct AtFlags: ffi::c_uint {
3737
/// `AT_SYMLINK_NOFOLLOW`
3838
const SYMLINK_NOFOLLOW = linux_raw_sys::general::AT_SYMLINK_NOFOLLOW;
3939

@@ -172,7 +172,7 @@ bitflags! {
172172
/// [`openat`]: crate::fs::openat
173173
#[repr(transparent)]
174174
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
175-
pub struct OFlags: c::c_uint {
175+
pub struct OFlags: ffi::c_uint {
176176
/// `O_ACCMODE`
177177
const ACCMODE = linux_raw_sys::general::O_ACCMODE;
178178

@@ -298,7 +298,7 @@ bitflags! {
298298
/// [`renameat_with`]: crate::fs::renameat_with
299299
#[repr(transparent)]
300300
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
301-
pub struct RenameFlags: c::c_uint {
301+
pub struct RenameFlags: ffi::c_uint {
302302
/// `RENAME_EXCHANGE`
303303
const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE;
304304

@@ -425,7 +425,7 @@ bitflags! {
425425
/// [`memfd_create`]: crate::fs::memfd_create
426426
#[repr(transparent)]
427427
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
428-
pub struct MemfdFlags: c::c_uint {
428+
pub struct MemfdFlags: ffi::c_uint {
429429
/// `MFD_CLOEXEC`
430430
const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC;
431431

@@ -739,7 +739,7 @@ pub type RawMode = linux_raw_sys::general::__kernel_mode_t;
739739
target_arch = "arm",
740740
))]
741741
// Don't use `__kernel_mode_t` since it's `u16` which differs from `st_size`.
742-
pub type RawMode = c::c_uint;
742+
pub type RawMode = ffi::c_uint;
743743

744744
/// `dev_t`
745745
// Within the kernel the `dev_t` is 32-bit, but userspace uses a 64-bit field.

0 commit comments

Comments
 (0)