diff --git a/Cargo.lock b/Cargo.lock index c7999204de..7a0ad6b2af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,7 +390,7 @@ dependencies = [ "libc", "untrusted", "wasm-bindgen-test", - "windows-sys", + "windows-link", ] [[package]] @@ -401,6 +401,13 @@ dependencies = [ "ring", ] +[[package]] +name = "ring-bindgen" +version = "0.1.0" +dependencies = [ + "windows-bindgen", +] + [[package]] name = "ring-cavp" version = "0.1.0" @@ -666,6 +673,17 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-bindgen" +version = "0.66.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b7ec123a4eadd44d1f44f76804316b477b2537abed9a2ab950b3c54afa1fcf" +dependencies = [ + "serde", + "serde_json", + "windows-threading", +] + [[package]] name = "windows-link" version = "0.2.1" @@ -680,3 +698,12 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ "windows-link", ] + +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] diff --git a/Cargo.toml b/Cargo.toml index 1c3463ab34..832798445e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -172,8 +172,8 @@ 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 = "aarch64", target_os = "windows"))'.dependencies] +windows-link = { version = "0.2.1" } [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] wasm-bindgen-test = { version = "0.3.64", default-features = false, features = ["std"] } @@ -236,10 +236,13 @@ overflow-checks = true [workspace] members = [ - # intentionally not a default member so that `cargo test` doesn't cause criterion.rs and all its + # Not a default member so that `cargo test` doesn't cause criterion.rs and all its # dependencies to get built. "bench", + # Not a defailt member as we regenerate bindings manually. + "build/bindgen", + "cavp", ] default-members = [ diff --git a/build/bindgen/Cargo.toml b/build/bindgen/Cargo.toml new file mode 100644 index 0000000000..9b9c84c557 --- /dev/null +++ b/build/bindgen/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "ring-bindgen" +edition = "2024" +publish = false +version = "0.1.0" + +[[bin]] +name = "bindgen" + +[dependencies] +windows-bindgen = "0.66" diff --git a/build/bindgen/src/bin/bindgen.rs b/build/bindgen/src/bin/bindgen.rs new file mode 100644 index 0000000000..946e830de4 --- /dev/null +++ b/build/bindgen/src/bin/bindgen.rs @@ -0,0 +1,14 @@ +// Run `cargo run -p ring-bindgen` in the Cargo workspace root directory. + +fn main() { + windows_bindgen::bindgen([ + "--out", + "src/polyfill/aarch64_windows.rs", + "--sys", + "--no-deps", + "--filter", + "IsProcessorFeaturePresent", + "PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE", + ]) + .unwrap() +} diff --git a/src/cpu/aarch64/windows.rs b/src/cpu/aarch64/windows.rs index bce30f136c..2063f84b48 100644 --- a/src/cpu/aarch64/windows.rs +++ b/src/cpu/aarch64/windows.rs @@ -13,7 +13,7 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use super::{Aes, CAPS_STATIC, Neon, PMull, Sha256}; -use windows_sys::Win32::System::Threading::{ +use crate::polyfill::aarch64_windows::Windows::Win32::System::Threading::{ IsProcessorFeaturePresent, PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE, }; diff --git a/src/polyfill/aarch64_windows.rs b/src/polyfill/aarch64_windows.rs new file mode 100644 index 0000000000..c4e87f500a --- /dev/null +++ b/src/polyfill/aarch64_windows.rs @@ -0,0 +1,22 @@ +// Bindings generated by `windows-bindgen` 0.66.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + +pub type BOOL = i32; +pub mod Windows { + pub mod Win32 { + pub mod System { + pub mod Threading { + windows_link::link!("kernel32.dll" "system" fn IsProcessorFeaturePresent(processorfeature : PROCESSOR_FEATURE_ID) -> super::super::super::super::BOOL); + pub const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE: PROCESSOR_FEATURE_ID = 30u32; + pub type PROCESSOR_FEATURE_ID = u32; + } + } + } +} diff --git a/src/polyfill/mod.rs b/src/polyfill/mod.rs index 47d2dc4048..5eb2619474 100644 --- a/src/polyfill/mod.rs +++ b/src/polyfill/mod.rs @@ -91,6 +91,9 @@ mod test; pub(crate) mod uninit; mod uninit_slice; +#[cfg(all(target_arch = "aarch64", target_os = "windows"))] +pub(crate) mod aarch64_windows; + pub use self::{array_flat_map::ArrayFlatMap, array_split_map::ArraySplitMap, notsend::NotSend}; #[allow(unused_imports)]