blob: b6b8cb59e48e8866c85233cf03378e24b611dfc2 [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
Will Cassellaee180272021-12-03 18:16:21291. Run `./tools/clang/scripts/build.py --without-android --without-fuchsia`
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 && \
Will Cassellaee180272021-12-03 18:16:2137 ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang)
jyasskin37110bc2015-12-04 03:40:2438
Daniel Cheng7174602d2018-03-29 20:49:1439Since the plugin is rolled with clang changes, behavior changes to the plugin
40should be guarded by flags to make it easy to roll clang. A general outline:
411. Implement new plugin behavior behind a flag.
421. Wait for a compiler roll to bring in the flag.
431. Start passing the new flag in `GN` and verify the new behavior.
441. Enable the new plugin behavior unconditionally and update the plugin to
45 ignore the flag.
461. Wait for another compiler roll.
471. Stop passing the flag from `GN`.
481. Remove the flag completely.
49
andybons3322f762015-08-24 21:37:0950## Using the clang static analyzer
51
kirillbobyreveed2584d2015-11-02 14:38:2952See [clang_static_analyzer.md](clang_static_analyzer.md).
andybons3322f762015-08-24 21:37:0953
54## Windows
55
Nico Weberb1617012019-09-06 18:20:3256clang is the default compiler on Windows. It uses MSVC's SDK, so you still need
57to have Visual Studio with C++ support installed.
andybons3322f762015-08-24 21:37:0958
59## Using a custom clang binary
60
thakis2a46c2d12016-11-29 22:41:3861Set `clang_base_path` in your args.gn to the llvm build directory containing
Nico Weber8699c0562019-09-06 19:05:5662`bin/clang` (i.e. the directory you ran cmake). This must be an absolute
thakis2a46c2d12016-11-29 22:41:3863path. You also need to disable chromium's clang plugin.
andybons3322f762015-08-24 21:37:0964
andybons6eaa0c0d2015-08-26 20:12:5265Here's an example that also disables debug info and enables the component build
66(both not strictly necessary, but they will speed up your build):
andybons3322f762015-08-24 21:37:0967
thakis2a46c2d12016-11-29 22:41:3868```
69clang_base_path = getenv("HOME") + "/src/llvm-build"
70clang_use_chrome_plugins = false
71is_debug = false
72symbol_level = 1
73is_component_build = true
andybons3322f762015-08-24 21:37:0974```
75
Nico Weberd9b4f452019-10-09 17:58:1676On Windows, for `clang_base_path` use something like this instead:
77
78```
79clang_base_path = "c:/src/llvm-build"
80```
81
Lei Zhang4906c17c2021-05-12 11:31:0182You can then look in `out/gn/toolchain.ninja` and check that the `rule cc` and
83`rule cxx` commands run your clang binary. If things look good, run `ninja
thakis2a46c2d12016-11-29 22:41:3884-C out/gn` to build.
andybons3322f762015-08-24 21:37:0985
Nico Weber14735122019-08-12 13:39:0586Chromium tries to be buildable with its currently pinned clang, and with clang
87trunk. Set `llvm_force_head_revision = true` in your args.gn if the clang you're
88trying to build with is closer to clang trunk than to Chromium's pinned clang
89(which `tools/clang/scripts/update.py --print-revision` prints).
Nico Weber46a1d77a2020-12-07 14:39:1390
91## Related documents
92
93* [Toolchain support](toolchain_support.md) gives an overview of clang
94 rolls, and documents when to revert clang rolls and how to file good
95 toolchain bugs.
96
97* [Updating clang](updating_clang.md) documents the mechanics of updating clang,
98 and which files are included in the default clang package.
99
100* [Clang Sheriffing](clang_sheriffing.md) contains instructions for how to debug
101 compiler bugs, for clang sheriffs.
Nico Weber6a992f32021-11-30 17:48:26102
103* [Clang Tool Refactoring](clang_tool_refactoring.md) has notes on how to build
104 and run refactoring tools based on clang's libraries.