From f6ccb418ec77011f2a67ac1124e70a18583431a1 Mon Sep 17 00:00:00 2001
From: Erich Gubler <erichdongubler@gmail.com>
Date: Fri, 17 Jan 2025 14:50:36 -0500
Subject: [PATCH 1/2] build!: move to `windows` from
 `windows-{bindgen,core,targets}`

---
 Cargo.lock     | 136 ++-----------------------------------------------
 Cargo.toml     |  11 ++--
 build.rs       |  29 ++---------
 src/windows.rs |  29 +++++------
 4 files changed, 27 insertions(+), 178 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 03b808d0..17493c95 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -11,12 +11,6 @@ dependencies = [
  "memchr",
 ]
 
-[[package]]
-name = "autocfg"
-version = "1.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
-
 [[package]]
 name = "bindgen"
 version = "0.69.5"
@@ -75,36 +69,6 @@ dependencies = [
  "libloading",
 ]
 
-[[package]]
-name = "crossbeam-deque"
-version = "0.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
-dependencies = [
- "cfg-if",
- "crossbeam-epoch",
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-epoch"
-version = "0.9.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695"
-dependencies = [
- "autocfg",
- "cfg-if",
- "crossbeam-utils",
- "memoffset",
- "scopeguard",
-]
-
-[[package]]
-name = "crossbeam-utils"
-version = "0.8.20"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
-
 [[package]]
 name = "either"
 version = "1.8.1"
@@ -126,12 +90,6 @@ dependencies = [
  "either",
 ]
 
-[[package]]
-name = "itoa"
-version = "1.0.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
-
 [[package]]
 name = "lazy_static"
 version = "1.4.0"
@@ -166,15 +124,6 @@ version = "2.7.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
 
-[[package]]
-name = "memoffset"
-version = "0.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
-dependencies = [
- "autocfg",
-]
-
 [[package]]
 name = "minimal-lexical"
 version = "0.2.1"
@@ -196,9 +145,7 @@ dependencies = [
  "libc",
  "mozbuild",
  "static_assertions",
- "windows-bindgen",
- "windows-core",
- "windows-targets",
+ "windows",
 ]
 
 [[package]]
@@ -229,26 +176,6 @@ dependencies = [
  "proc-macro2",
 ]
 
-[[package]]
-name = "rayon"
-version = "1.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
-dependencies = [
- "either",
- "rayon-core",
-]
-
-[[package]]
-name = "rayon-core"
-version = "1.12.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
-dependencies = [
- "crossbeam-deque",
- "crossbeam-utils",
-]
-
 [[package]]
 name = "regex"
 version = "1.9.4"
@@ -284,49 +211,6 @@ version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
 
-[[package]]
-name = "ryu"
-version = "1.0.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
-
-[[package]]
-name = "scopeguard"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
-
-[[package]]
-name = "serde"
-version = "1.0.214"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5"
-dependencies = [
- "serde_derive",
-]
-
-[[package]]
-name = "serde_derive"
-version = "1.0.214"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "serde_json"
-version = "1.0.116"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
-dependencies = [
- "itoa",
- "ryu",
- "serde",
-]
-
 [[package]]
 name = "shlex"
 version = "1.3.0"
@@ -357,17 +241,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
 
 [[package]]
-name = "windows-bindgen"
+name = "windows"
 version = "0.58.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "91cd28d93c692351f3a6e5615567c56756e330bee1c99c6bdd57bfc5ab15f589"
+checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6"
 dependencies = [
- "proc-macro2",
- "rayon",
- "serde",
- "serde_json",
- "syn",
- "windows-metadata",
+ "windows-core",
+ "windows-targets",
 ]
 
 [[package]]
@@ -405,12 +285,6 @@ dependencies = [
  "syn",
 ]
 
-[[package]]
-name = "windows-metadata"
-version = "0.58.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2e837f3c3012cfe9e7086302a93f441a7999439be1ad4c530d55d2f6d2921809"
-
 [[package]]
 name = "windows-result"
 version = "0.2.0"
diff --git a/Cargo.toml b/Cargo.toml
index 3af5adce..0171bc20 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,8 +27,12 @@ static_assertions = { version = "1.1", default-features = false }
 
 [target.'cfg(windows)'.dependencies]
 # Don't increase beyond what Firefox is currently using: https://searchfox.org/mozilla-central/source/Cargo.lock
-windows-core = { version = "0.58", default-features = false }
-windows-targets = { version = "0.52", default-features = false }
+windows = { version = "0.58", features = [
+  "Win32_Foundation",
+  "Win32_NetworkManagement_IpHelper",
+  "Win32_NetworkManagement_Ndis",
+  "Win32_Networking_WinSock",
+] }
 
 [build-dependencies]
 cfg_aliases = { version = "0.2", default-features = false }
@@ -38,9 +42,6 @@ mozbuild = { version = "0.1", default-features = false, optional = true }
 # Don't increase beyond what Firefox is currently using: https://searchfox.org/mozilla-central/source/Cargo.lock
 bindgen = { version = "0.69", default-features = false, features = ["runtime"] }
 
-[target.'cfg(windows)'.build-dependencies]
-windows-bindgen = { version = "0.58", default-features = false, features = ["metadata"] }
-
 [features]
 gecko = ["dep:mozbuild"]
 
diff --git a/build.rs b/build.rs
index fc5d18d0..f137ace6 100644
--- a/build.rs
+++ b/build.rs
@@ -6,6 +6,7 @@
 
 #![allow(clippy::unwrap_used)] // OK in build scripts.
 
+#[cfg(not(windows))]
 const BINDINGS: &str = "bindings.rs";
 
 #[cfg(feature = "gecko")]
@@ -79,32 +80,6 @@ fn bindgen() {
     println!("cargo:rustc-env=BINDINGS={}", out_path.display());
 }
 
-#[cfg(windows)]
-fn bindgen() {
-    let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()).join(BINDINGS);
-    windows_bindgen::bindgen([
-        "--out",
-        out_path.to_str().unwrap(),
-        "--config",
-        "flatten",
-        "no-inner-attributes",
-        "minimal",
-        "--filter",
-        "Windows.Win32.Foundation.NO_ERROR",
-        "Windows.Win32.Networking.WinSock.AF_INET",
-        "Windows.Win32.Networking.WinSock.AF_INET6",
-        "Windows.Win32.Networking.WinSock.SOCKADDR_INET",
-        "Windows.Win32.NetworkManagement.IpHelper.FreeMibTable",
-        "Windows.Win32.NetworkManagement.IpHelper.GetBestInterfaceEx",
-        "Windows.Win32.NetworkManagement.IpHelper.GetIpInterfaceTable",
-        "Windows.Win32.NetworkManagement.IpHelper.if_indextoname",
-        "Windows.Win32.NetworkManagement.IpHelper.MIB_IPINTERFACE_ROW",
-        "Windows.Win32.NetworkManagement.Ndis.IF_MAX_STRING_SIZE",
-    ])
-    .expect("Couldn't write bindings!");
-    println!("cargo:rustc-env=BINDINGS={}", out_path.display());
-}
-
 fn main() {
     // Setup cfg aliases
     cfg_aliases::cfg_aliases! {
@@ -126,5 +101,7 @@ fn main() {
             )
         }
     }
+
+    #[cfg(not(windows))]
     bindgen();
 }
diff --git a/src/windows.rs b/src/windows.rs
index 1a6320be..f82abc28 100644
--- a/src/windows.rs
+++ b/src/windows.rs
@@ -13,22 +13,19 @@ use std::{
 
 use crate::default_err;
 
-#[allow(
-    non_camel_case_types,
-    non_snake_case,
-    clippy::semicolon_if_nothing_returned,
-    clippy::missing_transmute_annotations,
-    clippy::upper_case_acronyms,
-    clippy::struct_field_names
-)]
-mod bindings {
-    include!(env!("BINDINGS"));
-}
-
-use bindings::{
-    if_indextoname, FreeMibTable, GetBestInterfaceEx, GetIpInterfaceTable, AF_INET, AF_INET6,
-    IF_MAX_STRING_SIZE, IN6_ADDR, IN6_ADDR_0, IN_ADDR, IN_ADDR_0, MIB_IPINTERFACE_ROW,
-    MIB_IPINTERFACE_TABLE, NO_ERROR, SOCKADDR, SOCKADDR_IN, SOCKADDR_IN6, SOCKADDR_INET,
+use windows::{
+    Win32::Foundation::NO_ERROR,
+    Win32::NetworkManagement::{
+        IpHelper::{
+            if_indextoname, FreeMibTable, GetBestInterfaceEx, GetIpInterfaceTable,
+            MIB_IPINTERFACE_ROW, MIB_IPINTERFACE_TABLE,
+        },
+        Ndis::IF_MAX_STRING_SIZE,
+    },
+    Win32::Networking::WinSock::{
+        AF_INET, AF_INET6, IN6_ADDR, IN6_ADDR_0, IN_ADDR, IN_ADDR_0, SOCKADDR, SOCKADDR_IN,
+        SOCKADDR_IN6, SOCKADDR_INET,
+    },
 };
 
 struct MibTablePtr(*mut MIB_IPINTERFACE_TABLE);

From 4afd54a930f99087191c2acb7aaeba950de249b4 Mon Sep 17 00:00:00 2001
From: Erich Gubler <erichdongubler@gmail.com>
Date: Fri, 17 Jan 2025 14:58:05 -0500
Subject: [PATCH 2/2] build: expand `windows` version range to include 0.59

---
 Cargo.toml     |  2 +-
 src/windows.rs | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 0171bc20..143afcd3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,7 @@ static_assertions = { version = "1.1", default-features = false }
 
 [target.'cfg(windows)'.dependencies]
 # Don't increase beyond what Firefox is currently using: https://searchfox.org/mozilla-central/source/Cargo.lock
-windows = { version = "0.58", features = [
+windows = { version = ">=0.58,<0.60", features = [
   "Win32_Foundation",
   "Win32_NetworkManagement_IpHelper",
   "Win32_NetworkManagement_Ndis",
diff --git a/src/windows.rs b/src/windows.rs
index f82abc28..cb28eda1 100644
--- a/src/windows.rs
+++ b/src/windows.rs
@@ -11,23 +11,23 @@ use std::{
     ptr, slice,
 };
 
-use crate::default_err;
-
-use windows::{
-    Win32::Foundation::NO_ERROR,
-    Win32::NetworkManagement::{
+use windows::Win32::{
+    Foundation::NO_ERROR,
+    NetworkManagement::{
         IpHelper::{
             if_indextoname, FreeMibTable, GetBestInterfaceEx, GetIpInterfaceTable,
             MIB_IPINTERFACE_ROW, MIB_IPINTERFACE_TABLE,
         },
         Ndis::IF_MAX_STRING_SIZE,
     },
-    Win32::Networking::WinSock::{
+    Networking::WinSock::{
         AF_INET, AF_INET6, IN6_ADDR, IN6_ADDR_0, IN_ADDR, IN_ADDR_0, SOCKADDR, SOCKADDR_IN,
         SOCKADDR_IN6, SOCKADDR_INET,
     },
 };
 
+use crate::default_err;
+
 struct MibTablePtr(*mut MIB_IPINTERFACE_TABLE);
 
 impl MibTablePtr {
