Skip to content

Commit 1890e5d

Browse files
committed
fix(harness-monitor): add Windows support with TCP fallback
- Use conditional compilation for Unix socket (only on Unix platforms) - On Windows, RuntimeSocket is not available, automatically fallback to TCP - send_socket_message returns error on Windows, triggering TCP fallback - socket_reachable returns false on Windows - This ensures Windows builds succeed while maintaining Unix socket on Unix/macOS Fixes Windows compilation error in GitHub Actions release workflow
1 parent 652f1c6 commit 1890e5d

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

crates/harness-monitor/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ mod run;
88
mod shared;
99
mod ui;
1010

11-
use crate::observe::ipc::{RuntimeSocket, RuntimeTcp};
11+
#[cfg(unix)]
12+
use crate::observe::ipc::RuntimeSocket;
13+
use crate::observe::ipc::RuntimeTcp;
1214
use crate::observe::Snapshot;
1315
use crate::observe::{resolve, resolve_runtime};
1416
use crate::shared::db::Db;
@@ -293,7 +295,11 @@ fn run_watch(
293295
}
294296

295297
fn run_serve(ctx: &crate::observe::repo::RepoContext) -> Result<()> {
298+
#[cfg(unix)]
296299
let socket_server = RuntimeSocket::bind(&ctx.runtime_socket_path).ok();
300+
#[cfg(not(unix))]
301+
let socket_server: Option<()> = None;
302+
297303
let tcp_server = if socket_server.is_none() {
298304
RuntimeTcp::bind(&ctx.runtime_tcp_addr).ok()
299305
} else {
@@ -327,6 +333,7 @@ fn run_serve(ctx: &crate::observe::repo::RepoContext) -> Result<()> {
327333
},
328334
)?;
329335

336+
#[cfg(unix)]
330337
if let Some(server) = &socket_server {
331338
for message in server.read_pending()? {
332339
crate::observe::ipc::send_message(&ctx.runtime_event_path, &message)?;

crates/harness-monitor/src/observe/ipc.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use anyhow::{Context, Result};
33
use std::fs::OpenOptions;
44
use std::io::{BufRead, BufReader, Seek, SeekFrom, Write};
55
use std::net::{TcpListener, TcpStream};
6+
#[cfg(unix)]
67
use std::os::unix::net::{UnixListener, UnixStream};
78
use std::path::{Path, PathBuf};
89
use std::time::Duration;
@@ -85,10 +86,12 @@ impl RuntimeFeed {
8586
}
8687
}
8788

89+
#[cfg(unix)]
8890
pub struct RuntimeSocket {
8991
listener: UnixListener,
9092
}
9193

94+
#[cfg(unix)]
9295
impl RuntimeSocket {
9396
pub fn bind(socket_path: &Path) -> Result<Self> {
9497
if let Some(parent) = socket_path.parent() {
@@ -172,6 +175,7 @@ pub fn send_message(event_path: &Path, message: &RuntimeMessage) -> Result<()> {
172175
Ok(())
173176
}
174177

178+
#[cfg(unix)]
175179
pub fn send_socket_message(socket_path: &Path, message: &RuntimeMessage) -> Result<()> {
176180
let mut stream = UnixStream::connect(socket_path)
177181
.with_context(|| format!("connect runtime socket {:?}", socket_path))?;
@@ -183,6 +187,11 @@ pub fn send_socket_message(socket_path: &Path, message: &RuntimeMessage) -> Resu
183187
Ok(())
184188
}
185189

190+
#[cfg(not(unix))]
191+
pub fn send_socket_message(_socket_path: &Path, _message: &RuntimeMessage) -> Result<()> {
192+
anyhow::bail!("Unix sockets are not supported on this platform")
193+
}
194+
186195
pub fn send_tcp_message(addr: &str, message: &RuntimeMessage) -> Result<()> {
187196
let mut stream =
188197
TcpStream::connect(addr).with_context(|| format!("connect runtime tcp {addr}"))?;
@@ -194,10 +203,16 @@ pub fn send_tcp_message(addr: &str, message: &RuntimeMessage) -> Result<()> {
194203
Ok(())
195204
}
196205

206+
#[cfg(unix)]
197207
pub fn socket_reachable(socket_path: &Path) -> bool {
198208
socket_path.exists() && UnixStream::connect(socket_path).is_ok()
199209
}
200210

211+
#[cfg(not(unix))]
212+
pub fn socket_reachable(_socket_path: &Path) -> bool {
213+
false
214+
}
215+
201216
pub fn tcp_reachable(addr: &str) -> bool {
202217
addr.parse()
203218
.ok()
@@ -227,6 +242,7 @@ pub fn read_service_info(info_path: &Path) -> Result<Option<RuntimeServiceInfo>>
227242
Ok(Some(info))
228243
}
229244

245+
#[cfg(unix)]
230246
fn read_stream_message(stream: UnixStream) -> Result<Option<RuntimeMessage>> {
231247
let mut reader = BufReader::new(stream);
232248
let mut line = String::new();

crates/harness-monitor/src/observe/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ pub mod repo;
1111
// Re-export commonly used types at this module level
1212
pub use self::detect::{calculate_stats, scan_agents};
1313
pub use self::hooks::{handle_git_event, handle_hook, parse_stdin_payload};
14-
pub use self::ipc::{RuntimeFeed, RuntimeSocket, RuntimeTcp};
14+
#[cfg(unix)]
15+
pub use self::ipc::RuntimeSocket;
16+
pub use self::ipc::{RuntimeFeed, RuntimeTcp};
1517
pub use self::observe::{
1618
entry_kind_for_path, entry_kind_for_repo_path, poll_repo, scan_repo, Snapshot,
1719
};

0 commit comments

Comments
 (0)