Skip to content

Commit 2c5f9d2

Browse files
committed
migrate to winapi 0.3
1 parent 57fc3c0 commit 2c5f9d2

File tree

16 files changed

+107
-131
lines changed

16 files changed

+107
-131
lines changed

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ url = "1.1.0"
5757
wait-timeout = "0.1.5"
5858

5959
[target."cfg(windows)".dependencies]
60-
winapi = "0.2.8"
60+
winapi = { version = "0.3", features = ["jobapi", "jobapi2", "processthreadsapi", "psapi", "synchapi", "winuser"] }
6161
winreg = "0.4.0"
62-
user32-sys = "0.2.0"
63-
kernel32-sys = "0.2.1"
6462
gcc = "0.3.50"
65-
psapi-sys = "0.1"
6663

6764
[dev-dependencies]
6865
rustup-mock = { path = "src/rustup-mock", version = "1.1.0" }

src/rustup-cli/job.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ mod imp {
3434

3535
#[cfg(windows)]
3636
mod imp {
37-
extern crate kernel32;
3837
extern crate winapi;
39-
extern crate psapi;
4038

4139
use std::ffi::OsString;
4240
use std::io;
4341
use std::mem;
4442
use std::os::windows::prelude::*;
43+
use winapi::shared::*;
44+
use winapi::um::*;
4545

4646
pub struct Setup {
4747
job: Handle,
4848
}
4949

5050
pub struct Handle {
51-
inner: winapi::HANDLE,
51+
inner: ntdef::HANDLE,
5252
}
5353

5454
fn last_err() -> io::Error {
@@ -65,7 +65,7 @@ mod imp {
6565
// use job objects, so we instead just ignore errors and assume that
6666
// we're otherwise part of someone else's job object in this case.
6767

68-
let job = kernel32::CreateJobObjectW(0 as *mut _, 0 as *const _);
68+
let job = jobapi2::CreateJobObjectW(0 as *mut _, 0 as *const _);
6969
if job.is_null() {
7070
return None
7171
}
@@ -75,22 +75,22 @@ mod imp {
7575
// process in the object should be killed. Note that this includes our
7676
// entire process tree by default because we've added ourselves and and
7777
// our children will reside in the job once we spawn a process.
78-
let mut info: winapi::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
78+
let mut info: winnt::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
7979
info = mem::zeroed();
8080
info.BasicLimitInformation.LimitFlags =
81-
winapi::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
82-
let r = kernel32::SetInformationJobObject(job.inner,
83-
winapi::JobObjectExtendedLimitInformation,
84-
&mut info as *mut _ as winapi::LPVOID,
85-
mem::size_of_val(&info) as winapi::DWORD);
81+
winnt::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
82+
let r = jobapi2::SetInformationJobObject(job.inner,
83+
winnt::JobObjectExtendedLimitInformation,
84+
&mut info as *mut _ as minwindef::LPVOID,
85+
mem::size_of_val(&info) as minwindef::DWORD);
8686
if r == 0 {
8787
return None
8888
}
8989

9090
// Assign our process to this job object, meaning that our children will
9191
// now live or die based on our existence.
92-
let me = kernel32::GetCurrentProcess();
93-
let r = kernel32::AssignProcessToJobObject(job.inner, me);
92+
let me = processthreadsapi::GetCurrentProcess();
93+
let r = jobapi2::AssignProcessToJobObject(job.inner, me);
9494
if r == 0 {
9595
return None
9696
}
@@ -118,13 +118,13 @@ mod imp {
118118
info!("killed some, going for more");
119119
}
120120

121-
let mut info: winapi::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
121+
let mut info: winnt::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
122122
info = mem::zeroed();
123-
let r = kernel32::SetInformationJobObject(
123+
let r = jobapi2::SetInformationJobObject(
124124
self.job.inner,
125-
winapi::JobObjectExtendedLimitInformation,
126-
&mut info as *mut _ as winapi::LPVOID,
127-
mem::size_of_val(&info) as winapi::DWORD);
125+
winnt::JobObjectExtendedLimitInformation,
126+
&mut info as *mut _ as minwindef::LPVOID,
127+
mem::size_of_val(&info) as minwindef::DWORD);
128128
if r == 0 {
129129
info!("failed to configure job object to defaults: {}",
130130
last_err());
@@ -137,16 +137,16 @@ mod imp {
137137
unsafe fn kill_remaining(&mut self) -> bool {
138138
#[repr(C)]
139139
struct Jobs {
140-
header: winapi::JOBOBJECT_BASIC_PROCESS_ID_LIST,
141-
list: [winapi::ULONG_PTR; 1024],
140+
header: winnt::JOBOBJECT_BASIC_PROCESS_ID_LIST,
141+
list: [basetsd::ULONG_PTR; 1024],
142142
}
143143

144144
let mut jobs: Jobs = mem::zeroed();
145-
let r = kernel32::QueryInformationJobObject(
145+
let r = jobapi2::QueryInformationJobObject(
146146
self.job.inner,
147-
winapi::JobObjectBasicProcessIdList,
148-
&mut jobs as *mut _ as winapi::LPVOID,
149-
mem::size_of_val(&jobs) as winapi::DWORD,
147+
winnt::JobObjectBasicProcessIdList,
148+
&mut jobs as *mut _ as minwindef::LPVOID,
149+
mem::size_of_val(&jobs) as minwindef::DWORD,
150150
0 as *mut _);
151151
if r == 0 {
152152
info!("failed to query job object: {}", last_err());
@@ -159,17 +159,17 @@ mod imp {
159159

160160
let list = list.iter().filter(|&&id| {
161161
// let's not kill ourselves
162-
id as winapi::DWORD != kernel32::GetCurrentProcessId()
162+
id as minwindef::DWORD != processthreadsapi::GetCurrentProcessId()
163163
}).filter_map(|&id| {
164164
// Open the process with the necessary rights, and if this
165165
// fails then we probably raced with the process exiting so we
166166
// ignore the problem.
167-
let flags = winapi::PROCESS_QUERY_INFORMATION |
168-
winapi::PROCESS_TERMINATE |
169-
winapi::SYNCHRONIZE;
170-
let p = kernel32::OpenProcess(flags,
171-
winapi::FALSE,
172-
id as winapi::DWORD);
167+
let flags = winnt::PROCESS_QUERY_INFORMATION |
168+
winnt::PROCESS_TERMINATE |
169+
winnt::SYNCHRONIZE;
170+
let p = processthreadsapi::OpenProcess(flags,
171+
minwindef::FALSE,
172+
id as minwindef::DWORD);
173173
if p.is_null() {
174174
None
175175
} else {
@@ -180,12 +180,12 @@ mod imp {
180180
// If it's not then we likely raced with something else
181181
// recycling this PID, so we just skip this step.
182182
let mut res = 0;
183-
let r = kernel32::IsProcessInJob(p.inner, self.job.inner, &mut res);
183+
let r = jobapi::IsProcessInJob(p.inner, self.job.inner, &mut res);
184184
if r == 0 {
185185
info!("failed to test is process in job: {}", last_err());
186186
return false
187187
}
188-
res == winapi::TRUE
188+
res == minwindef::TRUE
189189
});
190190

191191

@@ -195,7 +195,7 @@ mod imp {
195195
let mut buf = [0; 1024];
196196
let r = psapi::GetProcessImageFileNameW(p.inner,
197197
buf.as_mut_ptr(),
198-
buf.len() as winapi::DWORD);
198+
buf.len() as minwindef::DWORD);
199199
if r == 0 {
200200
info!("failed to get image name: {}", last_err());
201201
continue
@@ -224,14 +224,14 @@ mod imp {
224224
// Ok, this isn't mspdbsrv, let's kill the process. After we
225225
// kill it we wait on it to ensure that the next time around in
226226
// this function we're not going to see it again.
227-
let r = kernel32::TerminateProcess(p.inner, 1);
227+
let r = processthreadsapi::TerminateProcess(p.inner, 1);
228228
if r == 0 {
229229
info!("\tfailed to kill subprocess: {}", last_err());
230230
info!("\tassuming subprocess is dead...");
231231
} else {
232232
info!("\tterminated subprocess");
233233
}
234-
let r = kernel32::WaitForSingleObject(p.inner, winapi::INFINITE);
234+
let r = synchapi::WaitForSingleObject(p.inner, winbase::INFINITE);
235235
if r != 0 {
236236
info!("failed to wait for process to die: {}", last_err());
237237
return false
@@ -245,7 +245,7 @@ mod imp {
245245

246246
impl Drop for Handle {
247247
fn drop(&mut self) {
248-
unsafe { kernel32::CloseHandle(self.inner); }
248+
unsafe { handleapi::CloseHandle(self.inner); }
249249
}
250250
}
251251
}

src/rustup-cli/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ extern crate gcc;
4040
extern crate winapi;
4141
#[cfg(windows)]
4242
extern crate winreg;
43-
#[cfg(windows)]
44-
extern crate user32;
45-
#[cfg(windows)]
46-
extern crate kernel32;
4743
extern crate libc;
4844

4945
#[macro_use]
@@ -172,8 +168,7 @@ fn make_environment_compatible() {
172168
#[cfg(windows)]
173169
fn fix_windows_reg_key() {
174170
use winreg::RegKey;
175-
use winreg::enums::RegType;
176-
use winapi::*;
171+
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
177172

178173
let root = RegKey::predef(HKEY_CURRENT_USER);
179174
let env = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE);

src/rustup-cli/self_update.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -944,11 +944,12 @@ fn delete_rustup_and_cargo_home() -> Result<()> {
944944
let numbah: u32 = rand::random();
945945
let gc_exe = work_path.join(&format!("rustup-gc-{:x}.exe", numbah));
946946

947-
use winapi::{FILE_SHARE_DELETE, FILE_SHARE_READ,
948-
INVALID_HANDLE_VALUE, FILE_FLAG_DELETE_ON_CLOSE,
949-
DWORD, SECURITY_ATTRIBUTES, OPEN_EXISTING,
950-
GENERIC_READ};
951-
use kernel32::{CreateFileW, CloseHandle};
947+
use winapi::um::fileapi::{CreateFileW, OPEN_EXISTING};
948+
use winapi::um::handleapi::{CloseHandle, INVALID_HANDLE_VALUE};
949+
use winapi::um::minwinbase::SECURITY_ATTRIBUTES;
950+
use winapi::um::winbase::FILE_FLAG_DELETE_ON_CLOSE;
951+
use winapi::um::winnt::{FILE_SHARE_DELETE, FILE_SHARE_READ, GENERIC_READ};
952+
use winapi::shared::minwindef::DWORD;
952953
use std::os::windows::ffi::OsStrExt;
953954
use std::ptr;
954955
use std::io;
@@ -1028,11 +1029,13 @@ pub fn complete_windows_uninstall() -> Result<()> {
10281029

10291030
#[cfg(windows)]
10301031
fn wait_for_parent() -> Result<()> {
1031-
use kernel32::{Process32First, Process32Next,
1032-
CreateToolhelp32Snapshot, CloseHandle, OpenProcess,
1033-
GetCurrentProcessId, WaitForSingleObject};
1034-
use winapi::{PROCESSENTRY32, INVALID_HANDLE_VALUE, DWORD, INFINITE,
1035-
TH32CS_SNAPPROCESS, SYNCHRONIZE, WAIT_OBJECT_0};
1032+
use winapi::shared::minwindef::DWORD;
1033+
use winapi::um::handleapi::{CloseHandle, INVALID_HANDLE_VALUE};
1034+
use winapi::um::processthreadsapi::{OpenProcess, GetCurrentProcessId};
1035+
use winapi::um::synchapi::WaitForSingleObject;
1036+
use winapi::um::tlhelp32::{CreateToolhelp32Snapshot, Process32First, Process32Next, PROCESSENTRY32, TH32CS_SNAPPROCESS};
1037+
use winapi::um::winbase::{INFINITE, WAIT_OBJECT_0};
1038+
use winapi::um::winnt::SYNCHRONIZE;
10361039
use std::io;
10371040
use std::mem;
10381041
use std::ptr;
@@ -1172,9 +1175,9 @@ fn do_add_to_path(methods: &[PathUpdateMethod]) -> Result<()> {
11721175
assert!(methods.len() == 1 && methods[0] == PathUpdateMethod::Windows);
11731176

11741177
use winreg::{RegKey, RegValue};
1175-
use winreg::enums::RegType;
1176-
use winapi::*;
1177-
use user32::*;
1178+
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
1179+
use winapi::shared::minwindef::*;
1180+
use winapi::um::winuser::{SendMessageTimeoutA, HWND_BROADCAST, WM_SETTINGCHANGE, SMTO_ABORTIFHUNG};
11781181
use std::ptr;
11791182

11801183
let old_path = if let Some(s) = try!(get_windows_path_var()) {
@@ -1224,7 +1227,7 @@ fn do_add_to_path(methods: &[PathUpdateMethod]) -> Result<()> {
12241227
#[cfg(windows)]
12251228
fn get_windows_path_var() -> Result<Option<String>> {
12261229
use winreg::RegKey;
1227-
use winapi::*;
1230+
use winreg::enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
12281231
use std::io;
12291232

12301233
let root = RegKey::predef(HKEY_CURRENT_USER);
@@ -1281,10 +1284,10 @@ fn get_remove_path_methods() -> Result<Vec<PathUpdateMethod>> {
12811284
fn do_remove_from_path(methods: &[PathUpdateMethod]) -> Result<()> {
12821285
assert!(methods.len() == 1 && methods[0] == PathUpdateMethod::Windows);
12831286

1287+
use winapi::shared::minwindef::*;
1288+
use winapi::um::winuser::{SendMessageTimeoutA, SMTO_ABORTIFHUNG, HWND_BROADCAST, WM_SETTINGCHANGE};
12841289
use winreg::{RegKey, RegValue};
1285-
use winreg::enums::RegType;
1286-
use winapi::*;
1287-
use user32::*;
1290+
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
12881291
use std::ptr;
12891292

12901293
let old_path = if let Some(s) = try!(get_windows_path_var()) {

src/rustup-dist/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ rustup-mock = { path = "../rustup-mock" }
3232
tempdir = "0.3.4"
3333

3434
[target."cfg(windows)".dependencies]
35-
winapi = "0.2.8"
35+
winapi = { version = "0.3", features = ["handleapi", "sysinfoapi", "tlhelp32", "winnt"] }
3636
winreg = "0.4"
37-
user32-sys = "0.2.0"
38-
kernel32-sys = "0.2.1"
3937

4038
[target."cfg(not(windows))".dependencies]
4139
libc = "0.2.0"

src/rustup-dist/src/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl TargetTriple {
116116
pub fn from_host() -> Option<Self> {
117117
#[cfg(windows)]
118118
fn inner() -> Option<TargetTriple> {
119-
use kernel32::GetNativeSystemInfo;
119+
use winapi::um::sysinfoapi::GetNativeSystemInfo;
120120
use std::mem;
121121

122122
// First detect architecture
@@ -129,7 +129,7 @@ impl TargetTriple {
129129
GetNativeSystemInfo(&mut sys_info);
130130
}
131131

132-
let arch = match sys_info.wProcessorArchitecture {
132+
let arch = match unsafe { sys_info.u.s() }.wProcessorArchitecture {
133133
PROCESSOR_ARCHITECTURE_AMD64 => "x86_64",
134134
PROCESSOR_ARCHITECTURE_INTEL => "i686",
135135
_ => return None,

src/rustup-dist/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ extern crate sha2;
1616
extern crate winapi;
1717
#[cfg(windows)]
1818
extern crate winreg;
19-
#[cfg(windows)]
20-
extern crate user32;
21-
#[cfg(windows)]
22-
extern crate kernel32;
2319
#[cfg(not(windows))]
2420
extern crate libc;
2521

src/rustup-mock/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ sha2 = "0.6.0"
2222
wait-timeout = "0.1.3"
2323

2424
[target."cfg(windows)".dependencies]
25-
winapi = "0.2.8"
25+
winapi = "0.3"
2626
winreg = "0.4.0"
2727

src/rustup-mock/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl MockContents {
165165
#[cfg(windows)]
166166
pub fn get_path() -> Option<String> {
167167
use winreg::RegKey;
168-
use winapi::*;
168+
use winreg::enums::{HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
169169

170170
let root = RegKey::predef(HKEY_CURRENT_USER);
171171
let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE).unwrap();
@@ -176,8 +176,7 @@ pub fn get_path() -> Option<String> {
176176
#[cfg(windows)]
177177
pub fn restore_path(p: &Option<String>) {
178178
use winreg::{RegKey, RegValue};
179-
use winreg::enums::RegType;
180-
use winapi::*;
179+
use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE};
181180

182181
let root = RegKey::predef(HKEY_CURRENT_USER);
183182
let environment = root.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE).unwrap();

src/rustup-utils/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ toml = "0.4"
2424
url = "1.1"
2525

2626
[target."cfg(windows)".dependencies]
27-
advapi32-sys = "0.2.0"
28-
kernel32-sys = "0.2.1"
29-
ole32-sys = "0.2.0"
30-
shell32-sys = "0.1.1"
31-
userenv-sys = "0.2.0"
32-
winapi = "0.2.8"
27+
winapi = { version = "0.3", features = ["combaseapi", "errhandlingapi", "fileapi", "handleapi",
28+
"ioapiset", "minwindef", "processthreadsapi", "shlobj", "shtypes", "userenv", "winbase", "winerror", "winnt", "winioctl"] }
3329
winreg = "0.4.0"

src/rustup-utils/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ extern crate semver;
1414
extern crate winapi;
1515
#[cfg(windows)]
1616
extern crate winreg;
17-
#[cfg(windows)]
18-
extern crate shell32;
19-
#[cfg(windows)]
20-
extern crate ole32;
21-
#[cfg(windows)]
22-
extern crate kernel32;
23-
#[cfg(windows)]
24-
extern crate advapi32;
25-
#[cfg(windows)]
26-
extern crate userenv;
2717

2818
#[cfg(unix)]
2919
extern crate libc;

0 commit comments

Comments
 (0)