OLD | NEW |
1 # Clang | 1 # Clang |
2 | 2 |
3 [Clang](http://clang.llvm.org/) is a compiler with many desirable features | 3 [Clang](http://clang.llvm.org/) is a compiler with many desirable features |
4 (outlined on their website). | 4 (outlined on their website). |
5 | 5 |
6 Chrome can be built with Clang. It is now the default compiler on Mac and Linux | 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 | 7 for building Chrome, and it is currently useful for its warning and error |
8 messages on Android and Windows. | 8 messages on Android and Windows. |
9 | 9 |
10 See | 10 See |
11 [the open bugs](http://code.google.com/p/chromium/issues/list?q=label:clang). | 11 [the open bugs](http://code.google.com/p/chromium/issues/list?q=label:clang). |
12 | 12 |
13 [TOC] | 13 [TOC] |
14 | 14 |
15 ## Build instructions | 15 ## Build instructions |
16 | 16 |
17 Get clang (happens automatically during `gclient runhooks` on Mac and Linux): | 17 Get clang (happens automatically during `gclient runhooks` on Mac and Linux): |
18 | 18 |
19 tools/clang/scripts/update.py | 19 tools/clang/scripts/update.py |
20 | 20 |
21 Only needs to be run once per checkout, and clang will be automatically updated | 21 Only needs to be run once per checkout, and clang will be automatically updated |
22 by `gclient runhooks`. | 22 by `gclient runhooks`. |
23 | 23 |
24 Regenerate the ninja build files with Clang enabled. Again, on Linux and Mac, | 24 Regenerate the ninja build files with Clang enabled. Again, on Linux and Mac, |
25 Clang is the default compiler. | 25 Clang is the default compiler. |
26 | 26 |
27 Run `gn args` and add `is_clang = true` to your args.gn file. | 27 Run `gn args` and add `is_clang = true` to your args.gn file. |
28 | 28 |
29 Build: `ninja -C out/Debug chrome` | 29 Build: `ninja -C out/gn chrome` |
30 | 30 |
31 ## Reverting to gcc on linux | 31 ## Reverting to gcc on linux |
32 | 32 |
33 We don't have bots that test this, but building with gcc4.8+ should still work | 33 We don't have bots that test this, but building with gcc4.8+ should still work |
34 on Linux. If your system gcc is new enough, run `gn args` and add `is_clang = | 34 on Linux. If your system gcc is new enough, run `gn args` and add `is_clang = |
35 false`. | 35 false`. |
36 | 36 |
37 ## Mailing List | 37 ## Mailing List |
38 | 38 |
39 http://groups.google.com/a/chromium.org/group/clang/topics | 39 http://groups.google.com/a/chromium.org/group/clang/topics |
(...skipping 10 matching lines...) Expand all Loading... |
50 to build the plugin. | 50 to build the plugin. |
51 1. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build incrementall
y. | 51 1. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build incrementall
y. |
52 1. Build with clang like described above, but, if you use goma, disable it. | 52 1. Build with clang like described above, but, if you use goma, disable it. |
53 | 53 |
54 To test the FindBadConstructs plugin, run: | 54 To test the FindBadConstructs plugin, run: |
55 | 55 |
56 (cd tools/clang/plugins/tests && \ | 56 (cd tools/clang/plugins/tests && \ |
57 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \ | 57 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \ |
58 ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBad
Constructs.so) | 58 ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBad
Constructs.so) |
59 | 59 |
60 These instructions are for GYP which no longer works. Something similar needs | |
61 to be set up for the GN build if you want to do this. For reference, here are | |
62 the old instructions: To run [other plugins](writing_clang_plugins.md), add | |
63 these to your `GYP_DEFINES`: | |
64 | |
65 * `clang_load`: Absolute path to a dynamic library containing your plugin | |
66 * `clang_add_plugin`: tells clang to run a specific PluginASTAction | |
67 | |
68 So for example, you could use the plugin in this directory with: | |
69 | |
70 * `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so | |
71 clang_add_plugin=find-bad-constructs' gclient runhooks` | |
72 | |
73 ## Using the clang static analyzer | 60 ## Using the clang static analyzer |
74 | 61 |
75 See [clang_static_analyzer.md](clang_static_analyzer.md). | 62 See [clang_static_analyzer.md](clang_static_analyzer.md). |
76 | 63 |
77 ## Windows | 64 ## Windows |
78 | 65 |
79 clang can be used as compiler on Windows. Clang uses Visual Studio's linker and | 66 clang can be used as compiler on Windows. Clang uses Visual Studio's linker and |
80 SDK, so you still need to have Visual Studio installed. | 67 SDK, so you still need to have Visual Studio installed. |
81 | 68 |
82 Things should compile, and all tests should pass. You can check these bots for | 69 Things should compile, and all tests should pass. You can check these bots for |
83 how things are currently looking: | 70 how things are currently looking: |
84 http://build.chromium.org/p/chromium.fyi/console?category=win%20clang | 71 http://build.chromium.org/p/chromium.fyi/console?category=win%20clang |
85 | 72 |
86 ``` shell | 73 ```shell |
87 python tools\clang\scripts\update.py | 74 python tools\clang\scripts\update.py |
88 # run `gn args` and add `is_clang = true` to your args.gn, then... | 75 # run `gn args` and add `is_clang = true` to your args.gn, then... |
89 ninja -C out\Debug chrome | 76 ninja -C out\gn chrome |
90 ``` | 77 ``` |
91 | 78 |
92 The `update.py` script only needs to be run once per checkout. Clang will be | 79 The `update.py` script only needs to be run once per checkout. Clang will be |
93 kept up to date by `gclient runhooks`. | 80 kept up to date by `gclient runhooks`. |
94 | 81 |
95 Current brokenness: | 82 Current brokenness: |
96 | 83 |
97 * To get colored diagnostics, you need to be running | 84 * To get colored diagnostics, you need to be running |
98 [ansicon](https://github.com/adoxa/ansicon/releases). | 85 [ansicon](https://github.com/adoxa/ansicon/releases). |
99 * Debug info does now work, but support for it is new. If you see something | 86 * Debug info does now work, but support for it is new. If you see something |
100 not working right, please file a bug and mark it as blocking the | 87 not working right, please file a bug and mark it as blocking the |
101 [clang/win debug info tracking bug](https://crbug.com/636111). | 88 [clang/win debug info tracking bug](https://crbug.com/636111). |
102 | 89 |
103 ## Using a custom clang binary | 90 ## Using a custom clang binary |
104 | 91 |
105 These instructions are for GYP which no longer works. Something similar needs | 92 Set `clang_base_path` in your args.gn to the llvm build directory containing |
106 to be set up for the GN build if you want to do this. For reference, here are | 93 `bin/clang` (i.e. the directory you ran cmake). This [must][1] be an absolute |
107 the old instructions: | 94 path. You also need to disable chromium's clang plugin. |
108 | |
109 If you want to try building Chromium with your own clang binary that you've | |
110 already built, set `make_clang_dir` to the directory containing `bin/clang` | |
111 (i.e. the directory you ran cmake in, or your `Release+Asserts` folder if you | |
112 use the configure/make build). You also need to disable chromium's clang plugin | |
113 by setting `clang_use_chrome_plugins=0`, as it likely won't load in your custom | |
114 clang binary. | |
115 | 95 |
116 Here's an example that also disables debug info and enables the component build | 96 Here's an example that also disables debug info and enables the component build |
117 (both not strictly necessary, but they will speed up your build): | 97 (both not strictly necessary, but they will speed up your build): |
118 | 98 |
119 ```shell | 99 ``` |
120 GYP_DEFINES="clang=1 fastbuild=1 component=shared_library \ | 100 clang_base_path = getenv("HOME") + "/src/llvm-build" |
121 clang_use_chrome_plugins=0 make_clang_dir=$HOME/src/llvm-build" \ | 101 clang_use_chrome_plugins = false |
122 build/gyp_chromium | 102 is_debug = false |
| 103 symbol_level = 1 |
| 104 is_component_build = true |
| 105 is_clang = true # Implicitly set on Mac, Linux, iOS; needed on Win and Android. |
123 ``` | 106 ``` |
124 | 107 |
125 You can then run `head out/Release/build.ninja` and check that the first to | 108 You can then run `head out/gn/toolchain.ninja` and check that the first to |
126 lines set `cc` and `cxx` to your clang binary. If things look good, run `ninja | 109 lines set `cc` and `cxx` to your clang binary. If things look good, run `ninja |
127 -C out/Release` to build. | 110 -C out/gn` to build. |
128 | 111 |
129 If your clang revision is very different from the one currently used in chromium | 112 If your clang revision is very different from the one currently used in chromium |
130 | 113 |
131 * Check `tools/clang/scripts/update.py` to find chromium's clang revision | 114 * Check `tools/clang/scripts/update.py` to find chromium's clang revision |
132 * You might have to tweak warning flags. Or you could set `werror=` in the | 115 * You might have to tweak warning flags. |
133 line above to disable warnings as errors (but this only works on Linux). | |
134 | 116 |
135 ## Using LLD | 117 ## Using LLD |
136 | 118 |
137 **Experimental!** | 119 **Experimental!** |
138 | 120 |
139 LLD is a relatively new linker from LLVM. The current focus is on Windows and | 121 LLD is a relatively new linker from LLVM. The current focus is on Windows and |
140 Linux support, where it can link Chrome approximately twice as fast as gold and | 122 Linux support, where it can link Chrome approximately twice as fast as gold and |
141 MSVC's link.exe as of this writing. LLD does not yet support generating PDB | 123 MSVC's link.exe as of this writing. LLD does not yet support generating PDB |
142 files, which makes it hard to debug Chrome while using LLD. | 124 files, which makes it hard to debug Chrome while using LLD. |
143 | 125 |
144 Set `use_lld = true` in args.gn. Currently this configuration is only supported | |
145 on Windows. | 126 on Windows. |
| 127 Set `use_lld = true` in args.gn. |
OLD | NEW |