blob: eb4139f976c5d66dc43c965e1f94ce1d30c1753f [file] [log] [blame] [view]
andybons6eaa0c0d2015-08-26 20:12:521# Clang
andybons3322f762015-08-24 21:37:092
Daniel Bratellfd047c62018-03-12 15:35:023[Clang](http://clang.llvm.org/) is the main supported compiler when
4building Chromium on all platforms.
andybons3322f762015-08-24 21:37:095
Daniel Bratellfd047c62018-03-12 15:35:026Known [clang bugs and feature
7requests](http://code.google.com/p/chromium/issues/list?q=label:clang).
andybons6eaa0c0d2015-08-26 20:12:528
9[TOC]
andybons3322f762015-08-24 21:37:0910
Daniel Bratellfd047c62018-03-12 15:35:0211## Building with clang
andybons3322f762015-08-24 21:37:0912
Daniel Bratellfd047c62018-03-12 15:35:0213This happens by default, with clang binaries being fetched by gclient
14during the `gclient runhooks` phase. To fetch them manually, or build
15a local custom clang, use
andybons3322f762015-08-24 21:37:0916
Nico Weber21e0f4f2015-12-04 14:24:4717 tools/clang/scripts/update.py
andybons6eaa0c0d2015-08-26 20:12:5218
Daniel Bratellfd047c62018-03-12 15:35:0219Run `gn args` and make sure there is no `is_clang = false` in your args.gn file.
andybons3322f762015-08-24 21:37:0920
thakis2a46c2d12016-11-29 22:41:3821Build: `ninja -C out/gn chrome`
andybons3322f762015-08-24 21:37:0922
Daniel Bratellfd047c62018-03-12 15:35:0223## Reverting to gcc on Linux or MSVC on Windows
rnkc052ba32016-04-13 21:13:0024
Daniel Bratellfd047c62018-03-12 15:35:0225There are no bots that test this but `is_clang = false` will revert to
26gcc on Linux and to Visual Studio on Windows. There is no guarantee it
27will work.
rnkc052ba32016-04-13 21:13:0028
andybons3322f762015-08-24 21:37:0929## Mailing List
andybons6eaa0c0d2015-08-26 20:12:5230
xiaoyin.l1003c0b2016-12-06 02:51:1731https://groups.google.com/a/chromium.org/group/clang/topics
andybons3322f762015-08-24 21:37:0932
33## Using plugins
34
andybons6eaa0c0d2015-08-26 20:12:5235The
xiaoyin.l1003c0b2016-12-06 02:51:1736[chromium style plugin](https://dev.chromium.org/developers/coding-style/chromium-style-checker-errors)
andybons6eaa0c0d2015-08-26 20:12:5237is used by default when clang is used.
andybons3322f762015-08-24 21:37:0938
39If you're working on the plugin, you can build it locally like so:
40
Hans Wennborgd1eec552019-05-02 14:59:07411. Run `./tools/clang/scripts/build.py --without-android`
andybons6eaa0c0d2015-08-26 20:12:5242 to build the plugin.
jyasskin37110bc2015-12-04 03:40:24431. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build incrementally.
441. Build with clang like described above, but, if you use goma, disable it.
andybons3322f762015-08-24 21:37:0945
jyasskin37110bc2015-12-04 03:40:2446To test the FindBadConstructs plugin, run:
47
48 (cd tools/clang/plugins/tests && \
vmpstr0b23ec1a2016-02-11 21:01:5049 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \
jyasskin37110bc2015-12-04 03:40:2450 ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so)
51
Daniel Cheng7174602d2018-03-29 20:49:1452Since the plugin is rolled with clang changes, behavior changes to the plugin
53should be guarded by flags to make it easy to roll clang. A general outline:
541. Implement new plugin behavior behind a flag.
551. Wait for a compiler roll to bring in the flag.
561. Start passing the new flag in `GN` and verify the new behavior.
571. Enable the new plugin behavior unconditionally and update the plugin to
58 ignore the flag.
591. Wait for another compiler roll.
601. Stop passing the flag from `GN`.
611. Remove the flag completely.
62
andybons3322f762015-08-24 21:37:0963## Using the clang static analyzer
64
kirillbobyreveed2584d2015-11-02 14:38:2965See [clang_static_analyzer.md](clang_static_analyzer.md).
andybons3322f762015-08-24 21:37:0966
67## Windows
68
Daniel Bratellfd047c62018-03-12 15:35:0269Since October 2017, clang is the default compiler on Windows. It uses
70MSVC's linker and SDK, so you still need to have Visual Studio with
71C++ support installed.
andybons3322f762015-08-24 21:37:0972
Daniel Bratellfd047c62018-03-12 15:35:0273To use MSVC's compiler (if it still works), use `is_clang = false`.
rnkc052ba32016-04-13 21:13:0074
andybons3322f762015-08-24 21:37:0975Current brokenness:
76
andybons6eaa0c0d2015-08-26 20:12:5277* To get colored diagnostics, you need to be running
78 [ansicon](https://github.com/adoxa/ansicon/releases).
andybons3322f762015-08-24 21:37:0979
80## Using a custom clang binary
81
thakis2a46c2d12016-11-29 22:41:3882Set `clang_base_path` in your args.gn to the llvm build directory containing
83`bin/clang` (i.e. the directory you ran cmake). This [must][1] be an absolute
84path. You also need to disable chromium's clang plugin.
andybons3322f762015-08-24 21:37:0985
andybons6eaa0c0d2015-08-26 20:12:5286Here's an example that also disables debug info and enables the component build
87(both not strictly necessary, but they will speed up your build):
andybons3322f762015-08-24 21:37:0988
thakis2a46c2d12016-11-29 22:41:3889```
90clang_base_path = getenv("HOME") + "/src/llvm-build"
91clang_use_chrome_plugins = false
92is_debug = false
93symbol_level = 1
94is_component_build = true
andybons3322f762015-08-24 21:37:0995```
96
thakis2a46c2d12016-11-29 22:41:3897You can then run `head out/gn/toolchain.ninja` and check that the first to
andybons6eaa0c0d2015-08-26 20:12:5298lines set `cc` and `cxx` to your clang binary. If things look good, run `ninja
thakis2a46c2d12016-11-29 22:41:3899-C out/gn` to build.
andybons3322f762015-08-24 21:37:09100
andybons6eaa0c0d2015-08-26 20:12:52101If your clang revision is very different from the one currently used in chromium
102
Nico Weber21e0f4f2015-12-04 14:24:47103* Check `tools/clang/scripts/update.py` to find chromium's clang revision
thakis2a46c2d12016-11-29 22:41:38104* You might have to tweak warning flags.