Skip to content

Conversation

@kouhe3
Copy link
Contributor

@kouhe3 kouhe3 commented Oct 4, 2025

r? rust-lang/libs-api

Summary

This PR adds Unix-domain socket support to the Windows port of the standard library,
mirroring the existing APIs in std::os::unix::net.
The implementation is gated behind the unstable feature windows_unix_domain_sockets;
track issue #56533 .

Motivation / Background

Windows 10 17063+ officially support AF_UNIX.
Having the same UnixStream / UnixListener surface on Windows removes the need for
crates such as mio-uds-windows and lets cross-platform code use a single API.

Acknowledgements

most of the code was transplanted from
https://github.com/Azure/mio-uds-windows
(thank you @damonbarry ).
The main delta is switching from the winapi crate to the std.

What is added

module public items
std::os::windows::net UnixStream, UnixListener, SocketAddr, sockaddr_un

All types mirror their Unix counterparts and implement the usual
Read+Write, AsRawSocket/FromRawSocket/IntoRawSocket, AsSocket, etc.

Feature gate

#![cfg(all(windows, feature = "windows_unix_domain_sockets"))]
#![unstable(feature = "windows_unix_domain_sockets", issue = "56533")]

Testing

Can't run test because rustc ICE

How to try it locally

$ git checkout <your-branch>
$ ./x.py build library --stage 1
$ ./x.py test  library
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::UnixListener;

Notes for reviewers

  • No unsafe blocks outside sys::pal::windows.
  • All unsafe is restricted to WSASocketW, bind, connect, getsockname, getpeername.
  • sockaddr_un construction follows the Unix implementation: zero-init, copy path, null-term.
  • Drop impl is reused from sys::net::Socket, so closesocket always runs.

Commit message

std::os::windows::net: initial Unix-domain socket support
Adds unstable `windows_unix_domain_sockets` feature that exposes
`UnixStream` and `UnixListener` on Windows 10 17063+.

Code is largely taken from Azure/mio-uds-windows
Co-authored-by: kouhe3
Acked-by: 

Checklist before clicking “Create pull request”

  • ./x.py fmt - clean
  • ./x.py test - passed

@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 4, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 4, 2025
@kouhe3 kouhe3 changed the title Win af unix std::os::windows::net: add Unix-domain socket support (AF_UNIX on Windows) Oct 4, 2025
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Oct 4, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Oct 4, 2025

☔ The latest upstream changes (presumably #147340) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# This will eventually be the default.
windows_raw_dylib = ["windows-targets/windows_raw_dylib"]

windows_unix_domain_sockets = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unneeded unless something in the standard library is going to be doing cfg(feature = "windows_unix_domain_sockets"). Standard library nightly features feature(windows_unix_domain_sockets) are not supposed to be listed in this file.

Comment on lines 32 to 33
#[cfg(windows)]
pub mod net;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std::windows module does something unusual with cfg(doc) to render omnibus documentation that includes all platform-specific APIs from mutually exclusive platforms (e.g. windows-specific and unix-specific in the same documentation build). See library/std/src/os/mod.rs and https://doc.rust-lang.org/1.91.0/std/os/windows/index.html.

By putting cfg(windows) here, none of this will appear in rendered standard library documentation.

Please look into how the other contents of std::windows use cfg and follow the same approach. If that is not possible, please document this line explaining why it is done differently.

@@ -0,0 +1,8 @@
#![unstable(feature = "windows_unix_domain_sockets", issue = "56533")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the code was transplanted from https://github.com/Azure/mio-uds-windows

I am not sure that's going to be allowed. The mio-uds-windows repo is MIT licensed only whereas the standard library is dual licensed.

rust/COPYRIGHT

Lines 17 to 19 in 20383c9

Except as otherwise noted, Rust is licensed under the Apache License, Version
2.0 <LICENSE-APACHE> or <http://www.apache.org/licenses/LICENSE-2.0> or the MIT
license <LICENSE-MIT> or <http://opensource.org/licenses/MIT>, at your option.

We cannot legally take MIT-only code and unilaterally relicense it to Apache 2.0. One of the following needs to happen:

  1. The upstream code needs to be relicensed.

  2. The upstream copyright holder needs to grant Rust the right to take the code under a different license.

  3. The actual license of the domain socket code for Windows needs to be explained in the standard library source code sufficiently clearly to fall under "as otherwise noted".

  4. The contribution needs to be rewritten by somebody else without reference to copyrighted material from the original implementation.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 4, 2025
@rust-log-analyzer

This comment has been minimized.

@kouhe3
Copy link
Contributor Author

kouhe3 commented Nov 4, 2025

Hi @damonbarry,

I'm currently working on adding Unix Domain Socket support for Windows to the Rust standard library. My implementation is based on your mio-uds-windows repository, but I've adapted it to use Rust's standard Windows bindings instead of windows-rs.

I've submitted a PR to the Rust repository, and now need to address the licensing compatibility. Your project uses the MIT license, while Rust uses dual MIT/Apache-2.0 licensing.

Would you be willing to allow your code to be used in the Rust standard library under the Rust project's dual licensing terms (MIT/Apache-2.0)? This would help ensure the UDS functionality can be properly integrated into std.

The changes I made primarily involve replacing the windows-rs dependencies with std's Windows bindings, while maintaining the core logic and structure from your implementation.

Please let me know if you're comfortable with this usage. If you have any questions or need more details about the implementation, I'd be happy to provide them.

Thank you for your great work on mio-uds-windows!

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Nov 4, 2025
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels Nov 4, 2025
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] addr2line test:false 0.522
[RUSTC-TIMING] object test:false 6.424
    Checking std v0.0.0 (/checkout/library/std)
 Documenting std v0.0.0 (/checkout/library/std)
error[E0432]: unresolved imports `crate::sys::c`, `crate::sys::c`
 --> library/std/src/os/windows/net/addr.rs:6:17
  |
6 | use crate::sys::c::{self, SOCKADDR};
  |                 ^   ^^^^ no `c` in `sys`
  |                 |
  |                 could not find `c` in `sys`
  |
  = note: crate `crate::sys::net::connection::socket::c` exists but is inaccessible

error[E0432]: unresolved imports `crate::sys::c`, `crate::sys::c`
  --> library/std/src/os/windows/net/listener.rs:11:17
   |
11 | use crate::sys::c::{self, AF_UNIX, SOCK_STREAM, bind, getsockname, listen};
   |                 ^   ^^^^ no `c` in `sys`
   |                 |
   |                 could not find `c` in `sys`
   |
   = note: crate `crate::sys::net::connection::socket::c` exists but is inaccessible

---
For more information about this error, try `rustc --explain E0432`.
error: could not document `std`
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] std test:false 7.032
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo doc --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color always --release -p alloc -p compiler_builtins -p core -p panic_abort -p panic_unwind -p proc_macro -p rustc-std-workspace-core -p std -p std_detect -p sysroot -p test -p unwind --features 'backtrace panic-unwind compiler-builtins-c' --manifest-path /checkout/library/sysroot/Cargo.toml --no-deps --target-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/doc -Zskip-rustdoc-fingerprint -Zrustdoc-map [workdir=/checkout]` failed with exit code 101
Created at: src/bootstrap/src/core/build_steps/doc.rs:781:21
Executed at: src/bootstrap/src/core/build_steps/doc.rs:814:22

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `--stage 2 test --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Build completed unsuccessfully in 0:32:13
  local time: Tue Nov  4 15:36:51 UTC 2025
  network time: Tue, 04 Nov 2025 15:36:52 GMT
##[error]Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants