From e39c13bacb4e7b4cb15c686c13a72fe94a09eb46 Mon Sep 17 00:00:00 2001 From: Tomas Zemanovic Date: Fri, 10 May 2024 16:53:37 +0200 Subject: [PATCH] tower-abci: v038's `Server::listen_unix()` is only used in unix builds (#47) this adds a `#[cfg(target_family = "unix")]` gate to the `listen_unix` method of `Server`. this fixes a broken build on non-unix systems. --- example: ``` ; git show --oneline --quiet HEAD 4b73065 (HEAD -> main, origin/main, origin/HEAD) tower-abci: use `tendermint@0.35` (#46) ; cargo build --quiet --target x86_64-pc-windows-msvc && echo "build passed" error[E0432]: unresolved import `tokio::net::UnixListener` --> src/v038/server.rs:9:39 | 9 | net::{TcpListener, ToSocketAddrs, UnixListener}, | ^^^^^^^^^^^^ | | | no `UnixListener` in `net` | help: a similar name exists in the module: `TcpListener` | note: found an item that was configured out --> .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.35.1/src/net/mod.rs:50:29 | 50 | pub use unix::listener::UnixListener; | ^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0432`. error: could not compile `tower-abci` (lib) due to 1 previous error ; git switch unix-guard-v038 branch 'unix-guard-v038' set up to track 'heliaxdev/unix-guard-v038'. Switched to a new branch 'unix-guard-v038' ; git show --oneline --quiet HEAD 52382f4 (HEAD -> unix-guard-v038, heliaxdev/unix-guard-v038) add feature guard to unix-only listener in v038 ; cargo build --quiet --target x86_64-pc-windows-msvc && echo "build passed" build passed ``` --- src/v038/server.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/v038/server.rs b/src/v038/server.rs index 881fdb1..8cd1eb9 100644 --- a/src/v038/server.rs +++ b/src/v038/server.rs @@ -1,12 +1,11 @@ use std::convert::{TryFrom, TryInto}; -use std::path::Path; use futures::future::{FutureExt, TryFutureExt}; use futures::sink::SinkExt; use futures::stream::{FuturesOrdered, StreamExt}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::{ - net::{TcpListener, ToSocketAddrs, UnixListener}, + net::{TcpListener, ToSocketAddrs}, select, }; use tokio_util::codec::{FramedRead, FramedWrite}; @@ -126,8 +125,9 @@ where ServerBuilder::default() } - pub async fn listen_unix(self, path: impl AsRef) -> Result<(), BoxError> { - let listener = UnixListener::bind(path)?; + #[cfg(target_family = "unix")] + pub async fn listen_unix(self, path: impl AsRef) -> Result<(), BoxError> { + let listener = tokio::net::UnixListener::bind(path)?; let addr = listener.local_addr()?; tracing::info!(?addr, "ABCI server starting on uds");