Skip to content

Commit 387438a

Browse files
Merge branch 'main' into timeouts
2 parents a223044 + 29d17c7 commit 387438a

File tree

5 files changed

+50
-45
lines changed

5 files changed

+50
-45
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,15 @@ daemonize = "0.5"
140140
optional = true
141141
version = "0.1.15"
142142

143-
[target.'cfg(windows)'.dependencies.winapi]
143+
[target.'cfg(windows)'.dependencies.windows-sys]
144144
features = [
145-
"fileapi",
146-
"handleapi",
147-
"stringapiset",
148-
"winnls",
149-
"processenv",
150-
"std",
145+
"Win32_Foundation",
146+
"Win32_Globalization",
147+
"Win32_Storage_FileSystem",
148+
"Win32_System_Threading",
149+
"Win32_System_Console",
151150
]
152-
version = "0.3"
151+
version = "0.52"
153152

154153
[features]
155154
all = [

src/commands.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ fn redirect_stderr(f: File) {
133133
#[cfg(windows)]
134134
fn redirect_stderr(f: File) {
135135
use std::os::windows::io::IntoRawHandle;
136-
use winapi::um::processenv::SetStdHandle;
137-
use winapi::um::winbase::STD_ERROR_HANDLE;
136+
use windows_sys::Win32::System::Console::{SetStdHandle, STD_ERROR_HANDLE};
138137
// Ignore errors here.
139138
unsafe {
140-
SetStdHandle(STD_ERROR_HANDLE, f.into_raw_handle());
139+
SetStdHandle(STD_ERROR_HANDLE, f.into_raw_handle() as _);
141140
}
142141
}
143142

@@ -176,11 +175,10 @@ fn run_server_process(startup_timeout: Option<Duration>) -> Result<ServerStartup
176175
use std::ptr;
177176
use tokio::net::windows::named_pipe;
178177
use uuid::Uuid;
179-
use winapi::shared::minwindef::{DWORD, FALSE, LPVOID, TRUE};
180-
use winapi::um::handleapi::CloseHandle;
181-
use winapi::um::processthreadsapi::{CreateProcessW, PROCESS_INFORMATION, STARTUPINFOW};
182-
use winapi::um::winbase::{
183-
CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW, CREATE_UNICODE_ENVIRONMENT,
178+
use windows_sys::Win32::Foundation::CloseHandle;
179+
use windows_sys::Win32::System::Threading::{
180+
CreateProcessW, CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW, CREATE_UNICODE_ENVIRONMENT,
181+
PROCESS_INFORMATION, STARTUPINFOW,
184182
};
185183

186184
trace!("run_server_process");
@@ -227,26 +225,26 @@ fn run_server_process(startup_timeout: Option<Duration>) -> Result<ServerStartup
227225
// TODO: Expose `bInheritHandles` argument of `CreateProcessW` through the
228226
// standard library's `Command` type and then use that instead.
229227
let mut pi = PROCESS_INFORMATION {
230-
hProcess: ptr::null_mut(),
231-
hThread: ptr::null_mut(),
228+
hProcess: 0,
229+
hThread: 0,
232230
dwProcessId: 0,
233231
dwThreadId: 0,
234232
};
235233
let mut si: STARTUPINFOW = unsafe { mem::zeroed() };
236-
si.cb = mem::size_of::<STARTUPINFOW>() as DWORD;
234+
si.cb = mem::size_of::<STARTUPINFOW>() as _;
237235
if unsafe {
238236
CreateProcessW(
239237
exe.as_mut_ptr(),
240238
ptr::null_mut(),
241239
ptr::null_mut(),
242240
ptr::null_mut(),
243-
FALSE,
241+
0,
244242
CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW,
245-
envp.as_mut_ptr() as LPVOID,
243+
envp.as_mut_ptr().cast(),
246244
workdir.as_ptr(),
247-
&mut si,
245+
&si,
248246
&mut pi,
249-
) == TRUE
247+
) != 0
250248
} {
251249
unsafe {
252250
CloseHandle(pi.hProcess);

src/compiler/msvc.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,18 @@ fn from_local_codepage(multi_byte_str: &[u8]) -> io::Result<String> {
112112

113113
#[cfg(windows)]
114114
pub fn from_local_codepage(multi_byte_str: &[u8]) -> io::Result<String> {
115-
let codepage = winapi::um::winnls::CP_OEMCP;
116-
let flags = winapi::um::winnls::MB_ERR_INVALID_CHARS;
115+
use windows_sys::Win32::Globalization::{MultiByteToWideChar, CP_OEMCP, MB_ERR_INVALID_CHARS};
116+
117+
let codepage = CP_OEMCP;
118+
let flags = MB_ERR_INVALID_CHARS;
117119

118120
// Empty string
119121
if multi_byte_str.is_empty() {
120122
return Ok(String::new());
121123
}
122124
unsafe {
123125
// Get length of UTF-16 string
124-
let len = winapi::um::stringapiset::MultiByteToWideChar(
126+
let len = MultiByteToWideChar(
125127
codepage,
126128
flags,
127129
multi_byte_str.as_ptr() as _,
@@ -132,7 +134,7 @@ pub fn from_local_codepage(multi_byte_str: &[u8]) -> io::Result<String> {
132134
if len > 0 {
133135
// Convert to UTF-16
134136
let mut wstr: Vec<u16> = Vec::with_capacity(len as usize);
135-
let len = winapi::um::stringapiset::MultiByteToWideChar(
137+
let len = MultiByteToWideChar(
136138
codepage,
137139
flags,
138140
multi_byte_str.as_ptr() as _,
@@ -832,10 +834,10 @@ fn normpath(path: &str) -> String {
832834
use std::os::windows::ffi::OsStringExt;
833835
use std::os::windows::io::AsRawHandle;
834836
use std::ptr;
835-
use winapi::um::fileapi::GetFinalPathNameByHandleW;
837+
use windows_sys::Win32::Storage::FileSystem::GetFinalPathNameByHandleW;
836838
File::open(path)
837839
.and_then(|f| {
838-
let handle = f.as_raw_handle();
840+
let handle = f.as_raw_handle() as _;
839841
let size = unsafe { GetFinalPathNameByHandleW(handle, ptr::null_mut(), 0, 0) };
840842
if size == 0 {
841843
return Err(io::Error::last_os_error());
@@ -2582,7 +2584,7 @@ mod test {
25822584
#[cfg(windows)]
25832585
fn local_oem_codepage_conversions() {
25842586
use crate::util::wide_char_to_multi_byte;
2585-
use winapi::um::winnls::GetOEMCP;
2587+
use windows_sys::Win32::Globalization::GetOEMCP;
25862588

25872589
let current_oemcp = unsafe { GetOEMCP() };
25882590
// We don't control the local OEM codepage so test only if it is one of:

src/util.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -636,23 +636,27 @@ pub fn decode_path(bytes: &[u8]) -> std::io::Result<PathBuf> {
636636

637637
#[cfg(windows)]
638638
pub fn decode_path(bytes: &[u8]) -> std::io::Result<PathBuf> {
639-
let codepage = winapi::um::winnls::CP_OEMCP;
640-
let flags = winapi::um::winnls::MB_ERR_INVALID_CHARS;
639+
use windows_sys::Win32::Globalization::{CP_OEMCP, MB_ERR_INVALID_CHARS};
640+
641+
let codepage = CP_OEMCP;
642+
let flags = MB_ERR_INVALID_CHARS;
641643

642644
Ok(OsString::from_wide(&multi_byte_to_wide_char(codepage, flags, bytes)?).into())
643645
}
644646

645647
#[cfg(windows)]
646648
pub fn wide_char_to_multi_byte(wide_char_str: &[u16]) -> std::io::Result<Vec<u8>> {
647-
let codepage = winapi::um::winnls::CP_OEMCP;
649+
use windows_sys::Win32::Globalization::{WideCharToMultiByte, CP_OEMCP};
650+
651+
let codepage = CP_OEMCP;
648652
let flags = 0;
649653
// Empty string
650654
if wide_char_str.is_empty() {
651655
return Ok(Vec::new());
652656
}
653657
unsafe {
654658
// Get length of multibyte string
655-
let len = winapi::um::stringapiset::WideCharToMultiByte(
659+
let len = WideCharToMultiByte(
656660
codepage,
657661
flags,
658662
wide_char_str.as_ptr(),
@@ -666,7 +670,7 @@ pub fn wide_char_to_multi_byte(wide_char_str: &[u16]) -> std::io::Result<Vec<u8>
666670
if len > 0 {
667671
// Convert from UTF-16 to multibyte
668672
let mut astr: Vec<u8> = Vec::with_capacity(len as usize);
669-
let len = winapi::um::stringapiset::WideCharToMultiByte(
673+
let len = WideCharToMultiByte(
670674
codepage,
671675
flags,
672676
wide_char_str.as_ptr(),
@@ -695,30 +699,32 @@ pub fn wide_char_to_multi_byte(wide_char_str: &[u16]) -> std::io::Result<Vec<u8>
695699
/// See https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx
696700
/// for more details.
697701
pub fn multi_byte_to_wide_char(
698-
codepage: winapi::shared::minwindef::DWORD,
699-
flags: winapi::shared::minwindef::DWORD,
702+
codepage: u32,
703+
flags: u32,
700704
multi_byte_str: &[u8],
701705
) -> std::io::Result<Vec<u16>> {
706+
use windows_sys::Win32::Globalization::MultiByteToWideChar;
707+
702708
if multi_byte_str.is_empty() {
703709
return Ok(vec![]);
704710
}
705711
unsafe {
706712
// Get length of UTF-16 string
707-
let len = winapi::um::stringapiset::MultiByteToWideChar(
713+
let len = MultiByteToWideChar(
708714
codepage,
709715
flags,
710-
multi_byte_str.as_ptr() as winapi::um::winnt::LPSTR,
716+
multi_byte_str.as_ptr(),
711717
multi_byte_str.len() as i32,
712718
std::ptr::null_mut(),
713719
0,
714720
);
715721
if len > 0 {
716722
// Convert to UTF-16
717723
let mut wstr: Vec<u16> = Vec::with_capacity(len as usize);
718-
let len = winapi::um::stringapiset::MultiByteToWideChar(
724+
let len = MultiByteToWideChar(
719725
codepage,
720726
flags,
721-
multi_byte_str.as_ptr() as winapi::um::winnt::LPSTR,
727+
multi_byte_str.as_ptr(),
722728
multi_byte_str.len() as i32,
723729
wstr.as_mut_ptr(),
724730
len,

0 commit comments

Comments
 (0)