Building Firefox on Windows with clang-cl

Introduction

clang-cl is a new compiler from the LLVM project that attempts to be a drop-in replacement for MSVC's cl.exe. It also brings the full power of the LLVM toolchain to Windows.

lld-link is a linker from LLVM that can be used a drop-in replacement for MSVC's link.exe. It runs much faster than the Microsoft linker.

Firefox's build system now supports both clang-cl and lld-link.

Prerequisites

First, make sure you have an updated Mozilla source tree, as a number of build system fixes have landed very recently (March 2018).

You will need to obtain a recent build of clang-cl, using one of these options:

  • (Recommended) mach bootstrap will download the clang package currently used by automation to your ~/.mozbuild/clang directory. Mozilla's build system is able to detect clang-cl binaries in this location. There is no need to change your PATH.
  • Download a 64-bit release build or trunk snapshot from LLVM. You should allow the installer to put LLVM on your PATH.
  • Build your own LLVM from source. You must add the build directory to your PATH or provide a full path in your mozconfig.

Also, for the SDK requirement "Windows 10 SDK (N) for Desktop C++ x86 and x64", N must be 10.0.15063.0 or 10.0.17134.0. 10.0.16299.0 is not supported with clang-cl.

SDK paths are automatically discovered during the build process, but if you need to override them explicitly, the following environment variables are supported:

  • WINDOWSSDKDIR, pointing to the Windows Platform SDK (e.g. %WINDOWSSDKDIR%\Include\10.0.15063.0\um\Windows.h).
  • VC_PATH, pointing to the standard C++ libraries (e.g. %VC_PATH%\include\string).
  • DIA_SDK_PATH, pointing to the Debug Interface Access SDK (e.g. %DIA_SDK_PATH%\include\dia2.h).

Configuring your build

To build with clang-cl as your compiler, add the following to your mozconfig:

export CC="clang-cl.exe"
export CXX="clang-cl.exe"

To build with lld-link as your linker, add the following to your mozconfig:

export LINKER="lld-link.exe"

And then, proceed to build as normal.

Pushing to try

If you would like to use the clang toolchain on your try push, add one or both of the following lines to build/mozconfig.common.override:

. "$topsrcdir/build/mozconfig.clang-cl"
. "$topsrcdir/build/mozconfig.lld-link"

These files set the necessary exports and additionally have logic to find the clang binaries on the automation filesystems.

You can select a different LLVM SVN revision by editing build/build-clang/clang-win64.json (this file handles 32-bit builds too). When you push the change to try, it will first build that revision of clang (~1hr) and use the resulting compiler to build your code.

Document Tags and Contributors

Contributors to this page: hellosct1, staktrace, thenfour, jdashg, dmajor., gcp, Ehsan, kscarfone
Last updated by: hellosct1,