Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace miow, winapi, and ntapi with windows-sys #1556

Merged
merged 12 commits into from
Mar 31, 2022

Conversation

Jake-Shadle
Copy link
Contributor

@Jake-Shadle Jake-Shadle commented Mar 18, 2022

This removes the dependency on miow, winapi, and ntapi in favor of just using windows-sys directly. A few types/functions from miow were copied, and added, namely the Handle wrapper (for CloseHandle dropping) and the CompletionPort and CompletionStatus types.

There was only a single function, NtCancelIoFileEx that was present in ntapi but not windows-sys, so I merely added the extern declaration in the one place it was used as it is not worth bringing in a dependency just for that.

Note this uses the latest window-sys version, but I think the version restriction can be loosened to >=0.32 as (probably) the only actual relevant change for mio was the change of HANDLE from *mut c_void to isize. This is unfortunately a downside of the windows-sys crate, its minor version is bumped fairly frequently, but other than changes such as the one previously mentioned, most of those versions won't actually meaningfully affect mio's usage, and having an exact version requirement could mean duplicate versions of the windows-sys crates being used in downstream crates if they use a slightly newer version of it that is otherwise fully API compatible. Though of course the safest is to have >=0.32, <=0.34 to avoid a minor version > 0.34 actually having breaking changes for mio and downstream crates failing to compile unless they manually pin the version.

This updates miow to 0.4, which now uses the windows-sys crate instead
of winapi, as the former is maintained and updated frequently as opposed
to winapi. The windows-sys crate also covers more of the Windows API
surface, which also allowed me to remove the dependency on ntapi (as it
still depends on winapi). There was only a single function,
`NtCancelIoFileEx` that was present in ntapi but not windows-sys, so I
merely added the extern declaration in the one place it was used as it
is not worth bringing in a dependency just for that.
@Thomasdezeeuw
Copy link
Collaborator

I think @Noah-Kennedy was working on this as well.

@kennykerr
Copy link

Might be worth switching miow and mio directly to windows-sys version 0.33 as that is what the prominent parking_lot and winit crates have adopted.

@yoshuawuyts

@kennykerr
Copy link

kennykerr commented Mar 18, 2022

Here's a PR to update miow to use windows-sys 0.33: yoshuawuyts/miow#54

@Thomasdezeeuw
Copy link
Collaborator

Thomasdezeeuw commented Mar 18, 2022

Might be worth switching miow and mio directly to windows-sys version 0.33 as that is what the prominent parking_lot and winit crates have adopted.

I think it was @Noah-Kennedy idea to switch directly to use windows-sys/winapi as well, but I'm not 100% sure about that.

@Noah-Kennedy
Copy link

I think its probably best to just use either winapi or windows-sys directly and not depend on miow.

@Jake-Shadle
Copy link
Contributor Author

I can remove the dependency on miow in this PR if that's what's wanted? I love removing dependencies.

@Thomasdezeeuw
Copy link
Collaborator

I can remove the dependency on miow in this PR if that's what's wanted? I love removing dependencies.

Sounds good.

@Jake-Shadle Jake-Shadle changed the title Replace winapi/ntapi with windows-sys Replace miow, winapi, and ntapi with windows-sys Mar 21, 2022
Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave it a could look now, will do a proper review later.

One thing I noticed that you define various constants, I think those should all be moved to windows-sys.

src/sys/windows/afd.rs Show resolved Hide resolved
src/sys/windows/afd.rs Outdated Show resolved Hide resolved

/// Wrapper around a Windows HANDLE so that we close it upon drop in all scenarios
#[derive(Debug)]
pub struct Handle(HANDLE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a review comment, but future work: we can replace this with std::os::windows::io::OwnedHandle (currently unstable).

src/sys/windows/net.rs Outdated Show resolved Hide resolved
const SIO_BSP_HANDLE: u32 = IOC_OUT | IOC_WS2 | 27; // 1_207_959_579u32
const SIO_BSP_HANDLE_SELECT: u32 = IOC_OUT | IOC_WS2 | 28; // 1_207_959_580u32
const SIO_BSP_HANDLE_POLL: u32 = IOC_OUT | IOC_WS2 | 29; // 1_207_959_581u32
const SIO_BASE_HANDLE: u32 = IOC_OUT | IOC_WS2 | 34; // 1_207_959_586u32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these not in windows-sys?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @Noah-Kennedy can you review this as well?

Some future work:

@Thomasdezeeuw
Copy link
Collaborator

One open question is should this be a part of v0.8.x or v0.9.x? We don't use winapi's types publicly, but the rest of the ecosystem might still be using it, having both winapi and windows-sys might become a problem.

/// ports and waiting to receive the completion notification on the port.
pub unsafe fn read_overlapped(
&self,
buf: &mut [u8],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never quite been a fan of how miow did this, as its kinda a footgun. Still, I can't think of anything actively harmful about taking this in as an arg.

@Thomasdezeeuw Thomasdezeeuw merged commit fc2080c into tokio-rs:master Mar 31, 2022
@Thomasdezeeuw
Copy link
Collaborator

Thanks @Jake-Shadle! We can do some of the future work lined out in #1556 (review) in a future pr

@Thomasdezeeuw
Copy link
Collaborator

Created #1558 to keep track of that future work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants