Clang is a compiler with many desirable features (outlined on their website).
Chrome can be built with Clang. It is now the default compiler on Mac and Linux for building Chrome, and it is currently useful for its warning and error messages on Android and Windows.
See the open bugs.
Get clang (happens automatically during gclient runhooks
on Mac and Linux):
tools/clang/scripts/update.py
Only needs to be run once per checkout, and clang will be automatically updated by gclient runhooks
.
Regenerate the ninja build files with Clang enabled. Again, on Linux and Mac, Clang is the default compiler.
If you use gyp: GYP_DEFINES=clang=1 build/gyp_chromium
If you use gn, run gn args
and add is_clang = true
to your args.gn file.
Build: ninja -C out/Debug chrome
We don't have bots that test this, but building with gcc4.8+ should still work on Linux. If your system gcc is new enough, run gn args
and add is_clang = false
.
http://groups.google.com/a/chromium.org/group/clang/topics
The chromium style plugin is used by default when clang is used.
If you're working on the plugin, you can build it locally like so:
./tools/clang/scripts/update.py --force-local-build --without-android
to build the plugin.ninja -C third_party/llvm-build/Release+Asserts/
to build incrementally.To test the FindBadConstructs plugin, run:
(cd tools/clang/plugins/tests && \ ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \ ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so)
To run other plugins, add these to your GYP_DEFINES
(this is not currently set up in GN):
clang_load
: Absolute path to a dynamic library containing your pluginclang_add_plugin
: tells clang to run a specific PluginASTActionSo for example, you could use the plugin in this directory with:
GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so clang_add_plugin=find-bad-constructs' gclient runhooks
clang can be used as compiler on Windows. Clang uses Visual Studio's linker and SDK, so you still need to have Visual Studio installed.
Things should compile, and all tests should pass. You can check these bots for how things are currently looking: http://build.chromium.org/p/chromium.fyi/console?category=win%20clang
python tools\clang\scripts\update.py set GYP_DEFINES=clang=1 python build\gyp_chromium # or, if you use gn, run `gn args` and add `is_clang = true` to your args.gn ninja -C out\Debug chrome
The update.py
script only needs to be run once per checkout. Clang will be kept up to date by gclient runhooks
.
Current brokenness:
If you want to try building Chromium with your own clang binary that you‘ve already built, set make_clang_dir
to the directory containing bin/clang
(i.e. the directory you ran cmake in, or your Release+Asserts
folder if you use the configure/make build). You also need to disable chromium’s clang plugin by setting clang_use_chrome_plugins=0
, as it likely won't load in your custom clang binary.
Here's an example that also disables debug info and enables the component build (both not strictly necessary, but they will speed up your build):
GYP_DEFINES="clang=1 fastbuild=1 component=shared_library \ clang_use_chrome_plugins=0 make_clang_dir=$HOME/src/llvm-build" \ build/gyp_chromium
You can then run head out/Release/build.ninja
and check that the first to lines set cc
and cxx
to your clang binary. If things look good, run ninja -C out/Release
to build.
If your clang revision is very different from the one currently used in chromium
tools/clang/scripts/update.py
to find chromium's clang revisionwerror=
in the line above to disable warnings as errors (but this only works on Linux).Experimental!
LLD is a relatively new linker from LLVM. The current focus is on Windows and Linux support, where it can link Chrome approximately twice as fast as gold and MSVC's link.exe as of this writing. LLD does not yet support generating PDB files, which makes it hard to debug Chrome while using LLD.
If you use gyp, you can enable it with GYP_DEFINES=lld=1
. If you use gn, set use_lld = true
in args.gn. Currently this configuration is only supported on Windows.