Port to windows-sys (#27)

This commit is contained in:
John Nunley 2022-11-26 21:14:01 -08:00 committed by GitHub
parent f835f75f39
commit de1071784e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 11 deletions

View File

@ -35,10 +35,11 @@ default-features = false
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
blocking = "1.0.0" blocking = "1.0.0"
[target.'cfg(windows)'.dependencies.winapi] [target.'cfg(windows)'.dependencies.windows-sys]
version = "0.3.9" version = "0.42"
default-features = false default-features = false
features = [ features = [
"winbase", "Win32_Foundation",
"winnt" "Win32_System_Threading",
] "Win32_System_WindowsProgramming"
]

View File

@ -145,12 +145,16 @@ impl Child {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(windows)] { if #[cfg(windows)] {
use std::ffi::c_void;
use std::os::windows::io::AsRawHandle; use std::os::windows::io::AsRawHandle;
use std::sync::mpsc; use std::sync::mpsc;
use winapi::um::{ use windows_sys::Win32::{
winbase::{RegisterWaitForSingleObject, INFINITE}, System::{
winnt::{BOOLEAN, HANDLE, PVOID, WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE}, Threading::{RegisterWaitForSingleObject, WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE},
WindowsProgramming::INFINITE,
},
Foundation::{BOOLEAN, HANDLE},
}; };
// This channel is used to simulate SIGCHLD on Windows. // This channel is used to simulate SIGCHLD on Windows.
@ -168,12 +172,12 @@ impl Child {
// Called when a child exits. // 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(); callback_channel().0.try_send(()).ok();
} }
// Register this child process to invoke `callback` on exit. // 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 { let ret = unsafe {
RegisterWaitForSingleObject( RegisterWaitForSingleObject(
&mut wait_object, &mut wait_object,

View File

@ -385,7 +385,7 @@ fn child_status_preserved_with_kill_on_drop() {
#[cfg(windows)] #[cfg(windows)]
fn child_as_raw_handle() { fn child_as_raw_handle() {
use std::os::windows::io::AsRawHandle; use std::os::windows::io::AsRawHandle;
use winapi::um::processthreadsapi::GetProcessId; use windows_sys::Win32::System::Threading::GetProcessId;
future::block_on(async { future::block_on(async {
let p = Command::new("cmd.exe") let p = Command::new("cmd.exe")