rust-lang / rust-lang/rust-bindgen

Bindgen tries to use MSVC headers when using x86_64-pc-windows-gnu target

Open
#1,760 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted msvc
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

I'm using bindgen as part of a build.rs script. I would like to test that it works with x86_64-pc-windows-gnu, however it does not appear to.

My default rustup toolchain is stable-x86_64-pc-windows-gnu, however bindgen appears to be grabbing MSVC headers instead.

Example output:

D:\Code\libui-rs>cargo run --example inputs
   Compiling ui-sys v0.2.1 (D:\Code\libui-rs\ui-sys)
error: failed to run custom build command for `ui-sys v0.2.1 (D:\Code\libui-rs\ui-sys)`

Caused by:
  process didn't exit successfully: `D:\Code\libui-rs\target\debug\build\ui-sys-d4418d11d6941dbf\build-script-build` (exit code: 101)
--- stderr
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vadefs.h:28:33: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:93:1: error: expected identifier
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:93:20: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:190:29: error: expected ';' after top level declarator
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:191:30: error: typedef redefinition with different types ('__int64' (aka 'unsigned int') vs 'long long')
C:\Program Files\LLVM\lib\clang\8.0.0\include\stddef.h:51:26: note: previous definition is here
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:339:51: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:340:67: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:344:8: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:352:1: error: a parameter list without types is only allowed in a function definition
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:352:18: error: expected ';' after top level declarator
./libui/ui.h:84:2: error: type name requires a specifier or qualifier
./libui/ui.h:84:14: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
./libui/ui.h:98:12: error: unknown type name 'uintptr_t'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vadefs.h:28:33: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:93:1: error: expected identifier, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:93:20: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:190:29: error: expected ';' after top level declarator, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:191:30: error: typedef redefinition with different types ('__int64' (aka 'unsigned int') vs 'long long'), err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:339:51: error: unknown type name 'uintptr_t', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:340:67: error: unknown type name 'uintptr_t', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:344:8: error: unknown type name 'uintptr_t', err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:352:1: error: a parameter list without types is only allowed in a function definition, err: true
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:352:18: error: expected ';' after top level declarator, err: true
./libui/ui.h:84:2: error: type name requires a specifier or qualifier, err: true
./libui/ui.h:84:14: warning: type specifier missing, defaults to 'int' [-Wimplicit-int], err: false
./libui/ui.h:98:12: error: unknown type name 'uintptr_t', err: true
thread 'main' panicked at 'Unable to generate bindings: ()', ui-sys\build.rs:41:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


D:\Code\libui-rs>rustup show
Default host: x86_64-pc-windows-gnu
rustup home:  C:\Users\smcro\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-gnu (default)
stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-gnu (default)
rustc 1.42.0 (b8cedc004 2020-03-09)


D:\Code\libui-rs>

If I remove bindgen from my build.rs, then the cc crate is able to properly call gcc.exe and compile the rest of the crate, however I no longer have generated C bindings.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ui-sys/build.rs:41 and inspect how bindgen is invoked during the build, then reproduce the failure with the x86_64-pc-windows-gnu toolchain. Check the handling of the headers shown in the error, including libui/ui.h and the MSVC vadefs.h and vcruntime.h files. Done means bindings can be generated for the GNU target without the reported MSVC-header errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.