blob: 5b5ec9060d8af9548c6cc0d4ac922628979610f2 [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
andybons6eaa0c0d2015-08-26 20:12:526Chrome can be built with Clang. It is now the default compiler on Mac and Linux
7for building Chrome, and it is currently useful for its warning and error
8messages on Android and Windows.
9
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
andybons6eaa0c0d2015-08-26 20:12:5219 tools/clang/scripts/update.sh
20
21(Only needs to be run once per checkout, and clang will be automatically updated
22by `gclient runhooks`.)
andybons3322f762015-08-24 21:37:0923
24### Reverting to gcc on linux
25
andybons6eaa0c0d2015-08-26 20:12:5226We don't have bots that test this, but building with gcc4.8+ should still work
27on Linux. If your system gcc is new enough, use this to build with gcc if you
28don't want to build with clang:
andybons3322f762015-08-24 21:37:0929
andybons6eaa0c0d2015-08-26 20:12:5230 GYP_DEFINES=clang=0 build/gyp_chromium
andybons3322f762015-08-24 21:37:0931
32### Ninja
33
34Regenerate the build files (`clang=1` is on by default on Mac and Linux):
35
andybons6eaa0c0d2015-08-26 20:12:5236If you use gyp: `GYP_DEFINES=clang=1 build/gyp_chromium`
andybons3322f762015-08-24 21:37:0937
38If you use gn, run `gn args` and add `is_clang = true` to your args.gn file.
39
andybons6eaa0c0d2015-08-26 20:12:5240Build: `ninja -C out/Debug chrome`
andybons3322f762015-08-24 21:37:0941
42## Mailing List
andybons6eaa0c0d2015-08-26 20:12:5243
andybons3322f762015-08-24 21:37:0944http://groups.google.com/a/chromium.org/group/clang/topics
45
46## Using plugins
47
andybons6eaa0c0d2015-08-26 20:12:5248The
49[chromium style plugin](http://dev.chromium.org/developers/coding-style/chromium-style-checker-errors)
50is used by default when clang is used.
andybons3322f762015-08-24 21:37:0951
52If you're working on the plugin, you can build it locally like so:
53
andybons6eaa0c0d2015-08-26 20:12:52541. Run `./tools/clang/scripts/update.sh --force-local-build --without-android`
55 to build the plugin.
561. Build with clang like described above.
andybons3322f762015-08-24 21:37:0957
andybons6eaa0c0d2015-08-26 20:12:5258TODO: writing_clang_plugins does not exist.
59To run [other plugins](writing_clang_plugins.md), add these to your
60`GYP_DEFINES`:
andybons3322f762015-08-24 21:37:0961
andybons6eaa0c0d2015-08-26 20:12:5262* `clang_load`: Absolute path to a dynamic library containing your plugin
63* `clang_add_plugin`: tells clang to run a specific PluginASTAction
andybons3322f762015-08-24 21:37:0964
65So for example, you could use the plugin in this directory with:
66
andybons6eaa0c0d2015-08-26 20:12:5267* `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so
68 clang_add_plugin=find-bad-constructs' gclient runhooks`
andybons3322f762015-08-24 21:37:0969
70## Using the clang static analyzer
71
kirillbobyreveed2584d2015-11-02 14:38:2972See [clang_static_analyzer.md](clang_static_analyzer.md).
andybons3322f762015-08-24 21:37:0973
74## Windows
75
76**Experimental!**
77
andybons6eaa0c0d2015-08-26 20:12:5278clang can be used as compiler on Windows. Clang uses Visual Studio's linker and
79SDK, so you still need to have Visual Studio installed.
andybons3322f762015-08-24 21:37:0980
andybons6eaa0c0d2015-08-26 20:12:5281Things should compile, and all tests should pass. You can check these bots for
82how things are currently looking:
83http://build.chromium.org/p/chromium.fyi/console?category=win%20clang
andybons3322f762015-08-24 21:37:0984
andybons6eaa0c0d2015-08-26 20:12:5285``` shell
andybons3322f762015-08-24 21:37:0986python tools\clang\scripts\update.py
87set GYP_DEFINES=clang=1
88python build\gyp_chromium
andybons6eaa0c0d2015-08-26 20:12:5289
andybons3322f762015-08-24 21:37:0990# or, if you use gn, run `gn args` and add `is_clang = true` to your args.gn
91ninja -C out\Debug chrome
92```
93
94Current brokenness:
95
andybons6eaa0c0d2015-08-26 20:12:5296* Goma doesn't work.
97* Debug info is very limited.
98* To get colored diagnostics, you need to be running
99 [ansicon](https://github.com/adoxa/ansicon/releases).
andybons3322f762015-08-24 21:37:09100
101## Using a custom clang binary
102
andybons6eaa0c0d2015-08-26 20:12:52103If you want to try building Chromium with your own clang binary that you've
104already built, set `make_clang_dir` to the directory containing `bin/clang`
105(i.e. the directory you ran cmake in, or your `Release+Asserts` folder if you
106use the configure/make build). You also need to disable chromium's clang plugin
107by setting `clang_use_chrome_plugins=0`, as it likely won't load in your custom
108clang binary.
andybons3322f762015-08-24 21:37:09109
andybons6eaa0c0d2015-08-26 20:12:52110Here's an example that also disables debug info and enables the component build
111(both not strictly necessary, but they will speed up your build):
andybons3322f762015-08-24 21:37:09112
andybons6eaa0c0d2015-08-26 20:12:52113```shell
114GYP_DEFINES="clang=1 fastbuild=1 component=shared_library \
115clang_use_chrome_plugins=0 make_clang_dir=$HOME/src/llvm-build" \
116build/gyp_chromium
andybons3322f762015-08-24 21:37:09117```
118
andybons6eaa0c0d2015-08-26 20:12:52119You can then run `head out/Release/build.ninja` and check that the first to
120lines set `cc` and `cxx` to your clang binary. If things look good, run `ninja
121-C out/Release` to build.
andybons3322f762015-08-24 21:37:09122
andybons6eaa0c0d2015-08-26 20:12:52123If your clang revision is very different from the one currently used in chromium
124
125* Check `tools/clang/scripts/update.sh` to find chromium's clang revision
126* You might have to tweak warning flags. Or you could set `werror=` in the
127 line above to disable warnings as errors (but this only works on Linux).