blob: 4ae603a476b90f88d0a8806f095eb098bb61e2b6 [file] [log] [blame] [view]
andybons6eaa0c0d2015-08-26 20:12:521# Clang
andybons3322f762015-08-24 21:37:092
andybons6eaa0c0d2015-08-26 20:12:523[Clang](http://clang.llvm.org/) is a compiler with many desirable features
4(outlined on their website).
andybons3322f762015-08-24 21:37:095
Andrew Grievefe71bbc2017-09-22 18:44:406Chrome can be built with Clang. It is now the default compiler on Android, Mac
7and Linux for building Chrome, and it is currently useful for its warning and
8error messages on Windows.
andybons6eaa0c0d2015-08-26 20:12:529
10See
11[the open bugs](http://code.google.com/p/chromium/issues/list?q=label:clang).
12
13[TOC]
andybons3322f762015-08-24 21:37:0914
15## Build instructions
16
17Get clang (happens automatically during `gclient runhooks` on Mac and Linux):
andybons3322f762015-08-24 21:37:0918
Nico Weber21e0f4f2015-12-04 14:24:4719 tools/clang/scripts/update.py
andybons6eaa0c0d2015-08-26 20:12:5220
rnkc052ba32016-04-13 21:13:0021Only needs to be run once per checkout, and clang will be automatically updated
22by `gclient runhooks`.
andybons3322f762015-08-24 21:37:0923
rnkc052ba32016-04-13 21:13:0024Regenerate the ninja build files with Clang enabled. Again, on Linux and Mac,
25Clang is the default compiler.
andybons3322f762015-08-24 21:37:0926
brettwdbb91a1b2016-08-03 20:14:5427Run `gn args` and add `is_clang = true` to your args.gn file.
andybons3322f762015-08-24 21:37:0928
thakis2a46c2d12016-11-29 22:41:3829Build: `ninja -C out/gn chrome`
andybons3322f762015-08-24 21:37:0930
rnkc052ba32016-04-13 21:13:0031## Reverting to gcc on linux
32
33We don't have bots that test this, but building with gcc4.8+ should still work
brettwc25693b32016-05-26 01:11:5234on Linux. If your system gcc is new enough, run `gn args` and add `is_clang =
35false`.
rnkc052ba32016-04-13 21:13:0036
andybons3322f762015-08-24 21:37:0937## Mailing List
andybons6eaa0c0d2015-08-26 20:12:5238
xiaoyin.l1003c0b2016-12-06 02:51:1739https://groups.google.com/a/chromium.org/group/clang/topics
andybons3322f762015-08-24 21:37:0940
41## Using plugins
42
andybons6eaa0c0d2015-08-26 20:12:5243The
xiaoyin.l1003c0b2016-12-06 02:51:1744[chromium style plugin](https://dev.chromium.org/developers/coding-style/chromium-style-checker-errors)
andybons6eaa0c0d2015-08-26 20:12:5245is used by default when clang is used.
andybons3322f762015-08-24 21:37:0946
47If you're working on the plugin, you can build it locally like so:
48
jyasskin37110bc2015-12-04 03:40:24491. Run `./tools/clang/scripts/update.py --force-local-build --without-android`
andybons6eaa0c0d2015-08-26 20:12:5250 to build the plugin.
jyasskin37110bc2015-12-04 03:40:24511. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build incrementally.
521. Build with clang like described above, but, if you use goma, disable it.
andybons3322f762015-08-24 21:37:0953
jyasskin37110bc2015-12-04 03:40:2454To test the FindBadConstructs plugin, run:
55
56 (cd tools/clang/plugins/tests && \
vmpstr0b23ec1a2016-02-11 21:01:5057 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \
jyasskin37110bc2015-12-04 03:40:2458 ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so)
59
andybons3322f762015-08-24 21:37:0960## Using the clang static analyzer
61
kirillbobyreveed2584d2015-11-02 14:38:2962See [clang_static_analyzer.md](clang_static_analyzer.md).
andybons3322f762015-08-24 21:37:0963
64## Windows
65
andybons6eaa0c0d2015-08-26 20:12:5266clang can be used as compiler on Windows. Clang uses Visual Studio's linker and
67SDK, so you still need to have Visual Studio installed.
andybons3322f762015-08-24 21:37:0968
andybons6eaa0c0d2015-08-26 20:12:5269Things should compile, and all tests should pass. You can check these bots for
70how things are currently looking:
xiaoyin.l1003c0b2016-12-06 02:51:1771https://build.chromium.org/p/chromium.fyi/console?category=win%20clang
andybons3322f762015-08-24 21:37:0972
thakis2a46c2d12016-11-29 22:41:3873```shell
andybons3322f762015-08-24 21:37:0974python tools\clang\scripts\update.py
brettwdbb91a1b2016-08-03 20:14:5475# run `gn args` and add `is_clang = true` to your args.gn, then...
thakis2a46c2d12016-11-29 22:41:3876ninja -C out\gn chrome
andybons3322f762015-08-24 21:37:0977```
78
rnkc052ba32016-04-13 21:13:0079The `update.py` script only needs to be run once per checkout. Clang will be
thakis3e861de2016-06-14 14:24:0180kept up to date by `gclient runhooks`.
rnkc052ba32016-04-13 21:13:0081
andybons3322f762015-08-24 21:37:0982Current brokenness:
83
andybons6eaa0c0d2015-08-26 20:12:5284* To get colored diagnostics, you need to be running
85 [ansicon](https://github.com/adoxa/ansicon/releases).
thakis3a2294e2016-09-12 22:38:4986* Debug info does now work, but support for it is new. If you see something
87 not working right, please file a bug and mark it as blocking the
88 [clang/win debug info tracking bug](https://crbug.com/636111).
andybons3322f762015-08-24 21:37:0989
90## Using a custom clang binary
91
thakis2a46c2d12016-11-29 22:41:3892Set `clang_base_path` in your args.gn to the llvm build directory containing
93`bin/clang` (i.e. the directory you ran cmake). This [must][1] be an absolute
94path. You also need to disable chromium's clang plugin.
andybons3322f762015-08-24 21:37:0995
andybons6eaa0c0d2015-08-26 20:12:5296Here's an example that also disables debug info and enables the component build
97(both not strictly necessary, but they will speed up your build):
andybons3322f762015-08-24 21:37:0998
thakis2a46c2d12016-11-29 22:41:3899```
100clang_base_path = getenv("HOME") + "/src/llvm-build"
101clang_use_chrome_plugins = false
102is_debug = false
103symbol_level = 1
104is_component_build = true
105is_clang = true # Implicitly set on Mac, Linux, iOS; needed on Win and Android.
andybons3322f762015-08-24 21:37:09106```
107
thakis2a46c2d12016-11-29 22:41:38108You can then run `head out/gn/toolchain.ninja` and check that the first to
andybons6eaa0c0d2015-08-26 20:12:52109lines set `cc` and `cxx` to your clang binary. If things look good, run `ninja
thakis2a46c2d12016-11-29 22:41:38110-C out/gn` to build.
andybons3322f762015-08-24 21:37:09111
andybons6eaa0c0d2015-08-26 20:12:52112If your clang revision is very different from the one currently used in chromium
113
Nico Weber21e0f4f2015-12-04 14:24:47114* Check `tools/clang/scripts/update.py` to find chromium's clang revision
thakis2a46c2d12016-11-29 22:41:38115* You might have to tweak warning flags.
rnkc052ba32016-04-13 21:13:00116
117## Using LLD
118
119**Experimental!**
120
121LLD is a relatively new linker from LLVM. The current focus is on Windows and
122Linux support, where it can link Chrome approximately twice as fast as gold and
Andrew Grievefe71bbc2017-09-22 18:44:40123MSVC's link.exe as of this writing.
rnkc052ba32016-04-13 21:13:00124
thakis2a46c2d12016-11-29 22:41:38125Set `use_lld = true` in args.gn.