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 ``` | 18 |
19 ```shell | |
11 tools/clang/scripts/update.sh | 20 tools/clang/scripts/update.sh |
12 ``` | 21 ``` |
nodir
2015/08/26 16:26:17
nit: 4 space indent is best for oneliners
Bons
2015/08/26 19:43:14
Done.
| |
13 | 22 |
14 (Only needs to be run once per checkout, and clang will be automatically updated by `gclient runhooks`.) | 23 (Only needs to be run once per checkout, and clang will be automatically updated |
24 by `gclient runhooks`.) | |
15 | 25 |
16 ### Reverting to gcc on linux | 26 ### Reverting to gcc on linux |
17 | 27 |
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: | 28 We don't have bots that test this, but building with gcc4.8+ should still work |
29 on Linux. If your system gcc is new enough, use this to build with gcc if you | |
30 don't want to build with clang: | |
19 | 31 |
20 ``` | 32 ```shell |
21 GYP_DEFINES=clang=0 build/gyp_chromium | 33 GYP_DEFINES=clang=0 build/gyp_chromium |
22 ``` | 34 ``` |
23 | 35 |
24 ### Ninja | 36 ### Ninja |
25 | 37 |
26 Regenerate the build files (`clang=1` is on by default on Mac and Linux): | 38 Regenerate the build files (`clang=1` is on by default on Mac and Linux): |
27 | 39 |
28 If you use gyp: | 40 If you use gyp: `GYP_DEFINES=clang=1 build/gyp_chromium` |
29 ``` | |
30 GYP_DEFINES=clang=1 build/gyp_chromium | |
31 ``` | |
32 | 41 |
33 If you use gn, run `gn args` and add `is_clang = true` to your args.gn file. | 42 If you use gn, run `gn args` and add `is_clang = true` to your args.gn file. |
34 | 43 |
35 Build: | 44 Build: `ninja -C out/Debug chrome` |
36 ``` | |
37 ninja -C out/Debug chrome | |
38 ``` | |
39 | 45 |
40 ## Mailing List | 46 ## Mailing List |
47 | |
41 http://groups.google.com/a/chromium.org/group/clang/topics | 48 http://groups.google.com/a/chromium.org/group/clang/topics |
42 | 49 |
43 ## Using plugins | 50 ## Using plugins |
44 | 51 |
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. | 52 The |
53 [chromium style plugin](http://dev.chromium.org/developers/coding-style/chromium -style-checker-errors) | |
54 is used by default when clang is used. | |
46 | 55 |
47 If you're working on the plugin, you can build it locally like so: | 56 If you're working on the plugin, you can build it locally like so: |
48 | 57 |
49 1. Run `./tools/clang/scripts/update.sh --force-local-build --without-android` to build the plugin. | 58 1. Run `./tools/clang/scripts/update.sh --force-local-build --without-android` |
50 1. Build with clang like described above. | 59 to build the plugin. |
60 1. Build with clang like described above. | |
51 | 61 |
52 To run [other plugins](WritingClangPlugins.md), add these to your `GYP_DEFINES`: | 62 TODO: writing_clang_plugins does not exist. |
63 To run [other plugins](writing_clang_plugins.md), add these to your | |
64 `GYP_DEFINES`: | |
53 | 65 |
54 * `clang_load`: Absolute path to a dynamic library containing your plugin | 66 * `clang_load`: Absolute path to a dynamic library containing your plugin |
55 * `clang_add_plugin`: tells clang to run a specific PluginASTAction | 67 * `clang_add_plugin`: tells clang to run a specific PluginASTAction |
56 | 68 |
57 So for example, you could use the plugin in this directory with: | 69 So for example, you could use the plugin in this directory with: |
58 | 70 |
59 * `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so clang_add_ plugin=find-bad-constructs' gclient runhooks` | 71 * `GYP_DEFINES='clang=1 clang_load=/path/to/libFindBadConstructs.so |
72 clang_add_plugin=find-bad-constructs' gclient runhooks` | |
60 | 73 |
61 ## Using the clang static analyzer | 74 ## Using the clang static analyzer |
62 | 75 |
63 See ClangStaticAnalyzer. | 76 See [clang_static_analyser.md]. |
nodir
2015/08/26 16:26:17
This won't become a link on itself (unfortunately)
Bons
2015/08/26 19:43:14
Done.
| |
64 | 77 |
65 ## Windows | 78 ## Windows |
66 | 79 |
67 **Experimental!** | 80 **Experimental!** |
68 | 81 |
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. | 82 clang can be used as compiler on Windows. Clang uses Visual Studio's linker and |
83 SDK, so you still need to have Visual Studio installed. | |
70 | 84 |
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 | 85 Things should compile, and all tests should pass. You can check these bots for |
86 how things are currently looking: | |
87 http://build.chromium.org/p/chromium.fyi/console?category=win%20clang | |
72 | 88 |
73 ``` | 89 ``` shell |
74 python tools\clang\scripts\update.py | 90 python tools\clang\scripts\update.py set GYP_DEFINES=clang=1 \ |
nodir
2015/08/26 16:26:17
Not sure this is correct:
is "set" a command of up
Bons
2015/08/26 19:43:14
Done.
| |
75 set GYP_DEFINES=clang=1 | |
76 python build\gyp_chromium | 91 python build\gyp_chromium |
92 | |
77 # or, if you use gn, run `gn args` and add `is_clang = true` to your args.gn | 93 # or, if you use gn, run `gn args` and add `is_clang = true` to your args.gn |
78 ninja -C out\Debug chrome | 94 ninja -C out\Debug chrome |
79 ``` | 95 ``` |
80 | 96 |
81 Current brokenness: | 97 Current brokenness: |
82 | 98 |
83 * Goma doesn't work. | 99 * Goma doesn't work. |
84 * Debug info is very limited. | 100 * Debug info is very limited. |
85 * To get colored diagnostics, you need to be running [ansicon](https://github. com/adoxa/ansicon/releases). | 101 * To get colored diagnostics, you need to be running |
102 [ansicon](https://github.com/adoxa/ansicon/releases). | |
86 | 103 |
87 ## Using a custom clang binary | 104 ## Using a custom clang binary |
88 | 105 |
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. | 106 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 (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 by setting `clang_use_chrome_plugins=0`, as it likely won't load in your custom | |
111 clang binary. | |
90 | 112 |
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): | 113 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): | |
92 | 115 |
93 ``` | 116 ```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 | 117 GYP_DEFINES="clang=1 fastbuild=1 component=shared_library \ |
118 clang_use_chrome_plugins=0 make_clang_dir=$HOME/src/llvm-build" \ | |
119 build/gyp_chromium | |
nodir
2015/08/26 16:26:17
Consider indenting lines 118,119, so it is obvious
Bons
2015/08/26 19:43:14
within the g3 style guide it doesn't show its exam
| |
95 ``` | 120 ``` |
96 | 121 |
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. | 122 You can then run `head out/Release/build.ninja` and check that the first to |
123 lines set `cc` and `cxx` to your clang binary. If things look good, run `ninja | |
124 -C out/Release` to build. | |
98 | 125 |
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). | 126 If your clang revision is very different from the one currently used in chromium |
127 | |
128 * Check `tools/clang/scripts/update.sh` to find chromium's clang revision | |
129 * You might have to tweak warning flags. Or you could set `werror=` in the | |
130 line above to disable warnings as errors (but this only works on Linux). | |
OLD | NEW |