rust-lang / rust-lang/rust-bindgen
Telling libclang where to look for system includes on Windows
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
I've had success using bindgen on Windows with MSVC, but in order to do so I have to specify the INCLUDE environment variable as so (minus new-lines):
C:\Program Files (x86)\Microsoft Visual Studio\Shared\14.0\VC\include;
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt;
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\um;
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\shared
Without this definition clang fails to find the system headers. I also have to specify -fms-compatibility-version=19 (not 14) via Builder::clang_arg to get this to work.
Obviously this configuration is specific to this particular version of MSVC and my installation setup, so I'm reluctant to hard-code this into a crate that uses bindgen. Ideally bindgen would be able to, via use of the gcc crate, figure out whether additional configuration of libclang is necessary to match the system headers and ABI of the toolchain decided upon by the gcc crate (this allows bindgen output to match the ABI of, for example, external C++ code built with the cmake crate).
In terms of achieving this, it appears straightforward when the C++ compiler picked is gcc or clang, as they can be queried easily (via a flag) for the system include paths. It looks to be much harder to get this information out of MSVC. There are two "IDE" variables that contribute to the system include directories list by default, VC_IncludePath and WindowsSDK_IncludePath. Their definitions are in separate XML files whose locations vary based on MSVC version and installation. The most robust way of finding their values may be to have a MSVC project (perhaps generated using cmake) that builds an executable that prints them out.
Thoughts? Please note that implementing at least part of this would be of benefit when using gcc or clang, not just MSVC, as it would ensure bindgen matches the standard library implementation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with bindgen's Builder::clang_arg and the gcc crate's toolchain selection. Compare how gcc and clang expose system include paths with the MSVC environment variables described in the issue. Done means bindgen can obtain the selected toolchain's include paths and ABI settings without crate users hard-coding installation-specific values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp, rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100