diff --git a/.gitignore b/.gitignore index 869df07..efbe0b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target +/*/target Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 6eb09f3..374c5bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,6 @@ license = "MIT OR Apache-2.0" [target.'cfg(target_os = "android")'.dependencies] libc = "0.2" -[target.'cfg(windows)'.dependencies.windows-sys] -version = "0.48" -features = [ - "Win32_Globalization", - "Win32_Foundation" -] - [target.'cfg(all(target_family = "wasm", not(unix)))'.dependencies] js-sys = { version = "0.3", optional = true } wasm-bindgen = { version = "0.2", optional = true } diff --git a/gen-windows-bindings/Cargo.toml b/gen-windows-bindings/Cargo.toml new file mode 100644 index 0000000..54445b7 --- /dev/null +++ b/gen-windows-bindings/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "gen-windows-bindings" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +windows-bindgen = "0.51" + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] \ No newline at end of file diff --git a/gen-windows-bindings/bindings.config b/gen-windows-bindings/bindings.config new file mode 100644 index 0000000..3c0645e --- /dev/null +++ b/gen-windows-bindings/bindings.config @@ -0,0 +1,9 @@ +--out ../src/windows_sys.rs +// We use `std` for now until the versioning of `windows-targets` has had more time to settle. +// After that, replace it with the `sys` feature instead. +--config flatten std minimal + +--filter + Windows.Win32.Foundation.TRUE + Windows.Win32.Globalization.GetUserPreferredUILanguages + Windows.Win32.Globalization.MUI_LANGUAGE_NAME diff --git a/gen-windows-bindings/src/main.rs b/gen-windows-bindings/src/main.rs new file mode 100644 index 0000000..f476439 --- /dev/null +++ b/gen-windows-bindings/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + windows_bindgen::bindgen(&["--etc", "./bindings.config"]).unwrap(); +} diff --git a/src/windows.rs b/src/windows.rs index 1bb2e73..1b74b7e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,6 +1,8 @@ use alloc::{string::String, vec::Vec}; -use windows_sys::Win32::Foundation::TRUE; -use windows_sys::Win32::Globalization::{GetUserPreferredUILanguages, MUI_LANGUAGE_NAME}; + +#[path = "./windows_sys.rs"] +mod windows_sys; +use windows_sys::{GetUserPreferredUILanguages, MUI_LANGUAGE_NAME, TRUE}; #[allow(clippy::as_conversions)] pub(crate) fn get() -> impl Iterator { diff --git a/src/windows_sys.rs b/src/windows_sys.rs new file mode 100644 index 0000000..ea2cf14 --- /dev/null +++ b/src/windows_sys.rs @@ -0,0 +1,22 @@ +// Bindings generated by `windows-bindgen` 0.51.1 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] +#[link(name = "kernel32")] +extern "system" { + pub fn GetUserPreferredUILanguages( + dwflags: u32, + pulnumlanguages: *mut u32, + pwszlanguagesbuffer: PWSTR, + pcchlanguagesbuffer: *mut u32, + ) -> BOOL; +} +pub type BOOL = i32; +pub const MUI_LANGUAGE_NAME: u32 = 8u32; +pub type PWSTR = *mut u16; +pub const TRUE: BOOL = 1i32;