gradle-native icon indicating copy to clipboard operation
gradle-native copied to clipboard

Add support for clang-cl compiler on Windows

Open EmanueleOliveri opened this issue 5 years ago • 5 comments

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)

  1. Install Clang via Visual Studio 2019 installer (or install it separately here).
  2. Add new toolchain to gradle, as shown above. Specifically using Clang-cl for the compiler and the MSVC linker and librarian.
  3. 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

EmanueleOliveri avatar Feb 13 '20 01:02 EmanueleOliveri

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

GavinRay97 avatar Aug 30 '21 15:08 GavinRay97

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

pandaninjas avatar Sep 23 '23 00:09 pandaninjas

Futhurmore it seems like clang-cl doesn't support -dM...

pandaninjas avatar Sep 23 '23 00:09 pandaninjas

~~It seems odd, but clang doesn't respond to -dM either.~~ Edit: It does, the use of it is to determine defines

pandaninjas avatar Sep 23 '23 00:09 pandaninjas

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

pandaninjas avatar Sep 23 '23 00:09 pandaninjas