From 58556730f33ee46152a5f91a16db896e14e7bf4d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 22 Jun 2019 00:44:38 +0700 Subject: [PATCH] Remove usage of kernel32-sys crate --- Cargo.lock | 1 - Cargo.toml | 10 ++++++++-- src/commands.rs | 5 +++-- src/compiler/msvc.rs | 17 +++++++---------- src/compiler/rust.rs | 4 ++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 845b96f67..f670ad770 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1709,7 +1709,6 @@ dependencies = [ "itertools 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", "jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "jsonwebtoken 5.0.1 (git+https://github.com/Jake-Shadle/jsonwebtoken.git?rev=2f469a61)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", "libmount 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index a2ea8c553..0b224ba24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,11 +110,17 @@ daemonize = "0.3" tokio-uds = "0.2" [target.'cfg(windows)'.dependencies] -kernel32-sys = "0.2.2" -winapi = { version = "0.3", features = ["winnls"] } tokio-named-pipes = "0.1" tokio-reactor = "0.1" +[target.'cfg(windows)'.dependencies.winapi] +version = "0.3" +features = [ + "fileapi", + "handleapi", + "winnls", +] + [features] default = ["dist-client", "s3"] all = ["dist-client", "redis", "s3", "memcached", "gcs", "azure"] diff --git a/src/commands.rs b/src/commands.rs index 3af4637cb..608d97466 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -159,6 +159,7 @@ fn run_server_process() -> Result { use winapi::um::winbase::{ CREATE_NEW_PROCESS_GROUP, CREATE_UNICODE_ENVIRONMENT, DETACHED_PROCESS, }; + use winapi::um::handleapi::CloseHandle; trace!("run_server_process"); @@ -231,8 +232,8 @@ fn run_server_process() -> Result { ) == TRUE } { unsafe { - kernel32::CloseHandle(pi.hProcess); - kernel32::CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); } } else { return Err(io::Error::last_os_error().into()); diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 280eeb266..7206b6b62 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -429,25 +429,22 @@ pub fn parse_arguments(arguments: &[OsString], cwd: &Path, is_clang: bool) -> Co #[cfg(windows)] fn normpath(path: &str) -> String { use std::os::windows::ffi::OsStringExt; - use std::ptr; use std::os::windows::io::AsRawHandle; + use std::ptr; + use winapi::um::fileapi::GetFinalPathNameByHandleW; File::open(path) .and_then(|f| { let handle = f.as_raw_handle(); - let size = unsafe { kernel32::GetFinalPathNameByHandleW(handle, - ptr::null_mut(), - 0, - 0) - }; + let size = unsafe { GetFinalPathNameByHandleW(handle, ptr::null_mut(), 0, 0) }; if size == 0 { return Err(io::Error::last_os_error()); } let mut wchars = Vec::with_capacity(size as usize); wchars.resize(size as usize, 0); - if unsafe { kernel32::GetFinalPathNameByHandleW(handle, - wchars.as_mut_ptr(), - wchars.len() as u32, - 0) } == 0 { + if unsafe { + GetFinalPathNameByHandleW(handle, wchars.as_mut_ptr(), wchars.len() as u32, 0) + } == 0 + { return Err(io::Error::last_os_error()); } // The return value of GetFinalPathNameByHandleW uses the diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index 3f31d1cbb..1c254ff57 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -1525,9 +1525,9 @@ impl OutputsRewriter for RustOutputsRewriter { #[test] #[cfg(all(feature = "dist-client", target_os = "windows"))] fn test_rust_outputs_rewriter() { - use compiler::compiler::OutputsRewriter; + use crate::compiler::compiler::OutputsRewriter; use std::io::Write; - use test::utils::create_file; + use crate::test::utils::create_file; let mut pt = dist::PathTransformer::new(); pt.to_dist(Path::new("c:\\")).unwrap();