Skip to content

Port to windows-sys #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down