OLD | NEW |
1 [Clang](http://clang.llvm.org/) is a compiler with many desirable features (outl
ined on their website). | 1 # Clang |
2 | 2 |
3 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 messa
ges on Android and Windows. | 3 [Clang](http://clang.llvm.org/) is a compiler with many desirable features |
| 4 (outlined on their website). |
4 | 5 |
5 See [the open bugs](http://code.google.com/p/chromium/issues/list?q=label:clang)
. | 6 Chrome can be built with Clang. It is now the default compiler on Mac and Linux |
| 7 for building Chrome, and it is currently useful for its warning and error |
| 8 messages on Android and Windows. |
| 9 |
| 10 See |
| 11 [the open bugs](http://code.google.com/p/chromium/issues/list?q=label:clang). |
| 12 |
| 13 [TOC] |
6 | 14 |
7 ## Build instructions | 15 ## Build instructions |
8 | 16 |
9 Get clang (happens automatically during `gclient runhooks` on Mac and Linux): | 17 Get clang (happens automatically during `gclient runhooks` on Mac and Linux): |
10 ``` | |
11 tools/clang/scripts/update.sh | |
12 ``` | |
13 | 18 |
14 (Only needs to be run once per checkout, and clang will be automatically updated
by `gclient runhooks`.) | 19 tools/clang/scripts/update.sh |
| 20 |
| 21 (Only needs to be run once per checkout, and clang will be automatically updated |
| 22 by `gclient runhooks`.) |
15 | 23 |
16 ### Reverting to gcc on linux | 24 ### Reverting to gcc on linux |
17 | 25 |
18 We don't have bots that test this, but building with gcc4.8+ should still work o
n Linux. If your system gcc is new enough, use this to build with gcc if you don
't want to build with clang: | 26 We don't have bots that test this, but building with gcc4.8+ should still work |
| 27 on Linux. If your system gcc is new enough, use this to build with gcc if you |
| 28 don't want to build with clang: |
19 | 29 |
20 ``` | 30 GYP_DEFINES=clang=0 build/gyp_chromium |
21 GYP_DEFINES=clang=0 build/gyp_chromium | |
22 ``` | |
23 | 31 |
24 ### Ninja | 32 ### Ninja |
25 | 33 |
26 Regenerate the build files (`clang=1` is on by default on Mac and Linux): | 34 Regenerate the build files (`clang=1` is on by default on Mac and Linux): |
27 | 35 |
28 If you use gyp: | 36 If you use gyp: `GYP_DEFINES=clang=1 build/gyp_chromium` |
29 ``` | |
30 GYP_DEFINES=clang=1 build/gyp_chromium | |
31 ``` | |
32 | 37 |
33 If you use gn, run `gn args` and add `is_clang = true` to your args.gn file. | 38 If you use gn, run `gn args` and add `is_clang = true` to your args.gn file. |
34 | 39 |
35 Build: | 40 Build: `ninja -C out/Debug chrome` |
36 ``` | |
37 ninja -C out/Debug chrome | |
38 ``` | |
39 | 41 |
40 ## Mailing List | 42 ## Mailing List |
| 43 |
41 http://groups.google.com/a/chromium.org/group/clang/topics | 44 http://groups.google.com/a/chromium.org/group/clang/topics |
42 | 45 |
43 ## Using plugins | 46 ## Using plugins |
44 | 47 |
45 The [chromium style plugin](http://dev.chromium.org/developers/coding-style/chro
mium-style-checker-errors) is used by default when clang is used. | 48 The |
| 49 [chromium style plugin](http://dev.chromium.org/developers/coding-style/chromium
-style-checker-errors) |
| 50 is used by default when clang is used. |
46 | 51 |
47 If you're working on the plugin, you can build it locally like so: | 52 If you're working on the plugin, you can build it locally like so: |
48 | 53 |
49 1. Run `./tools/clang/scripts/update.sh --force-local-build --without-android`
to build the plugin. | 54 1. Run `./tools/clang/scripts/update.sh --force-local-build --without-android` |
50 1. Build with clang like described above. | 55 to build the plugin. |
| 56 1. Build with clang like described above. |
51 | 57 |
52 To run [other plugins](WritingClangPlugins.md), add these to your `GYP_DEFINES`: | 58 TODO: writing_clang_plugins does not exist. |
| 59 To run [other plugins](writing_clang_plugins.md), add these to your |
| 60 `GYP_DEFINES`: |
53 | 61 |
54 * `clang_load`: Absolute path to a dynamic library containing your plugin | 62 * `clang_load`: Absolute path to a dynamic library containing your plugin |
55 * `clang_add_plugin`: tells clang to run a specific PluginASTAction | 63 * `clang_add_plugin`: tells clang to run a specific PluginASTAction |
56 | 64 |
57 So for example, you could use the plugin in this directory with: | 65 So for example, you could use the plugin in this directory with: |
58 | 66 |
59 * `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so clang_add_
plugin=find-bad-constructs' gclient runhooks` | 67 * `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so |
| 68 clang_add_plugin=find-bad-constructs' gclient runhooks` |
60 | 69 |
61 ## Using the clang static analyzer | 70 ## Using the clang static analyzer |
62 | 71 |
63 See ClangStaticAnalyzer. | 72 See [clang_static_analyser.md](clang_static_analyser.md). |
64 | 73 |
65 ## Windows | 74 ## Windows |
66 | 75 |
67 **Experimental!** | 76 **Experimental!** |
68 | 77 |
69 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. | 78 clang can be used as compiler on Windows. Clang uses Visual Studio's linker and |
| 79 SDK, so you still need to have Visual Studio installed. |
70 | 80 |
71 Things should compile, and all tests should pass. You can check these bots for h
ow things are currently looking: http://build.chromium.org/p/chromium.fyi/consol
e?category=win%20clang | 81 Things should compile, and all tests should pass. You can check these bots for |
| 82 how things are currently looking: |
| 83 http://build.chromium.org/p/chromium.fyi/console?category=win%20clang |
72 | 84 |
73 ``` | 85 ``` shell |
74 python tools\clang\scripts\update.py | 86 python tools\clang\scripts\update.py |
75 set GYP_DEFINES=clang=1 | 87 set GYP_DEFINES=clang=1 |
76 python build\gyp_chromium | 88 python build\gyp_chromium |
| 89 |
77 # or, if you use gn, run `gn args` and add `is_clang = true` to your args.gn | 90 # or, if you use gn, run `gn args` and add `is_clang = true` to your args.gn |
78 ninja -C out\Debug chrome | 91 ninja -C out\Debug chrome |
79 ``` | 92 ``` |
80 | 93 |
81 Current brokenness: | 94 Current brokenness: |
82 | 95 |
83 * Goma doesn't work. | 96 * Goma doesn't work. |
84 * Debug info is very limited. | 97 * Debug info is very limited. |
85 * To get colored diagnostics, you need to be running [ansicon](https://github.
com/adoxa/ansicon/releases). | 98 * To get colored diagnostics, you need to be running |
| 99 [ansicon](https://github.com/adoxa/ansicon/releases). |
86 | 100 |
87 ## Using a custom clang binary | 101 ## Using a custom clang binary |
88 | 102 |
89 If you want to try building Chromium with your own clang binary that you've alre
ady built, set `make_clang_dir` to the directory containing `bin/clang` (i.e. th
e directory you ran cmake in, or your `Release+Asserts` folder if you use the co
nfigure/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 bina
ry. | 103 If you want to try building Chromium with your own clang binary that you've |
| 104 already 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 |
| 106 use the configure/make build). You also need to disable chromium's clang plugin |
| 107 by setting `clang_use_chrome_plugins=0`, as it likely won't load in your custom |
| 108 clang binary. |
90 | 109 |
91 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): | 110 Here'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): |
92 | 112 |
93 ``` | 113 ```shell |
94 GYP_DEFINES="clang=1 fastbuild=1 component=shared_library clang_use_chrome_plugi
ns=0 make_clang_dir=$HOME/src/llvm-build" build/gyp_chromium | 114 GYP_DEFINES="clang=1 fastbuild=1 component=shared_library \ |
| 115 clang_use_chrome_plugins=0 make_clang_dir=$HOME/src/llvm-build" \ |
| 116 build/gyp_chromium |
95 ``` | 117 ``` |
96 | 118 |
97 You can then run `head out/Release/build.ninja` and check that the first to line
s set `cc` and `cxx` to your clang binary. If things look good, run `ninja -C ou
t/Release` to build. | 119 You can then run `head out/Release/build.ninja` and check that the first to |
| 120 lines set `cc` and `cxx` to your clang binary. If things look good, run `ninja |
| 121 -C out/Release` to build. |
98 | 122 |
99 If your clang revision is very different from the one currently used in chromium
– check tools/clang/scripts/update.sh to find chromium's clang revision – you m
ight have to tweak warning flags. Or you could set `werror=` in the line above t
o disable warnings as errors (but this only works on Linux). | 123 If 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). |
OLD | NEW |