From 417fd9368c877bb2445701cb5addd3a02e0d2155 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Mon, 27 Apr 2026 12:46:01 +0200 Subject: [PATCH 1/2] Remove windows-sys --- Cargo.lock | 1 - Cargo.toml | 3 --- src/cpu/aarch64/windows.rs | 11 ++++++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe8a517462..82a3959c2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -477,7 +477,6 @@ dependencies = [ "libc", "untrusted", "wasm-bindgen-test", - "windows-sys", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b4863e7439..96ab4a2893 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,9 +175,6 @@ libc = { version = "0.2.172", default-features = false } [target.'cfg(all(all(target_arch = "aarch64", target_endian = "little"), target_vendor = "apple", any(target_os = "ios", target_os = "macos", target_os = "tvos", target_os = "visionos", target_os = "watchos")))'.dependencies] libc = { version = "0.2.172", default-features = false } -[target.'cfg(all(all(target_arch = "aarch64", target_endian = "little"), target_os = "windows"))'.dependencies] -windows-sys = { version = "0.61.2", features = ["Win32_Foundation", "Win32_System_Threading"] } - [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] wasm-bindgen-test = { version = "0.3.64", default-features = false, features = ["std"] } diff --git a/src/cpu/aarch64/windows.rs b/src/cpu/aarch64/windows.rs index bce30f136c..a8949edd35 100644 --- a/src/cpu/aarch64/windows.rs +++ b/src/cpu/aarch64/windows.rs @@ -13,11 +13,16 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use super::{Aes, CAPS_STATIC, Neon, PMull, Sha256}; -use windows_sys::Win32::System::Threading::{ - IsProcessorFeaturePresent, PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE, -}; pub const FORCE_DYNAMIC_DETECTION: u32 = 0; +/// This Arm processor implements the Arm v8 extra cryptographic instructions (for example, AES, SHA1 and SHA2). +const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE: u32 = 30; + +#[link(name = "kernel32")] +extern "system" { + /// + fn IsProcessorFeaturePresent(processor_feature: u32) -> i32; +} pub fn detect_features() -> u32 { // We do not need to check for the presence of NEON, as Armv8-A always has it From 1f0b3b92b526f29cd21a8c39604432ca5917a8a9 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 28 Apr 2026 10:09:22 +0200 Subject: [PATCH 2/2] Move to polyfill --- src/cpu/aarch64/windows.rs | 13 ++++--------- src/polyfill/mod.rs | 3 +++ src/polyfill/windows_sys.rs | 25 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 src/polyfill/windows_sys.rs diff --git a/src/cpu/aarch64/windows.rs b/src/cpu/aarch64/windows.rs index a8949edd35..d6d4da7b0c 100644 --- a/src/cpu/aarch64/windows.rs +++ b/src/cpu/aarch64/windows.rs @@ -13,16 +13,9 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use super::{Aes, CAPS_STATIC, Neon, PMull, Sha256}; +use crate::polyfill::windows_sys; pub const FORCE_DYNAMIC_DETECTION: u32 = 0; -/// This Arm processor implements the Arm v8 extra cryptographic instructions (for example, AES, SHA1 and SHA2). -const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE: u32 = 30; - -#[link(name = "kernel32")] -extern "system" { - /// - fn IsProcessorFeaturePresent(processor_feature: u32) -> i32; -} pub fn detect_features() -> u32 { // We do not need to check for the presence of NEON, as Armv8-A always has it @@ -30,7 +23,9 @@ pub fn detect_features() -> u32 { let mut features = 0; - let result = unsafe { IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) }; + let result = unsafe { + windows_sys::IsProcessorFeaturePresent(windows_sys::PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) + }; if result != 0 { // These are all covered by one call in Windows diff --git a/src/polyfill/mod.rs b/src/polyfill/mod.rs index 7108963492..f67e75bf59 100644 --- a/src/polyfill/mod.rs +++ b/src/polyfill/mod.rs @@ -93,6 +93,9 @@ mod test; mod uninit_slice; mod uninit_slice_cursor; +#[cfg(target_arch = "aarch64")] +pub(crate) mod windows_sys; + pub use self::{array_flat_map::ArrayFlatMap, array_split_map::ArraySplitMap, notsend::NotSend}; #[allow(unused_imports)] diff --git a/src/polyfill/windows_sys.rs b/src/polyfill/windows_sys.rs new file mode 100644 index 0000000000..130bde4411 --- /dev/null +++ b/src/polyfill/windows_sys.rs @@ -0,0 +1,25 @@ +// Copyright 2016-2025 Brian Smith. +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION +// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +pub type DWORD = u32; +pub type BOOL = i32; + +/// This Arm processor implements the Arm v8 extra cryptographic instructions (for example, AES, SHA1 and SHA2). +pub const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE: DWORD = 30; + +#[link(name = "kernel32", kind = "raw-dylib")] +extern "system" { + /// + fn IsProcessorFeaturePresent(processor_feature: DWORD) -> BOOL; +}