diff --git a/.github/bors.toml b/.github/bors.toml deleted file mode 100644 index e69d000..0000000 --- a/.github/bors.toml +++ /dev/null @@ -1,24 +0,0 @@ -block_labels = ["needs-decision"] -delete_merged_branches = true -required_approvals = 1 -status = [ - "build (stable, aarch64-unknown-linux-gnu)", - "build (stable, arm-unknown-linux-gnueabi)", - "build (stable, armv7-unknown-linux-gnueabihf)", - "build (stable, i686-unknown-linux-gnu)", - "build (stable, i686-unknown-linux-musl)", - "build (stable, mips-unknown-linux-gnu)", - "build (stable, mips64-unknown-linux-gnuabi64)", - "build (stable, mips64el-unknown-linux-gnuabi64)", - "build (stable, mipsel-unknown-linux-gnu)", - "build (stable, powerpc-unknown-linux-gnu)", - "build (stable, powerpc64le-unknown-linux-gnu)", - "build (stable, s390x-unknown-linux-gnu)", - "build (stable, x86_64-unknown-linux-gnu)", - "build (stable, x86_64-unknown-linux-musl)", - - "build (1.59.0, x86_64-unknown-linux-gnu)", - - "checks" -] -timeout_sec = 7200 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2751727..569cd2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,9 @@ on: - push: - branches: [ staging, trying, master ] - pull_request: + push: # Run CI for all branches except GitHub merge queue tmp branches + branches-ignore: + - "gh-readonly-queue/**" + pull_request: # Run CI for PRs on any branch + merge_group: # Run CI for the GitHub merge queue name: Build @@ -16,24 +18,24 @@ jobs: rust: [stable] TARGET: - aarch64-unknown-linux-gnu + - aarch64-unknown-linux-musl - arm-unknown-linux-gnueabi + - arm-unknown-linux-gnueabihf - armv7-unknown-linux-gnueabihf - i686-unknown-linux-gnu - i686-unknown-linux-musl - - mips-unknown-linux-gnu - - mips64-unknown-linux-gnuabi64 - - mips64el-unknown-linux-gnuabi64 - - mipsel-unknown-linux-gnu + # - loongarch64-unknown-linux-gnu - powerpc-unknown-linux-gnu # - powerpc64-unknown-linux-gnu - powerpc64le-unknown-linux-gnu + - riscv64gc-unknown-linux-gnu - s390x-unknown-linux-gnu - x86_64-unknown-linux-gnu - x86_64-unknown-linux-musl include: # MSRV - - rust: 1.59.0 + - rust: 1.65.0 TARGET: x86_64-unknown-linux-gnu # Test nightly but don't fail @@ -63,7 +65,6 @@ jobs: args: --target=${{ matrix.TARGET }} --all-features - name: Test - if: ${{ ! contains(matrix.TARGET, 'mips') }} # https://github.com/rust-lang/rust/issues/108835 uses: actions-rs/cargo@v1 with: use-cross: true @@ -71,7 +72,6 @@ jobs: args: --target=${{ matrix.TARGET }} - name: Test all features - if: ${{ ! contains(matrix.TARGET, 'mips') }} # https://github.com/rust-lang/rust/issues/108835 uses: actions-rs/cargo@v1 with: use-cross: true @@ -109,7 +109,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.59.0 + toolchain: 1.65.0 components: clippy - uses: actions-rs/clippy-check@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index a9f57ae..6b21a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -- MSRV is now 1.59.0. +- Updated nix to version `0.27`. +- Updated bitflags to version `2.4`. +- MSRV is now 1.65.0. ## [v0.5.1] - 2021-11-22 diff --git a/Cargo.toml b/Cargo.toml index 1ff489e..05d28c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ name = "async_tokio" required-features = ["async-tokio"] [dependencies] -bitflags = "1.3" +bitflags = "2.4" libc = "0.2" -nix = "0.23" +nix = { version = "0.27", features = ["ioctl"] } tokio = { version = "1", features = ["io-std", "net"], optional = true } futures = { version = "0.3", optional = true } @@ -31,6 +31,7 @@ quicli = "0.4" structopt = "0.3" anyhow = "1.0" tokio = { version = "1", features = ["io-std", "rt-multi-thread", "macros", "net"] } +nix = { version = "0.27", features = ["ioctl", "poll"] } [package.metadata.docs.rs] # To build locally: diff --git a/README.md b/README.md index 6db8098..5efdcef 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ to be considered reliable. ## Minimum Supported Rust Version (MSRV) -This crate is guaranteed to compile on stable Rust 1.59.0 and up. It *might* +This crate is guaranteed to compile on stable Rust 1.65.0 and up. It *might* compile with older versions but that may change in any new patch release. ## License diff --git a/examples/monitor.rs b/examples/monitor.rs index 0e4e372..7925907 100644 --- a/examples/monitor.rs +++ b/examples/monitor.rs @@ -9,7 +9,7 @@ use gpio_cdev::*; use nix::poll::*; use quicli::prelude::*; -use std::os::unix::io::AsRawFd; +use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd}; use structopt::StructOpt; type PollEventFlags = nix::poll::PollFlags; @@ -41,14 +41,13 @@ fn do_main(args: Cli) -> anyhow::Result<()> { .collect(); // Create a vector of file descriptors for polling - let mut pollfds: Vec = evt_handles + let ownedfd: Vec = evt_handles .iter() - .map(|h| { - PollFd::new( - h.as_raw_fd(), - PollEventFlags::POLLIN | PollEventFlags::POLLPRI, - ) - }) + .map(|h| unsafe { OwnedFd::from_raw_fd(h.as_raw_fd()) }) + .collect(); + let mut pollfds: Vec = ownedfd + .iter() + .map(|fd| PollFd::new(fd, PollEventFlags::POLLIN | PollEventFlags::POLLPRI)) .collect(); loop { diff --git a/src/async_tokio.rs b/src/async_tokio.rs index 9e4a73f..327272c 100644 --- a/src/async_tokio.rs +++ b/src/async_tokio.rs @@ -97,6 +97,6 @@ impl Stream for AsyncLineEventHandle { impl AsRef for AsyncLineEventHandle { fn as_ref(&self) -> &LineEventHandle { - &self.asyncfd.get_ref() + self.asyncfd.get_ref() } } diff --git a/src/lib.rs b/src/lib.rs index dd3461f..b8b6506 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,7 +95,7 @@ use std::fs::{read_dir, File, ReadDir}; use std::io::Read; use std::mem; use std::ops::Index; -use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; +use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, RawFd}; use std::path::{Path, PathBuf}; use std::ptr; use std::slice; @@ -335,7 +335,7 @@ pub struct Line { /// Wraps kernel [`struct gpioline_info`]. /// /// [`struct gpioline_info`]: https://elixir.bootlin.com/linux/v4.9.127/source/include/uapi/linux/gpio.h#L36 -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct LineInfo { line: Line, flags: LineFlags, @@ -349,6 +349,7 @@ bitflags! { /// Maps to kernel [`GPIOHANDLE_REQUEST_*`] flags. /// /// [`GPIOHANDLE_REQUEST_*`]: https://elixir.bootlin.com/linux/v4.9.127/source/include/uapi/linux/gpio.h#L58 + #[derive(Debug, Clone)] pub struct LineRequestFlags: u32 { const INPUT = (1 << 0); const OUTPUT = (1 << 1); @@ -367,7 +368,7 @@ bitflags! { pub struct EventRequestFlags: u32 { const RISING_EDGE = (1 << 0); const FALLING_EDGE = (1 << 1); - const BOTH_EDGES = Self::RISING_EDGE.bits | Self::FALLING_EDGE.bits; + const BOTH_EDGES = Self::RISING_EDGE.bits() | Self::FALLING_EDGE.bits(); } } @@ -377,6 +378,7 @@ bitflags! { /// Maps to kernel [`GPIOLINE_FLAG_*`] flags. /// /// [`GPIOLINE_FLAG_*`]: https://elixir.bootlin.com/linux/v4.9.127/source/include/uapi/linux/gpio.h#L29 + #[derive(Debug)] pub struct LineFlags: u32 { const KERNEL = (1 << 0); const IS_OUT = (1 << 1); @@ -572,7 +574,7 @@ impl Line { consumer: &str, ) -> Result { let events = self.events(handle_flags, event_flags, consumer)?; - Ok(AsyncLineEventHandle::new(events)?) + AsyncLineEventHandle::new(events) } } @@ -693,7 +695,7 @@ impl LineHandle { /// Get the flags with which this handle was created pub fn flags(&self) -> LineRequestFlags { - self.flags + self.flags.clone() } } @@ -985,6 +987,14 @@ impl LineEventHandle { &self.line } + pub fn file(&self) -> &File { + &self.file + } + + pub fn file2(&mut self) -> &File { + &self.file + } + /// Helper function which returns the line event if a complete event was read, Ok(None) if not /// enough data was read or the error returned by `read()`. pub(crate) fn read_event(&mut self) -> std::io::Result> { @@ -1011,6 +1021,13 @@ impl AsRawFd for LineEventHandle { } } +impl AsFd for LineEventHandle { + /// Gets the raw file descriptor for the `LineEventHandle`. + fn as_fd(&self) -> BorrowedFd<'_> { + self.file.as_fd() + } +} + impl Iterator for LineEventHandle { type Item = Result;