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 If you use gyp: `GYP_DEFINES=clang=1 build/gyp_chromium` | 27 Run `gn args` and add `is_clang = true` to your args.gn file. |
28 | |
29 If you use gn, run `gn args` and add `is_clang = true` to your args.gn file. | |
30 | 28 |
31 Build: `ninja -C out/Debug chrome` | 29 Build: `ninja -C out/Debug chrome` |
32 | 30 |
33 ## Reverting to gcc on linux | 31 ## Reverting to gcc on linux |
34 | 32 |
35 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 |
36 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 = |
37 false`. | 35 false`. |
38 | 36 |
39 ## Mailing List | 37 ## Mailing List |
(...skipping 12 matching lines...) Expand all Loading... |
52 to build the plugin. | 50 to build the plugin. |
53 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. |
54 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. |
55 | 53 |
56 To test the FindBadConstructs plugin, run: | 54 To test the FindBadConstructs plugin, run: |
57 | 55 |
58 (cd tools/clang/plugins/tests && \ | 56 (cd tools/clang/plugins/tests && \ |
59 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \ | 57 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \ |
60 ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBad
Constructs.so) | 58 ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBad
Constructs.so) |
61 | 59 |
62 To run [other plugins](writing_clang_plugins.md), add these to your | 60 These instructions are for GYP which no longer works. Something similar needs |
63 `GYP_DEFINES` (this is not currently set up in GN): | 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 | 64 |
65 * `clang_load`: Absolute path to a dynamic library containing your plugin | 65 * `clang_load`: Absolute path to a dynamic library containing your plugin |
66 * `clang_add_plugin`: tells clang to run a specific PluginASTAction | 66 * `clang_add_plugin`: tells clang to run a specific PluginASTAction |
67 | 67 |
68 So for example, you could use the plugin in this directory with: | 68 So for example, you could use the plugin in this directory with: |
69 | 69 |
70 * `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so | 70 * `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so |
71 clang_add_plugin=find-bad-constructs' gclient runhooks` | 71 clang_add_plugin=find-bad-constructs' gclient runhooks` |
72 | 72 |
73 ## Using the clang static analyzer | 73 ## Using the clang static analyzer |
74 | 74 |
75 See [clang_static_analyzer.md](clang_static_analyzer.md). | 75 See [clang_static_analyzer.md](clang_static_analyzer.md). |
76 | 76 |
77 ## Windows | 77 ## Windows |
78 | 78 |
79 clang can be used as compiler on Windows. Clang uses Visual Studio's linker and | 79 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. | 80 SDK, so you still need to have Visual Studio installed. |
81 | 81 |
82 Things should compile, and all tests should pass. You can check these bots for | 82 Things should compile, and all tests should pass. You can check these bots for |
83 how things are currently looking: | 83 how things are currently looking: |
84 http://build.chromium.org/p/chromium.fyi/console?category=win%20clang | 84 http://build.chromium.org/p/chromium.fyi/console?category=win%20clang |
85 | 85 |
86 ``` shell | 86 ``` shell |
87 python tools\clang\scripts\update.py | 87 python tools\clang\scripts\update.py |
88 set GYP_DEFINES=clang=1 | 88 # run `gn args` and add `is_clang = true` to your args.gn, then... |
89 python build\gyp_chromium | |
90 | |
91 # or, if you use gn, run `gn args` and add `is_clang = true` to your args.gn | |
92 ninja -C out\Debug chrome | 89 ninja -C out\Debug chrome |
93 ``` | 90 ``` |
94 | 91 |
95 The `update.py` script only needs to be run once per checkout. Clang will be | 92 The `update.py` script only needs to be run once per checkout. Clang will be |
96 kept up to date by `gclient runhooks`. | 93 kept up to date by `gclient runhooks`. |
97 | 94 |
98 Current brokenness: | 95 Current brokenness: |
99 | 96 |
100 * Debug info is very limited. | 97 * Debug info is very limited. |
101 * To get colored diagnostics, you need to be running | 98 * To get colored diagnostics, you need to be running |
102 [ansicon](https://github.com/adoxa/ansicon/releases). | 99 [ansicon](https://github.com/adoxa/ansicon/releases). |
103 | 100 |
104 ## Using a custom clang binary | 101 ## Using a custom clang binary |
105 | 102 |
| 103 These instructions are for GYP which no longer works. Something similar needs |
| 104 to be set up for the GN build if you want to do this. For reference, here are |
| 105 the old instructions: |
| 106 |
106 If you want to try building Chromium with your own clang binary that you've | 107 If you want to try building Chromium with your own clang binary that you've |
107 already built, set `make_clang_dir` to the directory containing `bin/clang` | 108 already built, set `make_clang_dir` to the directory containing `bin/clang` |
108 (i.e. the directory you ran cmake in, or your `Release+Asserts` folder if you | 109 (i.e. the directory you ran cmake in, or your `Release+Asserts` folder if you |
109 use the configure/make build). You also need to disable chromium's clang plugin | 110 use the configure/make build). You also need to disable chromium's clang plugin |
110 by setting `clang_use_chrome_plugins=0`, as it likely won't load in your custom | 111 by setting `clang_use_chrome_plugins=0`, as it likely won't load in your custom |
111 clang binary. | 112 clang binary. |
112 | 113 |
113 Here's an example that also disables debug info and enables the component build | 114 Here's an example that also disables debug info and enables the component build |
114 (both not strictly necessary, but they will speed up your build): | 115 (both not strictly necessary, but they will speed up your build): |
115 | 116 |
(...skipping 15 matching lines...) Expand all Loading... |
131 | 132 |
132 ## Using LLD | 133 ## Using LLD |
133 | 134 |
134 **Experimental!** | 135 **Experimental!** |
135 | 136 |
136 LLD is a relatively new linker from LLVM. The current focus is on Windows and | 137 LLD is a relatively new linker from LLVM. The current focus is on Windows and |
137 Linux support, where it can link Chrome approximately twice as fast as gold and | 138 Linux support, where it can link Chrome approximately twice as fast as gold and |
138 MSVC's link.exe as of this writing. LLD does not yet support generating PDB | 139 MSVC's link.exe as of this writing. LLD does not yet support generating PDB |
139 files, which makes it hard to debug Chrome while using LLD. | 140 files, which makes it hard to debug Chrome while using LLD. |
140 | 141 |
141 If you use gyp, you can enable it with `GYP_DEFINES=lld=1`. If you use gn, set | 142 Set `use_lld = true` in args.gn. Currently this configuration is only supported |
142 `use_lld = true` in args.gn. Currently this configuration is only supported on | 143 on Windows. |
143 Windows. | |
OLD | NEW |