Clang compiler errors when generating Rust bindings on Windows

I’m working on rust-lv2, a Rust library that provides an idiomatic framework for LV2 Plugins. One part of the library is the binding of the C API. This is generated using bindgen every time the library is built, which internally uses Clang to analyze the headers.

This works perfectly on Linux, MacOS, and my local Windows machine, but not on Travis CI’s Windows machines; The compiler complains about malformed headers from MSVC. I was not able to change anything about that or reproduce it on my system, which is why I’m posting it here. The errors I’m talking about are found, for example, in this build of this commit; All required information is found there.

What does this mean? I must admit that I’m more into Linux than into Windows and don’t quite know how this all works together. Is this a known error or is that due to the special Rust/Bindgen/MSVC/Clang relationship? Nonetheless, this an error that should be fixed and may be fixable, since it works fine on Linux and MacOS.

Rustup only supports MSVC and GCC toolchains in Windows (x86_64-pc-windows-gnu being the default for Travis) which don’t provide CLang.

I guess you could install a Windows version of CLang separately, but I’ve no idea how to make it use the same configuration (header search paths, predefined macros) as the stock toolchain would. You should probably ask Rustup maintainers for guidance here.

It’s possible though that Bindgen takes care of that and you only need to point it to a CLang installation as the error message says:

cargo:warning=couldn’t execute llvm-config --prefix (error: The system cannot find the file specified. (os error 2))
cargo:warning=set the LLVM_CONFIG_PATH environment variable to the full path to a valid llvm-config executable (including the executable itself)

xkcd-979

I had the same problem. Could not find an answer. This is for the next person who googles this.

language: rust
os:
  - linux
  - windows
rust:
  - stable
  - beta
  - nightly
jobs:
  allow_failures:
    - rust: nightly
  fast_finish: true
script:
  - |
    if [ "$TRAVIS_OS_NAME" = "windows" ]; then
      export LIBCLANG_PATH="C:\\Program Files\\LLVM\\\\bin"
      export TARGET="x86_64-pc-windows-msvc"
    else
      export TARGET="x86_64-unknown-linux-gnu"
    fi
  - rustup target add "$TARGET"
  - cargo build --verbose --target "$TARGET" --all
  - cargo test --verbose --target "$TARGET" --all
1 Like