diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b84767897..fa50d4f3e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ permissions: contents: read env: - MSRV: 1.69.0 + MSRV: 1.71.0 jobs: diff --git a/Cargo.toml b/Cargo.toml index 202c57b52a..8b7d6edf88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,9 @@ name = "nix" description = "Rust friendly bindings to *nix APIs" edition = "2021" +resolver = "2" version = "0.27.1" -rust-version = "1.69" +rust-version = "1.71" authors = ["The nix-rust Project Developers"] repository = "https://github.com/nix-rust/nix" license = "MIT" @@ -28,7 +29,6 @@ targets = [ ] [dependencies] -libc = { git = "https://github.com/rust-lang/libc", rev = "2f93bfb7678e18a9fc5373dec49384bd23f601c3", features = ["extra_traits"] } bitflags = "2.3.1" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } @@ -71,6 +71,11 @@ uio = [] user = ["feature"] zerocopy = ["fs", "uio"] +[dependencies.libc] +git = "https://github.com/anacrolix/rust-libc" +branch = "macos-ofd-fcntl" +features = ["extra_traits", "const-extern-fn"] + [dev-dependencies] assert-impl = "0.1" parking_lot = "0.12" diff --git a/changelog/2300.added.md b/changelog/2300.added.md new file mode 100644 index 0000000000..de69f67d73 --- /dev/null +++ b/changelog/2300.added.md @@ -0,0 +1 @@ +Enable fcntl::{F_OFD_SETLKW,F_OFD_SETLK,F_OFD_GETLK} for macOS diff --git a/changelog/2300.changed.md b/changelog/2300.changed.md new file mode 100644 index 0000000000..e9ea462576 --- /dev/null +++ b/changelog/2300.changed.md @@ -0,0 +1,2 @@ +Use resolver "2" +Require rust version 1.71 diff --git a/changelog/2300.fixed.md b/changelog/2300.fixed.md new file mode 100644 index 0000000000..dcd3db5cb6 --- /dev/null +++ b/changelog/2300.fixed.md @@ -0,0 +1,2 @@ +Fix libc feature deps for testing (added "const-extern-fn") +Fixed numerous clippy warnings diff --git a/src/fcntl.rs b/src/fcntl.rs index c1c8a4f196..392dc88ab8 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -522,15 +522,15 @@ pub enum FcntlArg<'a> { /// Get the first lock that blocks the lock description F_GETLK(&'a mut libc::flock), /// Acquire or release an open file description lock - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLK(&'a libc::flock), /// Like [`F_OFD_SETLK`](FcntlArg::F_OFD_SETLK) except that if a conflicting lock is held on /// the file, then wait for that lock to be released. - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLKW(&'a libc::flock), /// Determine whether it would be possible to create the given lock. If not, return details /// about one existing lock that would prevent it. - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_GETLK(&'a mut libc::flock), /// Add seals to the file #[cfg(any( @@ -614,11 +614,11 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result { F_SETLKW(flock) => libc::fcntl(fd, libc::F_SETLKW, flock), #[cfg(not(target_os = "redox"))] F_GETLK(flock) => libc::fcntl(fd, libc::F_GETLK, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLK(flock) => libc::fcntl(fd, libc::F_OFD_SETLK, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_SETLKW(flock) => libc::fcntl(fd, libc::F_OFD_SETLKW, flock), - #[cfg(linux_android)] + #[cfg(any(linux_android, macos))] F_OFD_GETLK(flock) => libc::fcntl(fd, libc::F_OFD_GETLK, flock), #[cfg(any( linux_android, diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index ec146a8c53..e98cc5fb80 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -6,7 +6,7 @@ use std::mem; use std::os::unix::io::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd}; libc_bitflags!( - pub struct EpollFlags: c_int { + pub struct EpollFlags: u32 { EPOLLIN; EPOLLPRI; EPOLLOUT; @@ -62,7 +62,7 @@ impl EpollEvent { } pub fn events(&self) -> EpollFlags { - EpollFlags::from_bits(self.event.events as c_int).unwrap() + EpollFlags::from_bits(self.event.events as u32).unwrap() } pub fn data(&self) -> u64 { diff --git a/src/sys/select.rs b/src/sys/select.rs index 64a8e258cf..6a5530fc81 100644 --- a/src/sys/select.rs +++ b/src/sys/select.rs @@ -3,7 +3,6 @@ use crate::errno::Errno; use crate::sys::time::{TimeSpec, TimeVal}; use crate::Result; use libc::{self, c_int}; -use std::convert::TryFrom; use std::iter::FusedIterator; use std::mem; use std::ops::Range; @@ -21,10 +20,7 @@ pub struct FdSet<'fd> { } fn assert_fd_valid(fd: RawFd) { - assert!( - usize::try_from(fd).map_or(false, |fd| fd < FD_SETSIZE), - "fd must be in the range 0..FD_SETSIZE", - ); + assert!(fd < FD_SETSIZE, "fd must be in the range 0..FD_SETSIZE",); } impl<'fd> FdSet<'fd> { @@ -110,7 +106,7 @@ impl<'fd> FdSet<'fd> { pub fn fds(&self, highest: Option) -> Fds { Fds { set: self, - range: 0..highest.map(|h| h as usize + 1).unwrap_or(FD_SETSIZE), + range: 0..highest.map(|h| h + 1).unwrap_or(FD_SETSIZE) as usize, } } } diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs index 746c6b6966..68e28cc149 100644 --- a/test/sys/test_select.rs +++ b/test/sys/test_select.rs @@ -68,13 +68,7 @@ macro_rules! generate_fdset_bad_fd_tests { mod test_fdset_too_large_fd { use super::*; - use std::convert::TryInto; - generate_fdset_bad_fd_tests!( - FD_SETSIZE.try_into().unwrap(), - insert, - remove, - contains, - ); + generate_fdset_bad_fd_tests!(FD_SETSIZE, insert, remove, contains,); } #[test] diff --git a/test/test_sendfile.rs b/test/test_sendfile.rs index 6333bf8662..1d6e133830 100644 --- a/test/test_sendfile.rs +++ b/test/test_sendfile.rs @@ -157,10 +157,10 @@ fn test_sendfile_dragonfly() { fn test_sendfile_darwin() { // Declare the content let header_strings = - vec!["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; + ["HTTP/1.1 200 OK\n", "Content-Type: text/plain\n", "\n"]; let body = "Xabcdef123456"; let body_offset = 1; - let trailer_strings = vec!["\n", "Served by Make Believe\n"]; + let trailer_strings = ["\n", "Served by Make Believe\n"]; // Write the body to a file let mut tmp = tempfile().unwrap();