Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update windows-bindgen dependency #1347

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-tools/gen-windows-sys-binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ edition = "2018"
publish = false

[dependencies]
windows-bindgen = "0.58"
windows-bindgen = "0.59"
tempfile = "3"
regex = "1"
31 changes: 9 additions & 22 deletions dev-tools/gen-windows-sys-binding/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
98 changes: 49 additions & 49 deletions dev-tools/gen-windows-sys-binding/windows_sys.list
Original file line number Diff line number Diff line change
@@ -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
29 changes: 21 additions & 8 deletions src/windows/windows_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
}
Comment on lines +73 to +90
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I wonder why these are added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The metadata used to described HMODULE - required by FreeLibrary and friends - actually depends on HINSTANCE.

image

Similarly, CoCreateInstance depends on IUnknown.

This is what I meant by the following in the PR description:

There are a handful of additional types in the output. Those reflect a more complete representation of the requested filters and their dependencies.

The bindgen crate doesn't know whether you actually need these dependencies but it includes them as there are cases where they are definitely required.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, thanks for the detailed explanation!

pub const KEY_READ: REG_SAM_FLAGS = 131097u32;
pub const KEY_WOW64_32KEY: REG_SAM_FLAGS = 512u32;
pub type MACHINE_ATTRIBUTES = i32;
Expand Down
Loading