From 0705501537d52d4bf1bf1a7480c3f25d98f164ad Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 14 Jul 2025 23:16:19 +0200 Subject: [PATCH] radicle: Depend on winpipe for Windows support --- Cargo.lock | 97 ++++++++++++++++++++++++++++++++++++-- Cargo.toml | 1 + crates/radicle/Cargo.toml | 3 ++ crates/radicle/src/node.rs | 12 +++-- 4 files changed, 106 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76682e24..f01ce4a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -650,6 +650,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "defer-heavy" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5053691e3e6c0e5979cfb55503b7eb4b06531897b5c15b0f617110096b05a0e1" + [[package]] name = "der" version = "0.7.9" @@ -1560,7 +1566,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -1946,9 +1952,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "maybe-async" @@ -2503,6 +2509,7 @@ dependencies = [ "tempfile", "thiserror 1.0.69", "unicode-normalization", + "winpipe", ] [[package]] @@ -2745,6 +2752,7 @@ dependencies = [ "byteorder", "log", "thiserror 1.0.69", + "winpipe", "zeroize", ] @@ -3408,6 +3416,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync-ptr" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b115b4cc742d11625f50e0e48ab15baf6fa548c2ec33a8d4113711886316a4f" + [[package]] name = "synstructure" version = "0.13.1" @@ -3892,6 +3906,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -3901,6 +3925,60 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -4058,6 +4136,19 @@ dependencies = [ "memchr", ] +[[package]] +name = "winpipe" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ccf671d62d1bd0c913d9059e69bb4a6b51f7a4c899ab83c62d921e35f206053" +dependencies = [ + "defer-heavy", + "log", + "rand", + "sync-ptr", + "windows", +] + [[package]] name = "write16" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 60697ad0..fc84637f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ snapbox = "0.4.3" sqlite = "0.32.0" tempfile = "3.3.0" thiserror = "1.0" +winpipe = "0.1.1" zeroize = "1.5.7" [workspace.lints] diff --git a/crates/radicle/Cargo.toml b/crates/radicle/Cargo.toml index 8ec5a9b9..b5cd8a73 100644 --- a/crates/radicle/Cargo.toml +++ b/crates/radicle/Cargo.toml @@ -48,6 +48,9 @@ unicode-normalization = { version = "0.1" } [target.'cfg(unix)'.dependencies] libc = { workspace = true } +[target.'cfg(windows)'.dependencies] +winpipe = { workspace = true } + [dev-dependencies] emojis = "0.6" jsonschema = { version = "0.30", default-features = false } diff --git a/crates/radicle/src/node.rs b/crates/radicle/src/node.rs index 93939aff..620b14d4 100644 --- a/crates/radicle/src/node.rs +++ b/crates/radicle/src/node.rs @@ -19,11 +19,15 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque}; use std::io::{BufRead, BufReader}; use std::marker::PhantomData; use std::ops::{ControlFlow, Deref}; -use std::os::unix::net::UnixStream; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::{fmt, io, net, thread, time}; +#[cfg(unix)] +use std::os::unix::net::UnixStream as Stream; +#[cfg(windows)] +use winpipe::WinStream as Stream; + use amplify::WrapperMut; use cyphernet::addr::NetAddr; use localtime::{LocalDuration, LocalTime}; @@ -1140,7 +1144,7 @@ pub trait Handle: Clone + Sync + Send { /// The iterator blocks for a `timeout` duration, returning [`Error::TimedOut`] /// if the duration is reached. pub struct LineIter { - stream: BufReader, + stream: BufReader, timeout: time::Duration, witness: PhantomData, } @@ -1204,9 +1208,9 @@ impl Node { cmd: Command, timeout: time::Duration, ) -> Result, Error> { - let stream = UnixStream::connect(&self.socket) + let mut stream = Stream::connect(&self.socket) .map_err(|e| Error::Connect(self.socket.clone(), e.kind()))?; - cmd.to_writer(&stream)?; + cmd.to_writer(&mut stream)?; Ok(LineIter { stream: BufReader::new(stream), timeout,