Skip to content

Commit

Permalink
build: allow windows-sys 0.59
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jan 22, 2025
1 parent c9b13f3 commit cdd3f30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,17 @@ pub(crate) fn unix_sockaddr(path: &Path) -> io::Result<SockAddr> {
}

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);
Expand Down

0 comments on commit cdd3f30

Please sign in to comment.