Skip to content

Commit 7e7483d

Browse files
committed
Auto merge of rust-lang#110152 - ChrisDenton:windows-sys, r=thomcc
Start using `windows sys` for Windows FFI bindings in std Switch to using windows-sys for FFI. In order to avoid some currently contentious issues, this uses windows-bindgen to generate a smaller set of bindings instead of using the full crate. Unlike the windows-sys crate, the generated bindings uses `*mut c_void` for handle types instead of `isize`. This to sidestep opsem concerns about mixing pointer types and integers between languages. Note that `SOCKET` remains defined as an integer but instead of being a usize, it's changed to fit the [standard library definition](https://github.com/rust-lang/rust/blob/a41fc00eaf352541008965fec0dee811e44373b3/library/std/src/os/windows/raw.rs#L12-L16): ```rust #[cfg(target_pointer_width = "32")] pub type SOCKET = u32; #[cfg(target_pointer_width = "64")] pub type SOCKET = u64; ``` The generated bindings also customizes the `#[link]` imports. I hope to switch to using raw-dylib but I don't want to tie that too closely with the switch to windows-sys. --- Changes outside of the bindings are, for the most part, fairly minimal (e.g. some differences in `*mut` vs. `*const` or a few types differ). One issue is that our own bindings sometimes mix in higher level types, like `BorrowedHandle`. This is pretty adhoc though.
2 parents 33a01e2 + e314a3b commit 7e7483d

File tree

23 files changed

+7187
-3098
lines changed

23 files changed

+7187
-3098
lines changed

Diff for: Cargo.lock

+29
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,13 @@ dependencies = [
14431443
"serde_json",
14441444
]
14451445

1446+
[[package]]
1447+
name = "generate-windows-sys"
1448+
version = "0.1.0"
1449+
dependencies = [
1450+
"windows-bindgen",
1451+
]
1452+
14461453
[[package]]
14471454
name = "generic-array"
14481455
version = "0.14.4"
@@ -5509,6 +5516,22 @@ dependencies = [
55095516
"windows-targets 0.48.0",
55105517
]
55115518

5519+
[[package]]
5520+
name = "windows-bindgen"
5521+
version = "0.49.0"
5522+
source = "registry+https://github.com/rust-lang/crates.io-index"
5523+
checksum = "b6935fb09b84ee57929ae92518b475f5dfdfbeb87c5334756acc28ee8e202b60"
5524+
dependencies = [
5525+
"windows-metadata",
5526+
"windows-tokens",
5527+
]
5528+
5529+
[[package]]
5530+
name = "windows-metadata"
5531+
version = "0.49.0"
5532+
source = "registry+https://github.com/rust-lang/crates.io-index"
5533+
checksum = "2f5bca94a32bf1e6a376522b6601275a3b611ee885ec0f1b6a05f17e8cfd3385"
5534+
55125535
[[package]]
55135536
name = "windows-sys"
55145537
version = "0.42.0"
@@ -5572,6 +5595,12 @@ dependencies = [
55725595
"windows_x86_64_msvc 0.48.0",
55735596
]
55745597

5598+
[[package]]
5599+
name = "windows-tokens"
5600+
version = "0.48.0"
5601+
source = "registry+https://github.com/rust-lang/crates.io-index"
5602+
checksum = "b34c9a3b28cb41db7385546f7f9a8179348dffc89923dde66857b1ba5312f6b4"
5603+
55755604
[[package]]
55765605
name = "windows_aarch64_gnullvm"
55775606
version = "0.42.2"

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ members = [
3939
"src/tools/collect-license-metadata",
4040
"src/tools/generate-copyright",
4141
"src/tools/suggest-tests",
42+
"src/tools/generate-windows-sys",
4243
]
4344

4445
exclude = [

Diff for: library/std/src/os/windows/io/socket.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl BorrowedSocket<'_> {
110110
/// object as the existing `BorrowedSocket` instance.
111111
#[stable(feature = "io_safety", since = "1.63.0")]
112112
pub fn try_clone_to_owned(&self) -> io::Result<OwnedSocket> {
113-
let mut info = unsafe { mem::zeroed::<c::WSAPROTOCOL_INFO>() };
113+
let mut info = unsafe { mem::zeroed::<c::WSAPROTOCOL_INFOW>() };
114114
let result = unsafe {
115115
c::WSADuplicateSocketW(self.as_raw_socket(), c::GetCurrentProcessId(), &mut info)
116116
};

0 commit comments

Comments
 (0)