Microsoft has released Visual Studio 16.1. It includes support for Clang. I have been waiting for this for a long time. I wonder whether it’s now possible to build Juce plugins using Clang on windows. If this works it means some 3rd party libraries will gain a lot of performance. I’m mainly thinking about Eigen and simdpp, but the Juce SIMD abstraction also works a lot better with Clang than with the Microsoft C++ compiler. I stayed away from using these because the MS compiler had troubles fully optimizing SIMD abstraction classes and Clang maybe now will solve this issue.
Ok so far it’s clear it’s an optional additional install accessible in the Visual Studio Installer app called “Clang compiler for windows”.
The performance issue with some SIMD libs and the JUCE SIMD abstractions is related to using a class to abstract SIMD types and VC++'s inability to optimize the class away properly. More info here: https://github.com/p12tic/libsimdpp/issues/116.
So if we could switch SIMD parts of the code to compile with CLANG we should get a nice speedup.
Hmmpf, I tried to get it to work, but unfortunately as of now it only works for project using CMake and not MSBuild and AFAIK Juce has no MSVC CMake exporter. MSBuild support is at least on the roadmap.
MSBuild support for the latest Clang as well as Clang v8 is now in the vs2019 16.2 preview 3. This probably means it’ll be in the official 16.2 release. Haven’t tried it yet, but the news got me excited for sure.
I downloaded the preview, installed the optional clang support and gave it a go with the JUCE hello world GUI pip. To switch to clang, all that is needed is switching the project’s Platform Toolset to "LLVM (clang-cl).
After some tweaking I got it to compile and run. Of course there are a few problems. For some reason
#pragma comment (lib, ...) doesn’t seem to work right, so I had to manually add the additional windows libraries to the linker options. Maybe this is a bug in the new platform toolset, but personally I think it’s a bad way to add libraries and should be avoided in general.
And I got one undefined command
__cpuid() which is a built-in microsoft compiler thing that doesn’t exist for clang.
For larger things, some parts of JUCE would need patching as right now JUCE assumes that WINDOWS_MSVC implies the microsoft compiler. For instants this doesn’t work with SSE intrinsics as they are slightly different. Obviously the code needed is already in JUCE, but some configuration work would be needed for the compiler to use the right stuff for this new MSVC + Clang config.
Obviously we’d also need an option to export from the Projucer with the Platform Toolset set to LLVM.
I hope the JUCE team will consider this new option to produce code on windows and will add official support.
#pragma comment (lib, ...) is supported, but that section of the JUCE headers doesn’t get parsed. Maybe something is awry with preprocessor macros before that point or clang uses a different include order. For some reason JUCE_WINDOWS gets defined too late.
I also read more about the new feature and apparently it’s possible to produce code for linux using VS with this new toolchain. I have never released JUCE software on linux but if I could use VS to build it that might help things a lot as I do not have access to an IDE I like (and/or understand) on linux.
Thanks for testing this, I am eager to switch to clang on Windows since the first time I learned how to use Godbolt.org
I read somewhere that it just uses the frontend of clang but the code generation is still the MS compiler. Has that changed?
Yes that has changed in this preview. Actually it already changed in 16.1.1 when it became possible to build in Visual Studio with llvm/clang/clang-cl using CMake. Before that I think VS 2019 already used parts of clang for code-completion and intellisense. Now it’s becoming a full blown toolset with MSBuild compatibility and MS spent resources to make their STL implementation work with it.
Visual Studio 2019 16.2 has been released with this new toolchain included. That means using Clang to build win software is now officially supported by Visual Studio and Microsoft. AFAIK it’s also possible to build libraries with Clang and link with MSVC compiled binaries.
Is there any interest by the JUCE devs to support this, or should the community come up with a pull request?
We certainly don’t mind including changes that makes this possible, but I’m reluctant to add official support until a few people have been using it for a while.
I personally don’t like when people sell a simple UI wrapper on top of free and open source tools, so I won’t try that extension.
However, I can recommend using
clang-analyze to find more issues than what compiler warnings can.
It looks like the UI wrapper post was created by a bot, so it’s been removed.