diff --git a/Cargo.lock b/Cargo.lock index fa8f380d0..45a73f1f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4422,7 +4422,7 @@ dependencies = [ "shared_library", "shell-words", "smol", - "winapi", + "windows-sys 0.61.2", "winreg", ] diff --git a/pty/Cargo.toml b/pty/Cargo.toml index 359686deb..50cf3fc65 100644 --- a/pty/Cargo.toml +++ b/pty/Cargo.toml @@ -27,15 +27,12 @@ serde_support = ["serde"] bitflags.workspace = true lazy_static.workspace = true shared_library.workspace = true -winapi = { workspace=true, features = [ - "winuser", - "consoleapi", - "handleapi", - "fileapi", - "namedpipeapi", - "processenv", - "synchapi", -]} +windows-sys = { workspace = true, features = [ + "Win32_Foundation", + "Win32_System_Console", + "Win32_System_Environment", + "Win32_System_Threading", +] } winreg.workspace = true [dev-dependencies] diff --git a/pty/src/cmdbuilder.rs b/pty/src/cmdbuilder.rs index 675d88cdb..e6679fea4 100644 --- a/pty/src/cmdbuilder.rs +++ b/pty/src/cmdbuilder.rs @@ -104,7 +104,7 @@ fn get_base_env() -> BTreeMap { #[cfg(windows)] { use std::os::windows::ffi::OsStringExt; - use winapi::um::processenv::ExpandEnvironmentStringsW; + use windows_sys::Win32::System::Environment::ExpandEnvironmentStringsW; use winreg::enums::{RegType, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE}; use winreg::types::FromRegValue; use winreg::{RegKey, RegValue}; diff --git a/pty/src/lib.rs b/pty/src/lib.rs index 264a86be6..f1e2d71a8 100644 --- a/pty/src/lib.rs +++ b/pty/src/lib.rs @@ -46,6 +46,8 @@ use serde::{Deserialize, Serialize}; use std::io::Result as IoResult; #[cfg(windows)] use std::os::windows::prelude::{AsRawHandle, RawHandle}; +#[cfg(windows)] +use windows_sys::Win32::System::Threading::TerminateProcess; pub mod cmdbuilder; pub use cmdbuilder::CommandBuilder; @@ -303,9 +305,7 @@ impl ChildKiller for ProcessSignaller { fn kill(&mut self) -> IoResult<()> { if let Some(handle) = &self.handle { unsafe { - if winapi::um::processthreadsapi::TerminateProcess(handle.as_raw_handle() as _, 127) - == 0 - { + if TerminateProcess(handle.as_raw_handle(), 127) == 0 { return Err(std::io::Error::last_os_error()); } } diff --git a/pty/src/win/conpty.rs b/pty/src/win/conpty.rs index 0e9a18c67..d6ca5645a 100644 --- a/pty/src/win/conpty.rs +++ b/pty/src/win/conpty.rs @@ -4,7 +4,7 @@ use crate::{Child, MasterPty, PtyPair, PtySize, PtySystem, SlavePty}; use anyhow::Error; use filedescriptor::{FileDescriptor, Pipe}; use std::sync::{Arc, Mutex}; -use winapi::um::wincon::COORD; +use windows_sys::Win32::System::Console::COORD; #[derive(Default)] pub struct ConPtySystem {} diff --git a/pty/src/win/mod.rs b/pty/src/win/mod.rs index 750f66975..ac15875a4 100644 --- a/pty/src/win/mod.rs +++ b/pty/src/win/mod.rs @@ -5,11 +5,10 @@ use std::os::windows::io::{AsRawHandle, RawHandle}; use std::pin::Pin; use std::sync::Mutex; use std::task::{Context, Poll}; -use winapi::shared::minwindef::DWORD; -use winapi::um::minwinbase::STILL_ACTIVE; -use winapi::um::processthreadsapi::*; -use winapi::um::synchapi::WaitForSingleObject; -use winapi::um::winbase::INFINITE; +use windows_sys::Win32::Foundation::STILL_ACTIVE; +use windows_sys::Win32::System::Threading::{ + GetExitCodeProcess, GetProcessId, TerminateProcess, WaitForSingleObject, INFINITE, +}; pub mod conpty; mod procthreadattr; @@ -24,11 +23,11 @@ pub struct WinChild { impl WinChild { fn is_complete(&mut self) -> IoResult> { - let mut status: DWORD = 0; + let mut status: u32 = 0; let proc = self.proc.lock().unwrap().try_clone().unwrap(); - let res = unsafe { GetExitCodeProcess(proc.as_raw_handle() as _, &mut status) }; + let res = unsafe { GetExitCodeProcess(proc.as_raw_handle(), &mut status) }; if res != 0 { - if status == STILL_ACTIVE { + if status == STILL_ACTIVE as u32 { Ok(None) } else { Ok(Some(ExitStatus::with_exit_code(status))) @@ -40,7 +39,7 @@ impl WinChild { fn do_kill(&mut self) -> IoResult<()> { let proc = self.proc.lock().unwrap().try_clone().unwrap(); - let res = unsafe { TerminateProcess(proc.as_raw_handle() as _, 1) }; + let res = unsafe { TerminateProcess(proc.as_raw_handle(), 1) }; let err = IoError::last_os_error(); if res == 0 { Err(err) @@ -69,7 +68,7 @@ pub struct WinChildKiller { impl ChildKiller for WinChildKiller { fn kill(&mut self) -> IoResult<()> { - let res = unsafe { TerminateProcess(self.proc.as_raw_handle() as _, 1) }; + let res = unsafe { TerminateProcess(self.proc.as_raw_handle(), 1) }; let err = IoError::last_os_error(); if res == 0 { Err(err) @@ -95,10 +94,10 @@ impl Child for WinChild { } let proc = self.proc.lock().unwrap().try_clone().unwrap(); unsafe { - WaitForSingleObject(proc.as_raw_handle() as _, INFINITE); + WaitForSingleObject(proc.as_raw_handle(), INFINITE); } - let mut status: DWORD = 0; - let res = unsafe { GetExitCodeProcess(proc.as_raw_handle() as _, &mut status) }; + let mut status: u32 = 0; + let res = unsafe { GetExitCodeProcess(proc.as_raw_handle(), &mut status) }; if res != 0 { Ok(ExitStatus::with_exit_code(status)) } else { @@ -107,7 +106,7 @@ impl Child for WinChild { } fn process_id(&self) -> Option { - let res = unsafe { GetProcessId(self.proc.lock().unwrap().as_raw_handle() as _) }; + let res = unsafe { GetProcessId(self.proc.lock().unwrap().as_raw_handle()) }; if res == 0 { None } else { diff --git a/pty/src/win/procthreadattr.rs b/pty/src/win/procthreadattr.rs index ad97d5825..3ef66e866 100644 --- a/pty/src/win/procthreadattr.rs +++ b/pty/src/win/procthreadattr.rs @@ -2,8 +2,10 @@ use crate::win::psuedocon::HPCON; use anyhow::{ensure, Error}; use std::io::Error as IoError; use std::{mem, ptr}; -use winapi::shared::minwindef::DWORD; -use winapi::um::processthreadsapi::*; +use windows_sys::Win32::System::Threading::{ + DeleteProcThreadAttributeList, InitializeProcThreadAttributeList, UpdateProcThreadAttribute, + LPPROC_THREAD_ATTRIBUTE_LIST, +}; const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x00020016; @@ -12,7 +14,7 @@ pub struct ProcThreadAttributeList { } impl ProcThreadAttributeList { - pub fn with_capacity(num_attributes: DWORD) -> Result { + pub fn with_capacity(num_attributes: u32) -> Result { let mut bytes_required: usize = 0; unsafe { InitializeProcThreadAttributeList( diff --git a/pty/src/win/psuedocon.rs b/pty/src/win/psuedocon.rs index 13c7c5dba..8c1614fb5 100644 --- a/pty/src/win/psuedocon.rs +++ b/pty/src/win/psuedocon.rs @@ -12,30 +12,28 @@ use std::os::windows::io::{AsRawHandle, FromRawHandle}; use std::path::Path; use std::sync::Mutex; use std::{mem, ptr}; -use winapi::shared::minwindef::DWORD; -use winapi::shared::winerror::{HRESULT, S_OK}; -use winapi::um::handleapi::*; -use winapi::um::processthreadsapi::*; -use winapi::um::winbase::{ - CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, STARTUPINFOEXW, +use windows_sys::core::HRESULT; +use windows_sys::Win32::Foundation::{HANDLE, INVALID_HANDLE_VALUE, S_OK}; +use windows_sys::Win32::System::Console::COORD; +use windows_sys::Win32::System::Threading::{ + CreateProcessW, CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT, PROCESS_INFORMATION, + STARTF_USESTDHANDLES, STARTUPINFOEXW, }; -use winapi::um::wincon::COORD; -use winapi::um::winnt::HANDLE; pub type HPCON = HANDLE; -pub const PSUEDOCONSOLE_INHERIT_CURSOR: DWORD = 0x1; -pub const PSEUDOCONSOLE_RESIZE_QUIRK: DWORD = 0x2; -pub const PSEUDOCONSOLE_WIN32_INPUT_MODE: DWORD = 0x4; +pub const PSUEDOCONSOLE_INHERIT_CURSOR: u32 = 0x1; +pub const PSEUDOCONSOLE_RESIZE_QUIRK: u32 = 0x2; +pub const PSEUDOCONSOLE_WIN32_INPUT_MODE: u32 = 0x4; #[allow(dead_code)] -pub const PSEUDOCONSOLE_PASSTHROUGH_MODE: DWORD = 0x8; +pub const PSEUDOCONSOLE_PASSTHROUGH_MODE: u32 = 0x8; shared_library!(ConPtyFuncs, pub fn CreatePseudoConsole( size: COORD, hInput: HANDLE, hOutput: HANDLE, - flags: DWORD, + flags: u32, hpc: *mut HPCON ) -> HRESULT, pub fn ResizePseudoConsole(hpc: HPCON, size: COORD) -> HRESULT, @@ -82,8 +80,8 @@ impl PsuedoCon { let result = unsafe { (CONPTY.CreatePseudoConsole)( size, - input.as_raw_handle() as _, - output.as_raw_handle() as _, + input.as_raw_handle(), + output.as_raw_handle(), PSUEDOCONSOLE_INHERIT_CURSOR | PSEUDOCONSOLE_RESIZE_QUIRK | PSEUDOCONSOLE_WIN32_INPUT_MODE,