From de1071784e862f8b613d18de3a04ecdb90613fd7 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sat, 26 Nov 2022 21:14:01 -0800 Subject: [PATCH] Port to windows-sys (#27) --- Cargo.toml | 11 ++++++----- src/lib.rs | 14 +++++++++----- tests/std.rs | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f27903e..d8f4df6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,10 +35,11 @@ default-features = false [target.'cfg(windows)'.dependencies] blocking = "1.0.0" -[target.'cfg(windows)'.dependencies.winapi] -version = "0.3.9" +[target.'cfg(windows)'.dependencies.windows-sys] +version = "0.42" default-features = false features = [ - "winbase", - "winnt" -] + "Win32_Foundation", + "Win32_System_Threading", + "Win32_System_WindowsProgramming" +] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0bd52ae..21efe51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,12 +145,16 @@ impl Child { cfg_if::cfg_if! { if #[cfg(windows)] { + use std::ffi::c_void; use std::os::windows::io::AsRawHandle; use std::sync::mpsc; - use winapi::um::{ - winbase::{RegisterWaitForSingleObject, INFINITE}, - winnt::{BOOLEAN, HANDLE, PVOID, WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE}, + use windows_sys::Win32::{ + System::{ + Threading::{RegisterWaitForSingleObject, WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE}, + WindowsProgramming::INFINITE, + }, + Foundation::{BOOLEAN, HANDLE}, }; // This channel is used to simulate SIGCHLD on Windows. @@ -168,12 +172,12 @@ impl Child { // Called when a child exits. - unsafe extern "system" fn callback(_: PVOID, _: BOOLEAN) { + unsafe extern "system" fn callback(_: *mut c_void, _: BOOLEAN) { callback_channel().0.try_send(()).ok(); } // Register this child process to invoke `callback` on exit. - let mut wait_object = std::ptr::null_mut(); + let mut wait_object = 0; let ret = unsafe { RegisterWaitForSingleObject( &mut wait_object, diff --git a/tests/std.rs b/tests/std.rs index d14f64f..261c4ba 100644 --- a/tests/std.rs +++ b/tests/std.rs @@ -385,7 +385,7 @@ fn child_status_preserved_with_kill_on_drop() { #[cfg(windows)] fn child_as_raw_handle() { use std::os::windows::io::AsRawHandle; - use winapi::um::processthreadsapi::GetProcessId; + use windows_sys::Win32::System::Threading::GetProcessId; future::block_on(async { let p = Command::new("cmd.exe")