Migrate from winapi to windows-sys (#4346)

* Migrate from `winapi` to `windows-sys`

I believe that Microsoft itself is supporting the development of
`windows-sys` and it's also used by `cap-std` now so this switches
Wasmtime's dependencies on Windows APIs from the `winapi` crate to the
`windows-sys` crate. We still have `winapi` in our dependency graph but
that may get phased out over time.

* Make windows-sys a target-specific dependency
This commit is contained in:
Alex Crichton
2022-06-28 13:02:41 -05:00
committed by GitHub
parent 27b94a4173
commit df1502531d
15 changed files with 79 additions and 68 deletions

View File

@@ -29,8 +29,11 @@ rustc-demangle = "0.1.16"
cpp_demangle = "0.3.2"
log = "0.4.8"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.8", features = ["winnt", "impl-default"] }
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = "0.36.0"
features = [
"Win32_System_Diagnostics_Debug",
]
[target.'cfg(target_os = "linux")'.dependencies]
rustix = { version = "0.35.6", features = ["process"] }

View File

@@ -2,7 +2,7 @@
use anyhow::{bail, Result};
use std::mem;
use winapi::um::winnt;
use windows_sys::Win32::System::Diagnostics::Debug::*;
/// Represents a registry of function unwind information for Windows x64 ABI.
pub struct UnwindRegistration {
@@ -16,9 +16,9 @@ impl UnwindRegistration {
unwind_len: usize,
) -> Result<UnwindRegistration> {
assert!(unwind_info as usize % 4 == 0);
let unit_len = mem::size_of::<winnt::RUNTIME_FUNCTION>();
let unit_len = mem::size_of::<IMAGE_RUNTIME_FUNCTION_ENTRY>();
assert!(unwind_len % unit_len == 0);
if winnt::RtlAddFunctionTable(
if RtlAddFunctionTable(
unwind_info as *mut _,
(unwind_len / unit_len) as u32,
base_address as u64,
@@ -40,7 +40,7 @@ impl UnwindRegistration {
impl Drop for UnwindRegistration {
fn drop(&mut self) {
unsafe {
winnt::RtlDeleteFunctionTable(self.functions as _);
RtlDeleteFunctionTable(self.functions as _);
}
}
}