KyleMayes / clang-sys

Rust bindings for libclang.
Apache License 2.0
128 stars 65 forks source link

Defaulting to older libclang on Windows (Inconvenient directory prioritization) #152

Closed kevin-cgc closed 1 year ago

kevin-cgc commented 1 year ago

Specifically, in my case, libclang from VS2019 (C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\Llvm\ v12.0.0) was being preferred over VS2022 (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\ v15.0.6) and the manually/explicitly installed LLVM (C:\Program Files\LLVM\ v15.0.6).

This leads to some unexpected behavior:

> clang --version
clang version 15.0.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
> bindgen.exe --version --verbose
bindgen 0.63.0
Clang: clang version 12.0.0

For me, setting $env:LIBCLANG_PATH="C:\Program Files\LLVM\bin\" allowed me to use clang 15.0.6 with no issues.

I think C:\Program Files\LLVM\ should be prioritized over Visual Studio installations, given that it is generally the most explicitly installed version, and is likely the clang version exposed on the PATH. It would also be nice if newer versions of Visual Studio could be preferred over older versions, but this may add unnecessary complexity to the search functions.


I imagine this is unrelated but, some entries in DIRECTORIES_WINDOWS seem inconsistent with this comment: https://github.com/KyleMayes/clang-sys/blob/master/build/common.rs#L231-L235

KyleMayes commented 1 year ago

The inconsistency of lib vs bin in the Windows backup directory globs is easy enough to fix, but the existing search logic should be preferring C:\Program Files\LLVM\ since it appears earlier in the backup directory glob list. I'll need to look into what's going wrong.

KyleMayes commented 1 year ago

I spent a while thinking this was some sort of bug, but the search directories are sorted in reverse order of preference and the Visual Studio patterns came after the more specific ones.

I've changed the lists of search directories to be in order of preference which makes more sense to me, added some tests to verify that the correct directories are preferred, and adjusted the Windows search directory order to prefer more specific installs in #153.

Once that is merged I'll do a release.

KyleMayes commented 1 year ago

Released in v1.5.0.