gradle-native
gradle-native copied to clipboard
Add support for clang-cl compiler on Windows
Expected Behavior
No errors when building with clang-cl whilst also using the MSVC libraries.
Current Behavior
When attempting to build using clang-cl we get the error below:
* What went wrong:
Execution failed for task ':Core:compileCoreWindowsClangReleaseDemoSharedLibraryCoreCpp'.
> Could not determine Clang metadata: clang-cl.exe produced unexpected output.
Context
Currently we cannot add the clang-cl compiler in a toolchain when trying to build with clang for MSVC compatibility on Windows whilst also using the MSVC linker and librarian.
toolChains {
clang(Clang) {
path "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/
eachPlatform {
cppCompiler.executable = "Llvm/bin/clang-cl.exe"
staticLibArchiver.executable = "MSVC/14.16.27023/bin/HostX64/x86/lib.exe"
linker.executable = "MSVC/14.16.27023/bin/HostX64/x86/link.exe"
}
}
}
NOTE: We're using the Visual Studio installed version of Clang which is the same as the separately installed version of Clang except for the location.
Steps to Reproduce (for bugs)
- Install Clang via Visual Studio 2019 installer (or install it separately here).
- Add new toolchain to gradle, as shown above. Specifically using Clang-cl for the compiler and the MSVC linker and librarian.
- Build using the new toolchain
Your Environment
Windows 10 (64 bit) Clang 9 Gradle 5.4.1 JDK 1.8.0_191 Using the software model C++ Plugin
Bump - clang
and clang-cl
both work fantastically on Windows. Unsure why you can only use MSVC or MinGW GCC 😦
LLVM toolchain is powerful and it's a shame not to have access to it at all with Gradle on Windows OS
It seems this is because clang-cl doesn't produce the expected output for clang-cl -dM -E -v
https://github.com/gradle/gradle/blob/master/subprojects/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/gcc/metadata/GccMetadataProvider.java#L191-L209
Futhurmore it seems like clang-cl doesn't support -dM...
~~It seems odd, but clang doesn't respond to -dM either.~~ Edit: It does, the use of it is to determine defines
Though since clang-cl is meant to replace cl and not clang, it might be a better idea to define it as a MSVC toolchain rather than a Clang toolchain