Skip to content

Commit

Permalink
Generate bindings for required symbols only
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Sep 3, 2024
1 parent fbf8d71 commit caf8bea
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ windows = { version = "0.58", default-features = false, features = [
"Win32_NetworkManagement_Ndis",
"Win32_Networking_WinSock",
] }
windows-targets = "0.52"

[target."cfg(windows)".dev-dependencies]
windows-bindgen = { version = "0.58" } # MSRV is 1.70

[lints.clippy]
cargo = { level = "warn", priority = -1 }
Expand Down
38 changes: 38 additions & 0 deletions tests/win_bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#![cfg(windows)]

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

#[test]
fn gen_bindings() {
let existing = fs::read_to_string(TARGET).unwrap();
let new = windows_bindgen::bindgen([
"--out",
TARGET,
"--config",
"flatten",
"--filter",
"Windows.Win32.Foundation.NO_ERROR",
"Windows.Win32.NetworkManagement.IpHelper.FreeMibTable",
"Windows.Win32.NetworkManagement.IpHelper.GetIpInterfaceTable",
"Windows.Win32.NetworkManagement.IpHelper.GetUnicastIpAddressTable",
"Windows.Win32.NetworkManagement.IpHelper.MIB_IPINTERFACE_ROW",
"Windows.Win32.NetworkManagement.IpHelper.MIB_IPINTERFACE_TABLE",
"Windows.Win32.NetworkManagement.IpHelper.MIB_UNICASTIPADDRESS_ROW",
"Windows.Win32.NetworkManagement.IpHelper.MIB_UNICASTIPADDRESS_TABLE",
"Windows.Win32.Networking.WinSock.AF_INET",
"Windows.Win32.Networking.WinSock.AF_INET6",
"Windows.Win32.Networking.WinSock.AF_UNSPEC",
])
.unwrap();

// 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 new = fs::read_to_string(TARGET).unwrap();
if !new.lines().eq(existing.lines()) {
panic!("generated file `{TARGET}` is changed");
}
}

const TARGET: &str = "src/win_bindings.rs";

0 comments on commit caf8bea

Please sign in to comment.