Skip to content

Commit

Permalink
build!: move to windows from windows-{bindgen,core,targets}
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jan 17, 2025
1 parent ded3b5b commit 16bcd32
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 178 deletions.
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", 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();
}
29 changes: 13 additions & 16 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 16bcd32

Please sign in to comment.