From 06ee9397c7cc255b1344a4283df261ca9c0b3461 Mon Sep 17 00:00:00 2001 From: Dirreke Date: Thu, 31 Aug 2023 11:08:51 +0800 Subject: [PATCH] update ci and deps --- .github/bors.toml | 11 ++++++----- .github/workflows/ci.yml | 14 ++++++-------- Cargo.toml | 5 +++-- README.md | 2 +- examples/monitor.rs | 17 +++++++++-------- src/lib.rs | 25 +++++++++++++++++++++---- 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/.github/bors.toml b/.github/bors.toml index e69d000..ecb27bf 100644 --- a/.github/bors.toml +++ b/.github/bors.toml @@ -3,21 +3,22 @@ delete_merged_branches = true required_approvals = 1 status = [ "build (stable, aarch64-unknown-linux-gnu)", + "build (stable, aarch64-unknown-linux-musl)", "build (stable, arm-unknown-linux-gnueabi)", + "build (stable, arm-unknown-linux-gnueabihf)", "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, loongarch64-unknown-linux-gnu)", "build (stable, powerpc-unknown-linux-gnu)", + # "build (stable, powerpc64-unknown-linux-gnu)", "build (stable, powerpc64le-unknown-linux-gnu)", + "build (stable, riscv64gc-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)", + "build (1.65.0, x86_64-unknown-linux-gnu)", "checks" ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2751727..b983362 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,24 +16,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 +63,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 +70,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 +107,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/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..1799253 100644 --- a/examples/monitor.rs +++ b/examples/monitor.rs @@ -9,7 +9,8 @@ use gpio_cdev::*; use nix::poll::*; use quicli::prelude::*; -use std::os::unix::io::AsRawFd; +use std::os::unix::io::{AsRawFd, FromRawFd}; +use std::os::fd::OwnedFd; use structopt::StructOpt; type PollEventFlags = nix::poll::PollFlags; @@ -41,15 +42,15 @@ 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 { // poll for an event on any of the lines diff --git a/src/lib.rs b/src/lib.rs index dd3461f..99afded 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ extern crate bitflags; #[macro_use] extern crate nix; -use std::cmp::min; +use std::{cmp::min, os::fd::{BorrowedFd, AsFd}}; use std::ffi::CStr; use std::fs::{read_dir, File, ReadDir}; use std::io::Read; @@ -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); @@ -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;