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

@@ -19,11 +19,11 @@ cfg-if = "1.0"
[target.'cfg(unix)'.dependencies]
rustix = { version = "0.35.6", features = ["mm", "param"] }
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3.9"
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.36.1"
features = [
"fibersapi",
"winbase",
"Win32_System_Threading",
"Win32_Foundation",
]
[build-dependencies]

View File

@@ -1,12 +1,10 @@
use crate::RunResult;
use std::cell::Cell;
use std::ffi::c_void;
use std::io;
use std::ptr;
use winapi::shared::minwindef::*;
use winapi::shared::winerror::ERROR_NOT_SUPPORTED;
use winapi::um::fibersapi::*;
use winapi::um::processthreadsapi::SetThreadStackGuarantee;
use winapi::um::winbase::*;
use windows_sys::Win32::Foundation::*;
use windows_sys::Win32::System::Threading::*;
#[derive(Debug)]
pub struct FiberStack(usize);
@@ -26,7 +24,7 @@ impl FiberStack {
}
pub struct Fiber {
fiber: LPVOID,
fiber: *mut c_void,
state: Box<StartState>,
}
@@ -35,18 +33,18 @@ pub struct Suspend {
}
struct StartState {
parent: Cell<LPVOID>,
parent: Cell<*mut c_void>,
initial_closure: Cell<*mut u8>,
result_location: Cell<*const u8>,
}
const FIBER_FLAG_FLOAT_SWITCH: DWORD = 1;
const FIBER_FLAG_FLOAT_SWITCH: u32 = 1;
extern "C" {
fn wasmtime_fiber_get_current() -> LPVOID;
fn wasmtime_fiber_get_current() -> *mut c_void;
}
unsafe extern "system" fn fiber_start<F, A, B, C>(data: LPVOID)
unsafe extern "system" fn fiber_start<F, A, B, C>(data: *mut c_void)
where
F: FnOnce(A, &super::Suspend<A, B, C>) -> C,
{