migrate compiler, bootstrap, and compiletest to windows-rs
This commit is contained in:
parent
13b7aa4d7f
commit
bb7c373fdf
22 changed files with 381 additions and 282 deletions
|
@ -36,8 +36,15 @@ elsa = "1.8"
|
|||
[dependencies.parking_lot]
|
||||
version = "0.11"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3", features = ["fileapi", "psapi", "winerror"] }
|
||||
[target.'cfg(windows)'.dependencies.windows]
|
||||
version = "0.46.0"
|
||||
features = [
|
||||
"Win32_Foundation",
|
||||
"Win32_Storage_FileSystem",
|
||||
"Win32_System_IO",
|
||||
"Win32_System_ProcessStatus",
|
||||
"Win32_System_Threading",
|
||||
]
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
memmap2 = "0.2.1"
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
//! green/native threading. This is just a bare-bones enough solution for
|
||||
//! librustdoc, it is not production quality at all.
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(nonstandard_style)]
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_os = "linux")] {
|
||||
mod linux;
|
||||
|
@ -16,7 +13,7 @@ cfg_if! {
|
|||
use unix as imp;
|
||||
} else if #[cfg(windows)] {
|
||||
mod windows;
|
||||
use windows as imp;
|
||||
use self::windows as imp;
|
||||
} else {
|
||||
mod unsupported;
|
||||
use unsupported as imp;
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
use std::fs::{File, OpenOptions};
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::os::windows::prelude::*;
|
||||
use std::path::Path;
|
||||
|
||||
use winapi::shared::winerror::ERROR_INVALID_FUNCTION;
|
||||
use winapi::um::fileapi::LockFileEx;
|
||||
use winapi::um::minwinbase::{LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY, OVERLAPPED};
|
||||
use winapi::um::winnt::{FILE_SHARE_DELETE, FILE_SHARE_READ, FILE_SHARE_WRITE};
|
||||
use windows::{
|
||||
Win32::Foundation::{ERROR_INVALID_FUNCTION, HANDLE},
|
||||
Win32::Storage::FileSystem::{
|
||||
LockFileEx, FILE_SHARE_DELETE, FILE_SHARE_READ, FILE_SHARE_WRITE, LOCKFILE_EXCLUSIVE_LOCK,
|
||||
LOCKFILE_FAIL_IMMEDIATELY, LOCK_FILE_FLAGS,
|
||||
},
|
||||
Win32::System::IO::OVERLAPPED,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Lock {
|
||||
|
@ -25,7 +28,7 @@ impl Lock {
|
|||
let share_mode = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
|
||||
let mut open_options = OpenOptions::new();
|
||||
open_options.read(true).share_mode(share_mode);
|
||||
open_options.read(true).share_mode(share_mode.0);
|
||||
|
||||
if create {
|
||||
open_options.create(true).write(true);
|
||||
|
@ -43,33 +46,42 @@ impl Lock {
|
|||
}
|
||||
};
|
||||
|
||||
let ret = unsafe {
|
||||
let mut overlapped: OVERLAPPED = mem::zeroed();
|
||||
|
||||
let mut dwFlags = 0;
|
||||
if !wait {
|
||||
dwFlags |= LOCKFILE_FAIL_IMMEDIATELY;
|
||||
}
|
||||
|
||||
if exclusive {
|
||||
dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
|
||||
}
|
||||
|
||||
debug!("attempting to acquire lock on lock file `{}`", p.display());
|
||||
LockFileEx(file.as_raw_handle(), dwFlags, 0, 0xFFFF_FFFF, 0xFFFF_FFFF, &mut overlapped)
|
||||
};
|
||||
if ret == 0 {
|
||||
let err = io::Error::last_os_error();
|
||||
debug!("failed acquiring file lock: {}", err);
|
||||
Err(err)
|
||||
} else {
|
||||
debug!("successfully acquired lock");
|
||||
Ok(Lock { _file: file })
|
||||
let mut flags = LOCK_FILE_FLAGS::default();
|
||||
if !wait {
|
||||
flags |= LOCKFILE_FAIL_IMMEDIATELY;
|
||||
}
|
||||
|
||||
if exclusive {
|
||||
flags |= LOCKFILE_EXCLUSIVE_LOCK;
|
||||
}
|
||||
|
||||
let mut overlapped = OVERLAPPED::default();
|
||||
|
||||
debug!("attempting to acquire lock on lock file `{}`", p.display());
|
||||
|
||||
unsafe {
|
||||
LockFileEx(
|
||||
HANDLE(file.as_raw_handle() as isize),
|
||||
flags,
|
||||
0,
|
||||
u32::MAX,
|
||||
u32::MAX,
|
||||
&mut overlapped,
|
||||
)
|
||||
}
|
||||
.ok()
|
||||
.map_err(|e| {
|
||||
let err = io::Error::from_raw_os_error(e.code().0);
|
||||
debug!("failed acquiring file lock: {}", err);
|
||||
err
|
||||
})?;
|
||||
|
||||
debug!("successfully acquired lock");
|
||||
Ok(Lock { _file: file })
|
||||
}
|
||||
|
||||
pub fn error_unsupported(err: &io::Error) -> bool {
|
||||
err.raw_os_error() == Some(ERROR_INVALID_FUNCTION as i32)
|
||||
err.raw_os_error() == Some(ERROR_INVALID_FUNCTION.0 as i32)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -796,21 +796,26 @@ fn get_thread_id() -> u32 {
|
|||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
pub fn get_resident_set_size() -> Option<usize> {
|
||||
use std::mem::{self, MaybeUninit};
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::um::processthreadsapi::GetCurrentProcess;
|
||||
use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
|
||||
use std::mem;
|
||||
|
||||
let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
|
||||
match unsafe {
|
||||
GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
|
||||
} {
|
||||
0 => None,
|
||||
_ => {
|
||||
let pmc = unsafe { pmc.assume_init() };
|
||||
Some(pmc.WorkingSetSize as usize)
|
||||
}
|
||||
use windows::{
|
||||
Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
|
||||
Win32::System::Threading::GetCurrentProcess,
|
||||
};
|
||||
|
||||
let mut pmc = PROCESS_MEMORY_COUNTERS::default();
|
||||
let pmc_size = mem::size_of_val(&pmc);
|
||||
unsafe {
|
||||
K32GetProcessMemoryInfo(
|
||||
GetCurrentProcess(),
|
||||
&mut pmc,
|
||||
pmc_size as u32,
|
||||
)
|
||||
}
|
||||
.ok()
|
||||
.ok()?;
|
||||
|
||||
Some(pmc.WorkingSetSize)
|
||||
}
|
||||
} else if #[cfg(target_os = "macos")] {
|
||||
pub fn get_resident_set_size() -> Option<usize> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue