blob: c856cbdd7949a306d4101d1714b565b824445786 [file] [log] [blame] [view]
andybons6eaa0c0d2015-08-26 20:12:521# Clang
andybons3322f762015-08-24 21:37:092
Nico Weberb1617012019-09-06 18:20:323Chromium ships a prebuilt [clang](http://clang.llvm.org) binary.
4It's just upstream clang built at a known-good revision that we
5bump every two weeks or so.
andybons3322f762015-08-24 21:37:096
Nico Weberb1617012019-09-06 18:20:327This is the only supported compiler for building Chromium.
andybons6eaa0c0d2015-08-26 20:12:528
9[TOC]
andybons3322f762015-08-24 21:37:0910
Nico Weberb1617012019-09-06 18:20:3211## Using gcc on Linux
andybons3322f762015-08-24 21:37:0912
Nico Weberb1617012019-09-06 18:20:3213`is_clang = false` will make the build use system gcc on Linux. There are no
14bots that test this and there is no guarantee it will work, but we accept
15patches for this configuration.
rnkc052ba32016-04-13 21:13:0016
andybons3322f762015-08-24 21:37:0917## Mailing List
andybons6eaa0c0d2015-08-26 20:12:5218
xiaoyin.l1003c0b2016-12-06 02:51:1719https://groups.google.com/a/chromium.org/group/clang/topics
andybons3322f762015-08-24 21:37:0920
21## Using plugins
22
andybons6eaa0c0d2015-08-26 20:12:5223The
xiaoyin.l1003c0b2016-12-06 02:51:1724[chromium style plugin](https://dev.chromium.org/developers/coding-style/chromium-style-checker-errors)
andybons6eaa0c0d2015-08-26 20:12:5225is used by default when clang is used.
andybons3322f762015-08-24 21:37:0926
27If you're working on the plugin, you can build it locally like so:
28
Hans Wennborgd1eec552019-05-02 14:59:07291. Run `./tools/clang/scripts/build.py --without-android`
andybons6eaa0c0d2015-08-26 20:12:5230 to build the plugin.
jyasskin37110bc2015-12-04 03:40:24311. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build incrementally.
321. Build with clang like described above, but, if you use goma, disable it.
andybons3322f762015-08-24 21:37:0933
jyasskin37110bc2015-12-04 03:40:2434To test the FindBadConstructs plugin, run:
35
36 (cd tools/clang/plugins/tests && \
vmpstr0b23ec1a2016-02-11 21:01:5037 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \
jyasskin37110bc2015-12-04 03:40:2438 ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so)
39
Daniel Cheng7174602d2018-03-29 20:49:1440Since the plugin is rolled with clang changes, behavior changes to the plugin
41should be guarded by flags to make it easy to roll clang. A general outline:
421. Implement new plugin behavior behind a flag.
431. Wait for a compiler roll to bring in the flag.
441. Start passing the new flag in `GN` and verify the new behavior.
451. Enable the new plugin behavior unconditionally and update the plugin to
46 ignore the flag.
471. Wait for another compiler roll.
481. Stop passing the flag from `GN`.
491. Remove the flag completely.
50
andybons3322f762015-08-24 21:37:0951## Using the clang static analyzer
52
kirillbobyreveed2584d2015-11-02 14:38:2953See [clang_static_analyzer.md](clang_static_analyzer.md).
andybons3322f762015-08-24 21:37:0954
55## Windows
56
Nico Weberb1617012019-09-06 18:20:3257clang is the default compiler on Windows. It uses MSVC's SDK, so you still need
58to have Visual Studio with C++ support installed.
andybons3322f762015-08-24 21:37:0959
60## Using a custom clang binary
61
thakis2a46c2d12016-11-29 22:41:3862Set `clang_base_path` in your args.gn to the llvm build directory containing
Nico Weber8699c0562019-09-06 19:05:5663`bin/clang` (i.e. the directory you ran cmake). This must be an absolute
thakis2a46c2d12016-11-29 22:41:3864path. You also need to disable chromium's clang plugin.
andybons3322f762015-08-24 21:37:0965
andybons6eaa0c0d2015-08-26 20:12:5266Here's an example that also disables debug info and enables the component build
67(both not strictly necessary, but they will speed up your build):
andybons3322f762015-08-24 21:37:0968
thakis2a46c2d12016-11-29 22:41:3869```
70clang_base_path = getenv("HOME") + "/src/llvm-build"
71clang_use_chrome_plugins = false
72is_debug = false
73symbol_level = 1
74is_component_build = true
andybons3322f762015-08-24 21:37:0975```
76
Nico Weberd9b4f452019-10-09 17:58:1677On Windows, for `clang_base_path` use something like this instead:
78
79```
80clang_base_path = "c:/src/llvm-build"
81```
82
Lei Zhang4906c17c2021-05-12 11:31:0183You can then look in `out/gn/toolchain.ninja` and check that the `rule cc` and
84`rule cxx` commands run your clang binary. If things look good, run `ninja
thakis2a46c2d12016-11-29 22:41:3885-C out/gn` to build.
andybons3322f762015-08-24 21:37:0986
Nico Weber14735122019-08-12 13:39:0587Chromium tries to be buildable with its currently pinned clang, and with clang
88trunk. Set `llvm_force_head_revision = true` in your args.gn if the clang you're
89trying to build with is closer to clang trunk than to Chromium's pinned clang
90(which `tools/clang/scripts/update.py --print-revision` prints).
Nico Weber46a1d77a2020-12-07 14:39:1391
92## Related documents
93
94* [Toolchain support](toolchain_support.md) gives an overview of clang
95 rolls, and documents when to revert clang rolls and how to file good
96 toolchain bugs.
97
98* [Updating clang](updating_clang.md) documents the mechanics of updating clang,
99 and which files are included in the default clang package.
100
101* [Clang Sheriffing](clang_sheriffing.md) contains instructions for how to debug
102 compiler bugs, for clang sheriffs.