Skip to content

Commit 625bcc4

Browse files
authoredJul 5, 2024
Rollup merge of rust-lang#127320 - ChrisDenton:win-sys, r=Mark-Simulacrum
Update windows-bindgen to 0.58.0 This also switches from the bespoke `std` generated bindings to the normal `sys` ones everyone else uses. This has almost no difference except that the `sys` bindings use the `windows_targets::links!` macro for FFI imports, which we implement manually. This does cause the diff to look much larger than it really is but the bulk of the changes are mostly contained to the generated code.
2 parents f8caf5f + 515bd30 commit 625bcc4

File tree

5 files changed

+162
-851
lines changed

5 files changed

+162
-851
lines changed
 

‎std/src/sys/pal/windows/c.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use crate::os::raw::{c_char, c_long, c_longlong, c_uint, c_ulong, c_ushort, c_vo
1313
use crate::os::windows::io::{AsRawHandle, BorrowedHandle};
1414
use crate::ptr;
1515

16+
mod windows_targets;
17+
1618
mod windows_sys;
1719
pub use windows_sys::*;
1820

@@ -504,11 +506,8 @@ if #[cfg(not(target_vendor = "uwp"))] {
504506
#[cfg(target_arch = "arm")]
505507
pub enum CONTEXT {}
506508
}}
507-
508-
#[link(name = "ws2_32")]
509-
extern "system" {
510-
pub fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32;
511-
}
509+
// WSAStartup is only redefined here so that we can override WSADATA for Arm32
510+
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32);
512511
#[cfg(target_arch = "arm")]
513512
#[repr(C)]
514513
pub struct WSADATA {

‎std/src/sys/pal/windows/c/bindings.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--out windows_sys.rs
2-
--config flatten std
2+
--config flatten sys
33
--filter
44
!Windows.Win32.Foundation.INVALID_HANDLE_VALUE
55
Windows.Wdk.Storage.FileSystem.FILE_COMPLETE_IF_OPLOCKED

‎std/src/sys/pal/windows/c/windows_sys.rs

+132-838
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Provides the `link!` macro used by the generated windows bindings.
2+
//!
3+
//! This is a simple wrapper around an `extern` block with a `#[link]` attribute.
4+
//! It's very roughly equivalent to the windows-targets crate.
5+
6+
pub macro link {
7+
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
8+
// Note: the windows-targets crate uses a pre-built Windows.lib import library which we don't
9+
// have in this repo. So instead we always link kernel32.lib and add the rest of the import
10+
// libraries below by using an empty extern block. This works because extern blocks are not
11+
// connected to the library given in the #[link] attribute.
12+
#[link(name = "kernel32")]
13+
extern $abi {
14+
$(#[link_name=$link_name])?
15+
pub fn $($function)*;
16+
}
17+
)
18+
}
19+
20+
#[link(name = "advapi32")]
21+
#[link(name = "ntdll")]
22+
#[link(name = "userenv")]
23+
#[link(name = "ws2_32")]
24+
extern "C" {}

‎std/src/sys/pal/windows/stdio.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,7 @@ fn write_u16s(handle: c::HANDLE, data: &[u16]) -> io::Result<usize> {
232232
debug_assert!(data.len() < u32::MAX as usize);
233233
let mut written = 0;
234234
cvt(unsafe {
235-
c::WriteConsoleW(
236-
handle,
237-
data.as_ptr() as c::LPCVOID,
238-
data.len() as u32,
239-
&mut written,
240-
ptr::null_mut(),
241-
)
235+
c::WriteConsoleW(handle, data.as_ptr(), data.len() as u32, &mut written, ptr::null_mut())
242236
})?;
243237
Ok(written as usize)
244238
}

0 commit comments

Comments
 (0)
Please sign in to comment.