Skip to content

Commit

Permalink
Replace windows-sys with windows-bindgen
Browse files Browse the repository at this point in the history
sys-locale only uses 3 definitions from Windows, which makes the windows-sys dependency not worthwhile
  • Loading branch information
complexspaces committed Aug 27, 2023
1 parent e746508 commit dfa5759
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/*/target
Cargo.lock
7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
12 changes: 12 additions & 0 deletions gen-windows-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = ["."]
9 changes: 9 additions & 0 deletions gen-windows-bindings/bindings.config
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions gen-windows-bindings/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
windows_bindgen::bindgen(&["--etc", "./bindings.config"]).unwrap();
}
6 changes: 4 additions & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -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<Item = String> {
Expand Down
22 changes: 22 additions & 0 deletions src/windows_sys.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit dfa5759

Please sign in to comment.