Skip to content

Commit 2825031

Browse files
committed
Use windows crate to link with required system libraries
1 parent fd56c4d commit 2825031

4 files changed

Lines changed: 125 additions & 47 deletions

File tree

Cargo.lock

Lines changed: 115 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pkcs11-bindings = ">= 0.1.3"
2121
strum = { version = "0.27", default-features = false, features = ["derive"] }
2222
thiserror = "2.0.12"
2323

24+
[target.'cfg(windows)'.dependencies]
25+
windows = { version = ">=0.60,<0.63", features = ["Win32_Security_Authentication_Identity"]}
26+
2427
[build-dependencies]
2528
bindgen = { version = "0.72", default-features = false, features = ["runtime"] }
2629
mozbuild = { version = "0.1", default-features = false, optional = true }
@@ -33,7 +36,7 @@ toml = { version = "0.9", default-features = false, features = ["parse", "serde"
3336
test-fixture = {path = "test-fixture"}
3437

3538
[package.metadata.cargo-machete]
36-
ignored = ["bindgen", "semver", "serde", "serde_derive", "toml"]
39+
ignored = ["bindgen", "semver", "serde", "serde_derive", "toml", "windows"]
3740

3841
[lints.rust]
3942
absolute_paths_not_starting_with_crate = "warn"

build.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,6 @@ fn process_config(config: &mut HashMap<String, Bindings>) {
544544
fn main() {
545545
println!("cargo:rustc-check-cfg=cfg(nss_nodb)");
546546

547-
if env::consts::OS == "windows" {
548-
println!("cargo:rustc-link-lib=advapi32");
549-
}
550-
551547
let flags = if cfg!(feature = "gecko") {
552548
setup_for_gecko()
553549
} else if let Ok(nss_dir) = env::var("NSS_DIR") {

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ use std::{
4747
use log::error;
4848
use once_cell::sync::OnceCell;
4949

50+
#[cfg(windows)]
51+
#[expect(unused_imports, reason = "Force Advapi32 linkage")]
52+
mod _link_anchor {
53+
use windows::Win32::Security::Authentication::Identity::RtlGenRandom as _;
54+
}
55+
5056
#[cfg(not(feature = "disable-encryption"))]
5157
pub use self::aead::RealAead as Aead;
5258
#[cfg(feature = "disable-encryption")]

0 commit comments

Comments
 (0)