Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libclang not found when building using github actions for windows target #1797

Closed
virtualritz opened this issue Jun 6, 2020 · 13 comments
Closed

Comments

@virtualritz
Copy link

I'm trying to use github actions to CI build my crate for several platforms. The windows target build fails on bindgen with:

thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at C:\\msys64\\mingw64\\bin\\libclang.dll could not be opened: The specified module could not be found. (os error 126)"', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.54.0\src/lib.rs:1959:13

This works all fine for the macos and ubuntu targets btw.

@kulp
Copy link
Member

kulp commented Jun 20, 2020

Perhaps related: #918.

@emilio
Copy link
Contributor

emilio commented Jun 20, 2020

Yeah, you need to somehow install libclang on that windows machine.

@kulp
Copy link
Member

kulp commented Jul 17, 2020

@virtualritz, I do not think bindgen can do anything useful here except perhaps implement #918, so if you like that issue, you can lend your support to it.

@kulp kulp closed this as completed Jul 17, 2020
@thomcc
Copy link
Member

thomcc commented Oct 4, 2020

I think these machines supposedly do have clang on them, so I think there is probably more that can be done, as https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md mentions:

Package Version
... ...
Microsoft.VisualStudio.Component.VC.Llvm.Clang 16.7.30310.162
Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset 16.3.29207.166
... ...
Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Llvm.Clang 16.7.30310.162
... ...

However, I don't exactly know where the clangs in question are located, unfortunately.

Digging around in a local install of MSVC with these components does produce a clang (it was a while ago when I did this, so I don't remember where), but the one on the server seems not to be located in the same place, possibly because it's enterprise edition, or possibly becuase it's windows server, IDK.

@someguynamedjosh
Copy link

I'm trying to build a project on a Github runner and am running into the same problem. Doing some debugging with ls shows that there is a file C:\msys64\mingw64\bin\libclang.dll installed on the runner by default. However, I still get the same error as the original poster, which specifies this exact path in the error message.

@someguynamedjosh
Copy link

I don't know if this is significant, but the Github runners by default load the user's files onto the D: drive while all the preinstalled software is located on the C: drive.

@thomcc
Copy link
Member

thomcc commented Feb 1, 2021

I was able to locate it ato some point inside C:\msys64\mingw64\bin (and some related stuff in C:\msys64\mingw64\lib), but never was able to make bindgen (or the clang-sys crate) load it, even trying various options.

Unsure why though, meant to follow up on it.

@someguynamedjosh
Copy link

Good news! 🎉 I have found at least a partial solution.

It looks like on the Github runners, the libclang DLL relies on other DLLs in the same folder but that folder is never searched. The underlying error was one returned by Windows itself when trying to load the DLL which, annoyingly enough, can be caused both by a missing file and by missing dependencies. Adding the folder to $Env:Path seemed to resolve the problem. However, it only seems to work if added to the start of the path, which also means that MinGW will be used in place of MSVC, which is not acceptable in my case. I'll do some more investigation to see if this can be easily worked around.

For future Googlers, the program that ended up tracking down the problem was procmon. Basically it shows you all the interactions between applications and the kernel, including those extra DLLs that the program tried unsuccessfully to load. I didn't thoroughly look through the logs as there was a lot of information, but some examples of culprits were things like libLLVM.dll and winpthread.dll.

@saschanaz
Copy link

saschanaz commented Feb 5, 2021

I had to add this step:

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

clang-sys uses this, but no idea why this is only problematic in GitHub Action on Windows.

maael added a commit to maael/dessa that referenced this issue Feb 6, 2021
@KyleMayes
Copy link
Contributor

KyleMayes commented Feb 10, 2021

I have added the Visual Studio LLVM component directory to the search paths used by clang-sys on Windows and tested it on my Windows machine. These changes are part of clang-sys v1.1.0 which also includes Clang 11 support.

This should hopefully remove the need for users relying on the VS LLVM component to manually set the LIBCLANG_PATH environment variable.

EDIT: Didn't understand the problem, I think the solution is just to set LIBCLANG_PATH...
That's what I do in the tests for clang-sys and the clang crates.
This probably shouldn't be necessary but I'm not sure why it isn't working and I'm way too lazy to investigate further.

lovasoa added a commit to rust-or/highs-sys that referenced this issue Feb 28, 2021
@lovasoa
Copy link

lovasoa commented Feb 28, 2021

Edit: you are right, one needs to install clang first.

For me the following worked :

jobs:
  build:
    runs-on: ${{ matrix.config.os }}
    strategy:
      matrix:
        config:
          - os: ubuntu-latest
          - os: macos-latest
          - os: windows-latest
    steps:
    - name: Install LLVM and Clang # required for bindgen to work, see https://github.com/rust-lang/rust-bindgen/issues/1797
      uses: KyleMayes/install-llvm-action@32c4866ebb71e0949e8833eb49beeebed48532bd
      if: matrix.config.os == 'windows-latest'
      with:
        version: "11.0"
        directory: ${{ runner.temp }}/llvm
    - name: Set LIBCLANG_PATH
      run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
      if: matrix.config.os == 'windows-latest'
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    - name: install dependencies
      run: ./install-dependencies.sh
    - name: Build
      run: cargo build
    - name: Run tests
      run: cargo test
> I had to add this step: [...] (@saschanaz)

When I tried that, it failed with :

Run echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
Get-Command: D:\a\_temp\b32fd303-37e7-49c6-b0fb-06fd5884522b.ps1:2
Line |
   2 |  echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $e …
     |                         ~~~~~~~~~
     | The term 'clang' is not recognized as a name of a cmdlet, function, script file, or executable
     | program. Check the spelling of the name, or if a path was included, verify that the path is correct
     | and try again.

Error: Process completed with exit code 1.

@saschanaz
Copy link

Ah yeah, that means you didn't install LLVM yourself: https://github.com/marketplace/actions/install-llvm-and-clang

@MolotovCherry
Copy link

Had this frustrating issue. Lovasoa's fix did make it work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants