Skip to content

Commit

Permalink
make log an optional dependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carllerche committed May 26, 2023
1 parent 0757ec8 commit 44df449
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*);
}
}
}
}
1 change: 0 additions & 1 deletion src/poll.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/sys/unix/selector/epoll.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
1 change: 0 additions & 1 deletion src/sys/unix/selector/kqueue.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down

0 comments on commit 44df449

Please sign in to comment.