From 988bd00dc48d345247a5732acc8cb8cc711ab6ae Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 26 May 2023 14:10:20 -0700 Subject: [PATCH] make `log` an optional dependency Currently, Mio depends on `log`. In rust-lang/log#552, the `log` maintainers aim to increase `log`'s MSRV to 1.60. This MSRV increase would impact Mio, which in turn, would impact Tokio. As of 1.25, Tokio supports Rust 1.49 with the intent of supporting it until March 2024. This commit makes `log` an optional dependency for those who wish to maintain a lower MSRV. --- Cargo.toml | 4 ++-- src/macros.rs | 24 ++++++++++++++++++++++++ src/poll.rs | 1 - src/sys/unix/selector/epoll.rs | 1 - src/sys/unix/selector/kqueue.rs | 1 - 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 30392b133..d6072e8b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ include = [ # For documentation of features see the `mio::features` module. [features] # By default Mio only provides a shell implementation. -default = [] +default = ["log"] # Enables the `Poll` and `Registry` types. os-poll = [] @@ -43,7 +43,7 @@ os-ext = [ net = [] [dependencies] -log = "0.4.8" +log = { version = "0.4.8", optional = true } [target.'cfg(unix)'.dependencies] libc = "0.2.121" diff --git a/src/macros.rs b/src/macros.rs index f97f90911..3d42bd20a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -68,3 +68,27 @@ macro_rules! cfg_any_os_ext { )* } } + +macro_rules! trace { + ($($t:tt)*) => { + #[cfg(feature = "log")] + log::trace!($($t)*) + } +} + +macro_rules! error { + ($($t:tt)*) => { + #[cfg(feature = "log")] + { + log::error!($($t)*) + } + + // Silence warnings + #[cfg(not(feature = "log"))] + { + if false { + format!($($t)*); + } + } + } +} diff --git a/src/poll.rs b/src/poll.rs index 289d6686c..25a273ad2 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -1,5 +1,4 @@ use crate::{event, sys, Events, Interest, Token}; -use log::trace; #[cfg(unix)] use std::os::unix::io::{AsRawFd, RawFd}; use std::time::Duration; diff --git a/src/sys/unix/selector/epoll.rs b/src/sys/unix/selector/epoll.rs index 282d126d1..f3e0988c6 100644 --- a/src/sys/unix/selector/epoll.rs +++ b/src/sys/unix/selector/epoll.rs @@ -1,7 +1,6 @@ use crate::{Interest, Token}; use libc::{EPOLLET, EPOLLIN, EPOLLOUT, EPOLLPRI, EPOLLRDHUP}; -use log::error; use std::os::unix::io::{AsRawFd, RawFd}; #[cfg(debug_assertions)] use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; diff --git a/src/sys/unix/selector/kqueue.rs b/src/sys/unix/selector/kqueue.rs index 4b0c63163..8e9aa4c47 100644 --- a/src/sys/unix/selector/kqueue.rs +++ b/src/sys/unix/selector/kqueue.rs @@ -1,5 +1,4 @@ use crate::{Interest, Token}; -use log::error; use std::mem::{self, MaybeUninit}; use std::ops::{Deref, DerefMut}; use std::os::unix::io::{AsRawFd, RawFd};