Skip to content

Commit

Permalink
chore: Switch to the windows crate (#2077)
Browse files Browse the repository at this point in the history
* chore: Switch to the `windows` crate

The `winapi` isn't being updated anymore, and the `windows` crate is a
more modern alternative maintained by Microsoft.

* Fix
  • Loading branch information
larseggert authored Aug 28, 2024
1 parent 910a7cd commit a793d4a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions neqo-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ hex = { version = "0.4", default-features = false, features = ["alloc"], optiona
log = { workspace = true }
qlog = { workspace = true }

[target."cfg(windows)".dependencies]
# Sync with https://searchfox.org/mozilla-central/source/Cargo.lock 2024-02-08
windows = { version = "0.58", default-features = false, features = ["Win32_Media"] }

[dev-dependencies]
test-fixture = { path = "../test-fixture" }

[features]
ci = []
build-fuzzing-corpus = ["hex"]

[target."cfg(windows)".dependencies.winapi]
version = "0.3"
features = ["timeapi"]

[lib]
# See https://github.com/bheisler/criterion.rs/blob/master/book/src/faq.md#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false
12 changes: 5 additions & 7 deletions neqo-common/src/hrtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use std::{
};

#[cfg(windows)]
use winapi::shared::minwindef::UINT;
#[cfg(windows)]
use winapi::um::timeapi::{timeBeginPeriod, timeEndPeriod};
use windows::Win32::Media::{timeBeginPeriod, timeEndPeriod};

/// A quantized `Duration`. This currently just produces 16 discrete values
/// corresponding to whole milliseconds. Future implementations might choose
Expand All @@ -26,8 +24,8 @@ impl Period {
const MIN: Self = Self(1);

#[cfg(windows)]
fn as_uint(self) -> UINT {
UINT::from(self.0)
fn as_u32(self) -> u32 {
u32::from(self.0)
}

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -299,7 +297,7 @@ impl Time {
#[cfg(target_os = "windows")]
fn start(&self) {
if let Some(p) = self.active {
_ = unsafe { timeBeginPeriod(p.as_uint()) };
_ = unsafe { timeBeginPeriod(p.as_u32()) };
}
}

Expand All @@ -310,7 +308,7 @@ impl Time {
#[cfg(windows)]
fn stop(&self) {
if let Some(p) = self.active {
_ = unsafe { timeEndPeriod(p.as_uint()) };
_ = unsafe { timeEndPeriod(p.as_u32()) };
}
}

Expand Down

0 comments on commit a793d4a

Please sign in to comment.