Skip to content

windows-bindgen 0.60 generates bindings that depend on windows_sys #3510

@djc

Description

@djc

Summary

In trying to upgrade chrono from -bindgen 0.59 to 0.60, I'm seeing this diff:

diff --git a/src/offset/local/win_bindings.rs b/src/offset/local/win_bindings.rs
index f2def25e..79474490 100644
--- a/src/offset/local/win_bindings.rs
+++ b/src/offset/local/win_bindings.rs
@@ -1,10 +1,9 @@
 #![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]
 
-windows_targets::link!("kernel32.dll" "system" fn GetTimeZoneInformationForYear(wyear : u16, pdtzi : *const DYNAMIC_TIME_ZONE_INFORMATION, ptzi : *mut TIME_ZONE_INFORMATION) -> BOOL);
-windows_targets::link!("kernel32.dll" "system" fn SystemTimeToFileTime(lpsystemtime : *const SYSTEMTIME, lpfiletime : *mut FILETIME) -> BOOL);
-windows_targets::link!("kernel32.dll" "system" fn SystemTimeToTzSpecificLocalTime(lptimezoneinformation : *const TIME_ZONE_INFORMATION, lpuniversaltime : *const SYSTEMTIME, lplocaltime : *mut SYSTEMTIME) -> BOOL);
-windows_targets::link!("kernel32.dll" "system" fn TzSpecificLocalTimeToSystemTime(lptimezoneinformation : *const TIME_ZONE_INFORMATION, lplocaltime : *const SYSTEMTIME, lpuniversaltime : *mut SYSTEMTIME) -> BOOL);
-pub type BOOL = i32;
+windows_link::link!("kernel32.dll" "system" fn GetTimeZoneInformationForYear(wyear : u16, pdtzi : *const DYNAMIC_TIME_ZONE_INFORMATION, ptzi : *mut TIME_ZONE_INFORMATION) -> windows_sys::core::BOOL);
+windows_link::link!("kernel32.dll" "system" fn SystemTimeToFileTime(lpsystemtime : *const SYSTEMTIME, lpfiletime : *mut FILETIME) -> windows_sys::core::BOOL);
+windows_link::link!("kernel32.dll" "system" fn SystemTimeToTzSpecificLocalTime(lptimezoneinformation : *const TIME_ZONE_INFORMATION, lpuniversaltime : *const SYSTEMTIME, lplocaltime : *mut SYSTEMTIME) -> windows_sys::core::BOOL);
+windows_link::link!("kernel32.dll" "system" fn TzSpecificLocalTimeToSystemTime(lptimezoneinformation : *const TIME_ZONE_INFORMATION, lplocaltime : *const SYSTEMTIME, lpuniversaltime : *mut SYSTEMTIME) -> windows_sys::core::BOOL);
 #[repr(C)]
 #[derive(Clone, Copy)]
 pub struct DYNAMIC_TIME_ZONE_INFORMATION {

Note that the generated code contains the return type of windows_sys::core::BOOL, but part of the goal of using windows-bindgen is that we can avoid the dependency on windows-sys.

Crate manifest

[target.'cfg(windows)'.dependencies]
windows-link = { version = "0.1", optional = true }
[target.'cfg(windows)'.dev-dependencies]
windows-bindgen = { version = "0.60" } # MSRV is 1.74

Crate code

use std::fs;
use windows_bindgen::bindgen;

#[test]
fn gen_bindings() {
    let input = "src/offset/local/win_bindings.txt";
    let output = "src/offset/local/win_bindings.rs";
    let existing = fs::read_to_string(output).unwrap();

    bindgen(["--etc", input]);

    // Check the output is the same as before.
    // Depending on the git configuration the file may have been checked out with `\r\n` newlines or
    // with `\n`. Compare line-by-line to ignore this difference.
    let mut new = fs::read_to_string(output).unwrap();
    if existing.contains("\r\n") && !new.contains("\r\n") {
        new = new.replace("\n", "\r\n");
    } else if !existing.contains("\r\n") && new.contains("\r\n") {
        new = new.replace("\r\n", "\n");
    }

    similar_asserts::assert_eq!(existing, new);
    if !new.lines().eq(existing.lines()) {
        panic!("generated file `{}` is changed.", output);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions