Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
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
136 changes: 5 additions & 131 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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,<0.60", features = [
"Win32_Foundation",
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_Ndis",
"Win32_Networking_WinSock",
] }

[build-dependencies]
cfg_aliases = { version = "0.2", default-features = false }
Expand All @@ -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"]

Expand Down
29 changes: 3 additions & 26 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#![allow(clippy::unwrap_used)] // OK in build scripts.

#[cfg(not(windows))]
const BINDINGS: &str = "bindings.rs";

#[cfg(feature = "gecko")]
Expand Down Expand Up @@ -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! {
Expand All @@ -126,5 +101,7 @@ fn main() {
)
}
}

#[cfg(not(windows))]
bindgen();
}
33 changes: 15 additions & 18 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,23 @@ use std::{
ptr, slice,
};

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,
NetworkManagement::{
IpHelper::{
if_indextoname, FreeMibTable, GetBestInterfaceEx, GetIpInterfaceTable,
MIB_IPINTERFACE_ROW, MIB_IPINTERFACE_TABLE,
},
Ndis::IF_MAX_STRING_SIZE,
},
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 {
Expand Down
Loading