From 685a1efe347bff0986f19acaa629d4c08bd2c461 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 7 Jan 2025 11:21:19 -0600 Subject: [PATCH] Update `windows-bindgen` dependency (#1347) --- dev-tools/gen-windows-sys-binding/Cargo.toml | 2 +- dev-tools/gen-windows-sys-binding/src/main.rs | 31 ++---- .../gen-windows-sys-binding/windows_sys.list | 98 +++++++++---------- src/windows/windows_sys.rs | 29 ++++-- 4 files changed, 80 insertions(+), 80 deletions(-) diff --git a/dev-tools/gen-windows-sys-binding/Cargo.toml b/dev-tools/gen-windows-sys-binding/Cargo.toml index 12d9f2764..9b0309b08 100644 --- a/dev-tools/gen-windows-sys-binding/Cargo.toml +++ b/dev-tools/gen-windows-sys-binding/Cargo.toml @@ -5,6 +5,6 @@ edition = "2018" publish = false [dependencies] -windows-bindgen = "0.58" +windows-bindgen = "0.59" tempfile = "3" regex = "1" diff --git a/dev-tools/gen-windows-sys-binding/src/main.rs b/dev-tools/gen-windows-sys-binding/src/main.rs index ef7c15f3d..c4067d33c 100644 --- a/dev-tools/gen-windows-sys-binding/src/main.rs +++ b/dev-tools/gen-windows-sys-binding/src/main.rs @@ -20,36 +20,23 @@ const PRELUDE: &str = r#"// This file is autogenerated. fn main() { let manifest_dir = env!("CARGO_MANIFEST_DIR"); + let filter = format!("{manifest_dir}/windows_sys.list"); let temp_file = tempfile::Builder::new() .suffix(".rs") .tempfile() .expect("failed to create temp file"); - // Common args to windows_bindgen. - let mut args = vec![ - "--config", - "flatten", - "sys", - "minimal", + // Generate bindings. + windows_bindgen::bindgen([ + "--flat", + "--sys", + "--no-core", "--out", temp_file.path().to_str().unwrap(), "--filter", - ]; - - // Append the list of APIs - let buffer = fs::read_to_string(format!("{manifest_dir}/windows_sys.list")) - .expect("failed to read list"); - args.extend(buffer.lines().filter_map(|line| { - let line = line.trim(); - if line.is_empty() || line.starts_with("//") { - None - } else { - Some(line) - } - })); - - // Generate bindings. - windows_bindgen::bindgen(&args).expect("running bindgen failed"); + "--etc", + &filter, + ]); let bindings = fs::read_to_string(temp_file.path()).expect("failed to read temp windows_sys.rs"); diff --git a/dev-tools/gen-windows-sys-binding/windows_sys.list b/dev-tools/gen-windows-sys-binding/windows_sys.list index bc1889577..ceb74c847 100644 --- a/dev-tools/gen-windows-sys-binding/windows_sys.list +++ b/dev-tools/gen-windows-sys-binding/windows_sys.list @@ -1,49 +1,49 @@ -Windows.Win32.Foundation.FILETIME -Windows.Win32.Foundation.ERROR_NO_MORE_ITEMS -Windows.Win32.Foundation.ERROR_SUCCESS -Windows.Win32.Foundation.SysFreeString -Windows.Win32.Foundation.SysStringLen -Windows.Win32.Foundation.S_FALSE -Windows.Win32.Foundation.S_OK -Windows.Win32.Foundation.FALSE -Windows.Win32.Foundation.HANDLE -Windows.Win32.Foundation.WAIT_OBJECT_0 -Windows.Win32.Foundation.WAIT_TIMEOUT -Windows.Win32.Foundation.WAIT_FAILED -Windows.Win32.Foundation.WAIT_ABANDONED -Windows.Win32.Foundation.FreeLibrary - -Windows.Win32.System.Com.SAFEARRAY -Windows.Win32.System.Com.SAFEARRAYBOUND -Windows.Win32.System.Com.CLSCTX_ALL -Windows.Win32.System.Com.COINIT_MULTITHREADED -Windows.Win32.System.Com.CoCreateInstance -Windows.Win32.System.Com.CoInitializeEx - -Windows.Win32.System.LibraryLoader.GetProcAddress -Windows.Win32.System.LibraryLoader.LoadLibraryA - -Windows.Win32.System.Pipes.PeekNamedPipe - -Windows.Win32.System.Registry.RegCloseKey -Windows.Win32.System.Registry.RegEnumKeyExW -Windows.Win32.System.Registry.RegOpenKeyExW -Windows.Win32.System.Registry.RegQueryValueExW -Windows.Win32.System.Registry.HKEY -Windows.Win32.System.Registry.HKEY_LOCAL_MACHINE -Windows.Win32.System.Registry.KEY_READ -Windows.Win32.System.Registry.KEY_WOW64_32KEY -Windows.Win32.System.Registry.REG_SZ - -Windows.Win32.System.SystemInformation.IMAGE_FILE_MACHINE_AMD64 - -Windows.Win32.Storage.FileSystem.FILE_ATTRIBUTE_TEMPORARY - -Windows.Win32.System.Threading.GetMachineTypeAttributes -Windows.Win32.System.Threading.ReleaseSemaphore -Windows.Win32.System.Threading.WaitForSingleObject -Windows.Win32.System.Threading.SEMAPHORE_MODIFY_STATE -Windows.Win32.System.Threading.THREAD_SYNCHRONIZE -Windows.Win32.System.Threading.UserEnabled - -Windows.Win32.System.WindowsProgramming.OpenSemaphoreA +FILETIME +ERROR_NO_MORE_ITEMS +ERROR_SUCCESS +SysFreeString +SysStringLen +S_FALSE +S_OK +FALSE +HANDLE +WAIT_OBJECT_0 +WAIT_TIMEOUT +WAIT_FAILED +WAIT_ABANDONED +FreeLibrary + +SAFEARRAY +SAFEARRAYBOUND +CLSCTX_ALL +COINIT_MULTITHREADED +CoCreateInstance +CoInitializeEx + +GetProcAddress +LoadLibraryA + +PeekNamedPipe + +RegCloseKey +RegEnumKeyExW +RegOpenKeyExW +RegQueryValueExW +HKEY +HKEY_LOCAL_MACHINE +KEY_READ +KEY_WOW64_32KEY +REG_SZ + +IMAGE_FILE_MACHINE_AMD64 + +FILE_ATTRIBUTE_TEMPORARY + +GetMachineTypeAttributes +ReleaseSemaphore +WaitForSingleObject +SEMAPHORE_MODIFY_STATE +THREAD_SYNCHRONIZE +UserEnabled + +OpenSemaphoreA diff --git a/src/windows/windows_sys.rs b/src/windows/windows_sys.rs index fd177e658..376a281fb 100644 --- a/src/windows/windows_sys.rs +++ b/src/windows/windows_sys.rs @@ -6,7 +6,7 @@ // cd generate-windows-sys/ // cargo run // ``` -// Bindings generated by `windows-bindgen` 0.58.0 +// Bindings generated by `windows-bindgen` 0.59.0 #![allow( non_snake_case, @@ -15,22 +15,23 @@ dead_code, clippy::all )] -windows_targets::link!("advapi32.dll" "system" fn RegCloseKey(hkey : HKEY) -> WIN32_ERROR); -windows_targets::link!("advapi32.dll" "system" fn RegEnumKeyExW(hkey : HKEY, dwindex : u32, lpname : PWSTR, lpcchname : *mut u32, lpreserved : *const u32, lpclass : PWSTR, lpcchclass : *mut u32, lpftlastwritetime : *mut FILETIME) -> WIN32_ERROR); -windows_targets::link!("advapi32.dll" "system" fn RegOpenKeyExW(hkey : HKEY, lpsubkey : PCWSTR, uloptions : u32, samdesired : REG_SAM_FLAGS, phkresult : *mut HKEY) -> WIN32_ERROR); -windows_targets::link!("advapi32.dll" "system" fn RegQueryValueExW(hkey : HKEY, lpvaluename : PCWSTR, lpreserved : *const u32, lptype : *mut REG_VALUE_TYPE, lpdata : *mut u8, lpcbdata : *mut u32) -> WIN32_ERROR); + +windows_targets::link!("ole32.dll" "system" fn CoCreateInstance(rclsid : *const GUID, punkouter : * mut core::ffi::c_void, dwclscontext : CLSCTX, riid : *const GUID, ppv : *mut *mut core::ffi::c_void) -> HRESULT); +windows_targets::link!("ole32.dll" "system" fn CoInitializeEx(pvreserved : *const core::ffi::c_void, dwcoinit : u32) -> HRESULT); windows_targets::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : HMODULE) -> BOOL); windows_targets::link!("kernel32.dll" "system" fn GetMachineTypeAttributes(machine : u16, machinetypeattributes : *mut MACHINE_ATTRIBUTES) -> HRESULT); windows_targets::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : PCSTR) -> FARPROC); windows_targets::link!("kernel32.dll" "system" fn LoadLibraryA(lplibfilename : PCSTR) -> HMODULE); windows_targets::link!("kernel32.dll" "system" fn OpenSemaphoreA(dwdesiredaccess : u32, binherithandle : BOOL, lpname : PCSTR) -> HANDLE); windows_targets::link!("kernel32.dll" "system" fn PeekNamedPipe(hnamedpipe : HANDLE, lpbuffer : *mut core::ffi::c_void, nbuffersize : u32, lpbytesread : *mut u32, lptotalbytesavail : *mut u32, lpbytesleftthismessage : *mut u32) -> BOOL); +windows_targets::link!("advapi32.dll" "system" fn RegCloseKey(hkey : HKEY) -> WIN32_ERROR); +windows_targets::link!("advapi32.dll" "system" fn RegEnumKeyExW(hkey : HKEY, dwindex : u32, lpname : PWSTR, lpcchname : *mut u32, lpreserved : *const u32, lpclass : PWSTR, lpcchclass : *mut u32, lpftlastwritetime : *mut FILETIME) -> WIN32_ERROR); +windows_targets::link!("advapi32.dll" "system" fn RegOpenKeyExW(hkey : HKEY, lpsubkey : PCWSTR, uloptions : u32, samdesired : REG_SAM_FLAGS, phkresult : *mut HKEY) -> WIN32_ERROR); +windows_targets::link!("advapi32.dll" "system" fn RegQueryValueExW(hkey : HKEY, lpvaluename : PCWSTR, lpreserved : *const u32, lptype : *mut REG_VALUE_TYPE, lpdata : *mut u8, lpcbdata : *mut u32) -> WIN32_ERROR); windows_targets::link!("kernel32.dll" "system" fn ReleaseSemaphore(hsemaphore : HANDLE, lreleasecount : i32, lppreviouscount : *mut i32) -> BOOL); -windows_targets::link!("kernel32.dll" "system" fn WaitForSingleObject(hhandle : HANDLE, dwmilliseconds : u32) -> WAIT_EVENT); -windows_targets::link!("ole32.dll" "system" fn CoCreateInstance(rclsid : *const GUID, punkouter : * mut core::ffi::c_void, dwclscontext : CLSCTX, riid : *const GUID, ppv : *mut *mut core::ffi::c_void) -> HRESULT); -windows_targets::link!("ole32.dll" "system" fn CoInitializeEx(pvreserved : *const core::ffi::c_void, dwcoinit : u32) -> HRESULT); windows_targets::link!("oleaut32.dll" "system" fn SysFreeString(bstrstring : BSTR)); windows_targets::link!("oleaut32.dll" "system" fn SysStringLen(pbstr : BSTR) -> u32); +windows_targets::link!("kernel32.dll" "system" fn WaitForSingleObject(hhandle : HANDLE, dwmilliseconds : u32) -> WAIT_EVENT); pub type ADVANCED_FEATURE_FLAGS = u16; pub type BOOL = i32; pub type BSTR = *const u16; @@ -69,12 +70,24 @@ impl GUID { } } pub type HANDLE = *mut core::ffi::c_void; +pub type HINSTANCE = *mut core::ffi::c_void; pub type HKEY = *mut core::ffi::c_void; pub const HKEY_LOCAL_MACHINE: HKEY = -2147483646i32 as _; pub type HMODULE = *mut core::ffi::c_void; pub type HRESULT = i32; pub type IMAGE_FILE_MACHINE = u16; pub const IMAGE_FILE_MACHINE_AMD64: IMAGE_FILE_MACHINE = 34404u16; +pub const IID_IUnknown: GUID = GUID::from_u128(0x00000000_0000_0000_c000_000000000046); +#[repr(C)] +pub struct IUnknown_Vtbl { + pub QueryInterface: unsafe extern "system" fn( + this: *mut core::ffi::c_void, + iid: *const GUID, + interface: *mut *mut core::ffi::c_void, + ) -> HRESULT, + pub AddRef: unsafe extern "system" fn(this: *mut core::ffi::c_void) -> u32, + pub Release: unsafe extern "system" fn(this: *mut core::ffi::c_void) -> u32, +} pub const KEY_READ: REG_SAM_FLAGS = 131097u32; pub const KEY_WOW64_32KEY: REG_SAM_FLAGS = 512u32; pub type MACHINE_ATTRIBUTES = i32;