KyleMayes / clang-sys

Rust bindings for libclang.
Apache License 2.0
135 stars 69 forks source link

libclang detection fails on GitHub Action #121

Closed saschanaz closed 2 years ago

saschanaz commented 3 years ago

Background: https://github.com/rust-lang/rust-bindgen/issues/1797

I had to add this step:

      - name: Set LIBCLANG_PATH
        run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV

... per the following line:

https://github.com/KyleMayes/clang-sys/blob/ddd3af568ed76a2af94bcc3a9fd06af8e00fec99/build/dynamic.rs#L149

It seems this is only problematic in GitHub Action, not sure why. It's not a problem in my Windows machine without that environment variable.

My current script: https://github.com/saschanaz/jxl-winthumb/blob/2fc12d454163c7096158f93b712ef9f51b6f1f4b/.github/workflows/ci.yml

BlackHoleFox commented 3 years ago

This is probably because visual studio installs clang under C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\Llvm\\bin. The path isn't on clang-sys's search list.

Is this where your clang is locally or are you using the distribution from LLVM which is stored at C:\\LLVM\\?

KyleMayes commented 3 years ago

I added the Visual Studio LLVM component directory to the search paths as part of the now released v1.1.0.

I downloaded the Visual Studio LLVM component on my Windows machine and clang-sys found that libclang so hopefully this should remove the need to manually set LIBCLANG_PATH for users relying on the VS LLVM component.

saschanaz commented 3 years ago

Well, my script installs LLVM by KyleMayes/install-llvm-action (your GH Action script 😉) so I don't think it's about Visual Studio.

KyleMayes commented 3 years ago

Yes, I see that now.

I tunnel visioned on the mention of VS in a previous comment. I think the solution is just to set LIBCLANG_PATH like I do in the CI for this crate. It probably shouldn't be necessary, but 🤷‍♂️ .

saschanaz commented 3 years ago

Could it try guessing by the global clang path, which is what my step does? 👀

KyleMayes commented 3 years ago

clang-sys should be finding it already because install-llvm-action adds the installed directory to LD_LIBRARY_PATH and clang-sys searches LD_LIBRARY_PATH.

Why this isn't working I don't know.

I'll reopen the issue since it is a bug that should be fixed but I can't guarantee I'll get around to investigating it in a timely fashion.

trevyn commented 3 years ago

This also appears to be a problem on Azure Pipelines: https://github.com/mimblewimble/grin/pull/3596#issuecomment-801240927

KyleMayes commented 3 years ago

I've partially fixed this problem (for dynamic linking but not runtime linking) in 1.2.0:

I removed setting the environment variables in the CI YAML for this crate as a demonstration of clang-sys being able to find the Clang binaries when linking dynamically after these changes. However, as reported in https://github.com/rust-lang/rust-bindgen/issues/1797, clang-sys still attempts to link to an invalid MinGW libclang.so instance when linking at runtime.

Not sure what's going on there, I'll try to take another crack at it this weekend.

perqin commented 3 years ago

I added the Visual Studio LLVM component directory to the search paths as part of the now released v1.1.0.

I downloaded the Visual Studio LLVM component on my Windows machine and clang-sys found that libclang so hopefully this should remove the need to manually set LIBCLANG_PATH for users relying on the VS LLVM component.

On my Windows machine, the LLVM is by default installed into C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm. Should we add this path too? I've googled a bit, but didn't find any documentation provided by Microsoft telling the standard location in where the bundled LLVM is installed.

KyleMayes commented 2 years ago

It no longer seems necessary to set LIBCLANG_PATH in GitHub actions that use Windows.

I was able to remove the last clang-sys environment variable from this repository's CI action and it worked just fine (https://github.com/KyleMayes/clang-sys/commit/609d1c196f3ee621deb69590d9434ce69aeec7cd).

I'm going to close but if someone has a similar issue please open a new issue.