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

clang_sys::load tries to load ARM64 library on x64 Windows #170

Closed
IvanPashchenko opened this issue Mar 22, 2024 · 1 comment
Closed

clang_sys::load tries to load ARM64 library on x64 Windows #170

IvanPashchenko opened this issue Mar 22, 2024 · 1 comment

Comments

@IvanPashchenko
Copy link

IvanPashchenko commented Mar 22, 2024

I have LLVM installed via MS Build Tools Installer (components C++ Clang Compiler for Windows (16.0.5) and MSBuild support for LLVM (clang-cl) toolset) and have both ARM64 and x64 versions present:

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm

01/17/2024  06:45 PM    <DIR>          .
01/17/2024  06:44 PM    <DIR>          ..
01/17/2024  06:45 PM    <DIR>          ARM64
01/17/2024  06:45 PM    <DIR>          bin
01/17/2024  06:45 PM    <DIR>          lib
01/17/2024  06:45 PM    <DIR>          x64
               0 File(s)              0 bytes
               6 Dir(s)  176,173,752,320 bytes free

Following paths to load the libclang.dll are available:

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\ARM64\bin\libclang.dll
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\bin\libclang.dll
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\x64\bin\libclang.dll

A pretty simple project with

clang-sys = { version = "1.7.0", features = ["runtime"] }

And

fn main() {
  clang_sys::load().unwrap();
}

Will fail with the following error:

called `Result::unwrap()` on an `Err` value: "the `libclang` shared library at C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\Llvm\\ARM64\\bin\\libclang.dll could not be opened: LoadLibraryExW failed"

It is indeed an ARM64 library and it's not possible to load it in x64 Windows:

Dump of file C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\Llvm\\ARM64\\bin\\libclang.dll

PE signature found

File Type: DLL

FILE HEADER VALUES
            AA64 machine (ARM64)
[...]

I'm not really familiary with the clang/LLVM ecosystem, but I'm happy to try and provide a fix.

  1. What would be the proper place for the fix? dynamic.rs fn validate_library?
  2. Is there a way to determine the target architecture (like target_os macro)?
@KyleMayes
Copy link
Owner

KyleMayes commented May 29, 2024

I've improved the library detection on Windows to take into account the machine type of the library, so ARM64 DLLs should get ignored when targeting x86-64 and vice-versa (released in v1.8.1).

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

2 participants