

Start using `windows sys` for Windows FFI bindings in std by ChrisDenton · Pull...
source link: https://github.com/rust-lang/rust/pull/110152
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Start using windows sys
for Windows FFI bindings in std
#110152
Conversation
Contributor
Switch to using windows-sys for FFI. In order to avoid some currently contentious issues, this uses windows-bindgen to generate a smaller set of bindings instead of using the full crate.
Unlike the windows-sys crate, the generated bindings uses *mut c_void
for handle types instead of isize
. This to sidestep opsem concerns about mixing pointer types and integers between languages. Note that SOCKET
remains defined as an integer but instead of being a usize, it's changed to fit the standard library definition:
#[cfg(target_pointer_width = "32")]
pub type SOCKET = u32;
#[cfg(target_pointer_width = "64")]
pub type SOCKET = u64;
The generated bindings also customizes the #[link]
imports. I hope to switch to using raw-dylib but I don't want to tie that too closely with the switch to windows-sys.
Changes outside of the bindings are, for the most part, fairly minimal (e.g. some differences in *mut
vs. *const
or a few types differ). One issue is that our own bindings sometimes mix in higher level types, like BorrowedHandle
. This is pretty adhoc though.
Collaborator
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
labels
Contributor
Author
(rebased on master branch) |
Definitely want to avoid using a hacked |
Contributor
Author
It's mostly just making the following the edits, which I believe could be done by using the
The most hacky thing it does is change the way imports work to fit std's currently style. E.g.:
But I do hope we can move to raw-dylib. |
This comment has been minimized.
For the type changes, can we find some middle ground with the Win32 metadata or is there a technical reason you need these just so? I’d prefer that we don’t manage forked metadata in the short term as I’m working on some Rust-friendly metadata authoring support which will make this a lot easier in the long run. For the imports, is that because We could also plausibly add a |
For that matter, I'd be happy to discuss changes to |
Contributor
Author
To take the changes one by one...
There are still some discussion about how handle types should be... handled. By keeping the status quo within the std I was hoping to avoid trying to force that issue at this time. I suspect it may be a blocker otherwise.
This is less of an issue but Rust stably defines the
The linking changes again are there to keep the status quo for now. Using |
For the handle types, I would like the metadata to actually store the true native type def rather than tip the scales in favor of C#. We'll likely get that resolved on the Rust side with the new metadata authoring support. Anyway, sounds like adding standalone flags to |
Contributor
Author
For sure! That sounds good to me. |
Take this for a spin: microsoft/windows-rs#2439 |
added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label
Contributor
Author
Ok, I've updated this PR and the description to reflect the current code gen. This no longer uses a hacked windows-bindgen (see above) but a few things still differ between regular windows-sys and these bindings (see OP). |
This comment has been minimized.
The update looks great! Let me know when you need me to publish an update of the |
Contributor
Author
Sure thing. I think I'd want to wait for the next metadata update but there's no rush, I'm happy to let this sit for a little bit to give people time to comment, if anyone is inclined to do so. |
Contributor
|
This comment has been minimized.
This comment has been minimized.
Contributor
|
Contributor
Author
Ok, I think with the latest metadata this is looking good to go. @kennykerr, A new release of |
removed A-testsuite Area: The testsuite used to check the correctness of rustc T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
labels
Sorry for the delay here, I've been occupied with family stuff.
This looks great and avoids most of the problems I'd normally complain about in something like this . (In particular, windows-sys is heavyweight enough compared to what we need from it that I prefer this approach to a direct dep)
Only real nit is that IMO we should require the .lst file be sorted, (and verify that in CI). I'd accept an argument for why it's fine as-is if you feel really strongly, though.
Member
@rustbot author |
added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
labels
Contributor
Author
I've sorted @rustbot ready |
added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
labels
Member
Sorry if I'm blind, but I don't see a change to tidy. |
Contributor
Author
Tidy checks everything between |
Member
Oh, my bad. Yeah, thanks @bors r+ |
added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
labels
Contributor
|
Collaborator
Finished benchmarking commit (7e7483d): comparison URL. Overall result:
|
mean | range | count | |
---|---|---|---|
Regressions ![]() (primary) |
- | - | 0 |
Regressions ![]() (secondary) |
- | - | 0 |
Improvements ![]() (primary) |
- | - | 0 |
Improvements ![]() (secondary) |
-0.3% | [-0.3%, -0.3%] | 1 |
All ![]() ![]() |
- | - | 0 |
Max RSS (memory usage)
Results
Cycles
This benchmark run did not return any relevant results for this metric.
Binary size
This benchmark run did not return any relevant results for this metric.
Bootstrap: 656.874s -> 656.5s (-0.06%)
Contributor
It appears this merge has broken
It's unclear to me why doctest wants to build this Windows-specific file on a non-Windows platform (and why this apparently does not cause failures on any other non-Windows platform?). |
Contributor
Author
Yes that puzzled me too so I made a PR to remove it (#111401). Hopefully that should fix the issue. |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Successfully merging this pull request may close these issues.
None yet
Recommend
-
10
Conversation Copy link Contributor ...
-
9
Copy link Contributor ChrisDenton...
-
7
Copy link Contributor ChrisDenton...
-
7
Resolve `process::Command` program without using the current directory by ChrisDenton · Pull Request #87704 · rust-lang/rust · GitHub Copy link Contributor...
-
8
Conversation Copy link Contribu...
-
8
Copy link Contributor ChrisDenton
-
3
Copy link Contributor ChrisDenton
-
9
Copy link Contributor
-
5
Conversation Contributor...
-
16
Conversation Contributor...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK