Skip to content

use winapi crate instead of generating bindings to windows.h #1562

New issue

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

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

Already on GitHub? # to your account

Closed
ghost opened this issue May 16, 2019 · 8 comments
Closed

use winapi crate instead of generating bindings to windows.h #1562

ghost opened this issue May 16, 2019 · 8 comments

Comments

@ghost
Copy link

ghost commented May 16, 2019

Hi, I couln't find any way to do this in docs or the book, I am generating bindings to vulkan but when I add a definition to make it include windows support It includes windows.h, build takes a long time and it crashes with no output. I want to ignore the windows.h include somehow and use winapi crate instead. Is there a way to this?

@emilio
Copy link
Contributor

emilio commented May 16, 2019

The way to do something like that is to blacklist the windows types and adding something like use winapi::* using raw_line.

Bindgen shouldn't be crashing though (and it's somewhat suprising it does since I'm pretty sure on Firefox bindgen ends up including windows.h without issues).

I don't have a windows machine, but would there be any chance for you to try to dump the contents make bindgen crash for you and upload them here?

A reduced test-case would be extra-awesome, but just a reproducible crash / hang is awesome on its own.

@ghost
Copy link
Author

ghost commented May 17, 2019

hi, bindgen doesn't crash but I get this error when compiling the generated bindings: error[E0588]: packed type cannot transitively contain a [repr(align)] type. the generated rust file is 1 line so the error was too long, thats why I couldn't see anything. so I think this is duplıcate of #1538.

@ghost ghost closed this as completed May 17, 2019
@emilio
Copy link
Contributor

emilio commented May 17, 2019

Yeah, with_rustfmt and such helps a lot to diagnose errors :)

@bugproof
Copy link

bugproof commented Aug 2, 2020

Why was this issue closed? IMO there should be a switch like --use-winapi

@kulp
Copy link
Member

kulp commented Aug 2, 2020

Why was this issue closed? IMO there should be a switch like --use-winapi

The original author came to believe the underlying issue is a duplicate of another open issue.

@bugproof, if you have a need, maybe you should open a new issue to describe what use you would have for --use-winapi.

@sam0x17
Copy link

sam0x17 commented May 30, 2021

I have the same problem. Was there ever a solution?

Reproducible example is literally a header file that includes windows.h. In my case this is what is leading to it:

#include <windows.h>
#include "ViGEm/Client.h"

//
// Link against SetupAPI
//
#pragma comment(lib, "setupapi.lib")

Ideally there would be some kind of windows.h shim I could include that will automatically get converted to use the winapi crate when bindgen sees it. Short of that I don't see how this is going to work as the library I'm linking with uses windows.h types all over the place

@sam0x17
Copy link

sam0x17 commented May 30, 2021

followup: Looks like if you blacklist the following types build will succeed with all of windows.h:

        .blacklist_type("_IMAGE_TLS_DIRECTORY64")
        .blacklist_type("IMAGE_TLS_DIRECTORY64")
        .blacklist_type("PIMAGE_TLS_DIRECTORY64")
        .blacklist_type("IMAGE_TLS_DIRECTORY")
        .blacklist_type("PIMAGE_TLS_DIRECTORY")

superbort added a commit to Ximea-GmbH/xiapi-sys that referenced this issue Oct 11, 2021
Add Windows specific paths to build.rs.

Add wintypedefs.h to the project. The header files are interpreted in the same way on all platforms, so files specific to the Linux package must be added to allow for building on Windows. The alternative would be to include the complete windows.h header in the bindings, which currently fails via bindgen and produces much bigger files. See also: rust-lang/rust-bindgen#1562
@IoIxD
Copy link

IoIxD commented Dec 14, 2023

Hey, can somebody here answer the original question a bit better?

How am I supposed to "blacklist the windows types"? I tried blocklisting windows.h and that doesn't work. I was suggested to use regex to filter out all the functions, but Microsoft uses hungarian notation so that doesn't work.

This issue was closed.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants