Over the past three weeks or so, Jeff Muizelaar and I started to investigate what it would take for us to be able to use clang-cl to build Firefox on Windows, and I'm really excited to report that as of earlier this week, all of the patches required have landed on both mozilla-central and LLVM and we can produce debug builds that run at least for basic browsing.
clang-cl is the LLVM project's drop-in replacement for Microsoft's Visual C++ compiler. It uses the same base technology as clang, but it supports the Microsoft ABI to a large extent, and it also provides a compiler driver that accepts many of the same options as Visual C++. There are of course things that are missing from clang-cl still (such as support for C++ and structured exceptions, and MSVC-style inline assembly), but fortunately clang-cl supports a fallback mode which enables us to build the tiny portions of our tree which still cannot be compiled with clang-cl itself by calling back to the Microsoft compiler. Because both compilers generate code adhering to the same ABI, we can link all of this code and produce a working build.
To try this out yourself, you'll need to download and build clang on Windows from the recent trunk (note that we have had to fix a bunch of issues in clang/LLVM, so you really want the tip of tree trunk!). Once you have a working clang-cl build, you need to build a recent mozilla-central tree with a mozconfig containing the following:
export CC=clang-cl export CXX=clang-cl export CFLAGS="-fallback" export CXXFLAGS="-fallback" export MOZ_CFLAGS_NSS="-fallback"
With this, you should be able to build Firefox with clang-cl! (Note that earlier today I found a regression in clang-cl which causes a crash when configuring ICU, but you should be able to ignore that crash and proceed.)
I think clang-cl can be really interesting for Mozilla for a number of reasons. There is of course the promise of a decent open source compiler on Windows, which really excites me, but we're still a bit far from being able to use this compiler for our production builds. But in the very near future, we should be able to use clang-cl in order to produce AddressSanitizer builds on Windows. That should be super helpful to debug memory correctness issues on Windows, where we don't really have a decent story yet. We should also be able to experiment with other sanitizer tools in clang on Windows. We can even start to think about other clang-based tools on Windows (DXR comes to mind.) Soon we will also be able to start comparing the performance of the generated code between clang-cl and Visual C++ and hopefully be able to provide good test cases for the LLVM project to improve their codegen performance to make it on par with Visual C++. And who knows what other ideas people will come up with!
Last but not least, I've been impressed with the quality of clang-cl. It was relatively easy for me and Jeff to spend some of our free time over the course of 2-3 weeks to get to working build from scratch with some fixes both on our side and on LLVM. The LLVM engineers at Google who are working on clang-cl deserve most of the credit for that. Specifically I'd like to thank Hans Wennborg and Reid Kleckner for their immense help in fixing the LLVM issues we encountered.
If you'd like to follow along, please watch the tracker bug for clang-cl support. If you'd like to help, or have awesome ideas on the possibilities this opens up, please get in touch!