Skip to content

Commit

Permalink
Fix compiling for Windows targets (#5053)
Browse files Browse the repository at this point in the history
The `unix::signal` was also included during Windows compilations.
This of course will not work. Fix this by only including it for `unix` targets.

Also changed all other conditional compilation options to use `cfg(unix)` instead of `cfg(not(windows))`.
The latter may also include `wasm` for example, or any other future target family.
This way we will only match `unix`

Fixes #5052
  • Loading branch information
BlackDex authored Oct 6, 2024
1 parent 040e2a7 commit f0efec7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ query_logger = ["dep:diesel_logger"]
# Currently only used to enable rusts official ip support
unstable = []

[target."cfg(not(windows))".dependencies]
[target."cfg(unix)".dependencies]
# Logging
syslog = "6.1.1"

Expand Down
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ use std::{
use tokio::{
fs::File,
io::{AsyncBufReadExt, BufReader},
signal::unix::SignalKind,
};

#[cfg(unix)]
use tokio::signal::unix::SignalKind;

#[macro_use]
mod error;
mod api;
Expand Down Expand Up @@ -383,15 +385,15 @@ fn init_logging() -> Result<log::LevelFilter, Error> {
{
logger = logger.chain(fern::log_file(log_file)?);
}
#[cfg(not(windows))]
#[cfg(unix)]
{
const SIGHUP: i32 = SignalKind::hangup().as_raw_value();
let path = Path::new(&log_file);
logger = logger.chain(fern::log_reopen1(path, [SIGHUP])?);
}
}

#[cfg(not(windows))]
#[cfg(unix)]
{
if cfg!(feature = "enable_syslog") || CONFIG.use_syslog() {
logger = chain_syslog(logger);
Expand Down Expand Up @@ -441,7 +443,7 @@ fn init_logging() -> Result<log::LevelFilter, Error> {
Ok(level)
}

#[cfg(not(windows))]
#[cfg(unix)]
fn chain_syslog(logger: fern::Dispatch) -> fern::Dispatch {
let syslog_fmt = syslog::Formatter3164 {
facility: syslog::Facility::LOG_USER,
Expand Down

0 comments on commit f0efec7

Please sign in to comment.