From d4ed5f73ddb051ac700e1b7ee66a72905a86a05e Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Tue, 21 Jan 2025 17:24:29 -0500 Subject: [PATCH] build: allow `windows-sys` 0.59 --- Cargo.toml | 2 +- src/sys/windows.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fbb7fea9..eb985f34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ features = ["all"] libc = "0.2.150" [target.'cfg(windows)'.dependencies.windows-sys] -version = "0.52" +version = ">=0.52,<0.60" features = [ "Win32_Foundation", "Win32_Networking_WinSock", diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 8cf27b53..a427fd80 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -930,6 +930,17 @@ pub(crate) fn unix_sockaddr(path: &Path) -> io::Result { } storage.sun_family = crate::sys::AF_UNIX as sa_family_t; + + // `windows-sys` 0.52.* represents `SOCKADDR_UN::sun_path` as `&[u8]`, but 0.59.* + // represents it as `&[i8]`. + // + // TODO: Remove this once `windows-sys` 0.52.* is no longer + // permitted as a dependency. + // + // SAFETY: We are safe in doing this, because: `bytes` starts as `&[u8]`, and is converted + // to a `&[u8]` or `&[i8]`, and all of these types have the same size and alignment. + let bytes = unsafe { slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) }; + // `storage` was initialized to zero above, so the path is // already null terminated. storage.sun_path[..bytes.len()].copy_from_slice(bytes);