From 26d45f6f90046a9d610edca711d2a1bd7f2fbd7c Mon Sep 17 00:00:00 2001 From: Maksim Bondarenkov Date: Sat, 3 Aug 2024 11:25:42 +0300 Subject: [PATCH] Windows: use windows-sys instead of winapi --- Cargo.lock | 57 ++++++++++++++++++++++++------------------ Cargo.toml | 2 +- src/tasker/shutdown.rs | 8 +++--- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2e5e74e..512f291f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,7 +407,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -419,7 +419,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1226,7 +1226,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1255,7 +1255,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1389,7 +1389,7 @@ dependencies = [ "twox-hash", "unicode-segmentation", "whatlang", - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -1716,7 +1716,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1734,11 +1734,20 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1752,51 +1761,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" diff --git a/Cargo.toml b/Cargo.toml index 6f507562..d3c0261b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ nix = "0.18" tikv-jemallocator = { version = "0.4", optional = true } [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3", features = ["minwindef", "consoleapi"] } +windows-sys = { version = "0.59", features = ["Win32_System_Console"] } [features] default = ["allocator-jemalloc", "tokenizer-chinese"] diff --git a/src/tasker/shutdown.rs b/src/tasker/shutdown.rs index f28aa7a6..8507bdc4 100644 --- a/src/tasker/shutdown.rs +++ b/src/tasker/shutdown.rs @@ -13,18 +13,18 @@ mod platform { use std::sync::mpsc::{sync_channel, Receiver, SyncSender}; use std::sync::Mutex; - use winapi::shared::minwindef::{BOOL, DWORD, TRUE}; - use winapi::um::consoleapi::SetConsoleCtrlHandler; + use windows_sys::Win32::Foundation::{BOOL, TRUE}; + use windows_sys::Win32::System::Console::SetConsoleCtrlHandler; lazy_static! { - static ref CHANNEL: (SyncSender, Mutex>) = { + static ref CHANNEL: (SyncSender, Mutex>) = { let channel = sync_channel(0); (channel.0, Mutex::new(channel.1)) }; } - unsafe extern "system" fn handler(event: DWORD) -> BOOL { + unsafe extern "system" fn handler(event: u32) -> BOOL { CHANNEL.0.send(event).unwrap(); CHANNEL.0.send(0).unwrap();