blob: 1f3a9761b3f91f626c554b0a10f15e6b84bf9572 [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.
Tom Sepez7b8dfca2025-02-19 19:36:38311. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build
32 incrementally after making changes.
331. Run `(cd tools/clang/plugins/tests && ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang)`
34 to test the plugin after making changes.
351. Build Chromium with clang as usual, but, if you use reclient, disable it.
jyasskin37110bc2015-12-04 03:40:2436
Tom Sepez07b77e62025-05-05 17:41:5237The local plugin will then be used for local builds until the next
38`gclient sync` restores the default toolchain.
39
Daniel Cheng7174602d2018-03-29 20:49:1440Since the plugin is rolled with clang changes, behavior changes to the plugin
Tom Sepez07b77e62025-05-05 17:41:5241should be guarded by flags to make it easy to roll clang without introducing
42unexpected breakage. A general outline:
431. Implement new plugin behavior behind a flag, disabled by default.
Daniel Cheng7174602d2018-03-29 20:49:14441. Wait for a compiler roll to bring in the flag.
451. Start passing the new flag in `GN` and verify the new behavior.
461. Enable the new plugin behavior unconditionally and update the plugin to
47 ignore the flag.
481. Wait for another compiler roll.
491. Stop passing the flag from `GN`.
501. Remove the flag completely.
51
andybons3322f762015-08-24 21:37:0952## Using the clang static analyzer
53
kirillbobyreveed2584d2015-11-02 14:38:2954See [clang_static_analyzer.md](clang_static_analyzer.md).
andybons3322f762015-08-24 21:37:0955
56## Windows
57
Nico Weberb1617012019-09-06 18:20:3258clang is the default compiler on Windows. It uses MSVC's SDK, so you still need
59to have Visual Studio with C++ support installed.
andybons3322f762015-08-24 21:37:0960
61## Using a custom clang binary
62
thakis2a46c2d12016-11-29 22:41:3863Set `clang_base_path` in your args.gn to the llvm build directory containing
Nico Weber8699c0562019-09-06 19:05:5664`bin/clang` (i.e. the directory you ran cmake). This must be an absolute
thakis2a46c2d12016-11-29 22:41:3865path. You also need to disable chromium's clang plugin.
andybons3322f762015-08-24 21:37:0966
andybons6eaa0c0d2015-08-26 20:12:5267Here's an example that also disables debug info and enables the component build
68(both not strictly necessary, but they will speed up your build):
andybons3322f762015-08-24 21:37:0969
thakis2a46c2d12016-11-29 22:41:3870```
71clang_base_path = getenv("HOME") + "/src/llvm-build"
72clang_use_chrome_plugins = false
73is_debug = false
74symbol_level = 1
75is_component_build = true
andybons3322f762015-08-24 21:37:0976```
77
Nico Weberd9b4f452019-10-09 17:58:1678On Windows, for `clang_base_path` use something like this instead:
79
80```
81clang_base_path = "c:/src/llvm-build"
82```
83
Lei Zhang4906c17c2021-05-12 11:31:0184You can then look in `out/gn/toolchain.ninja` and check that the `rule cc` and
85`rule cxx` commands run your clang binary. If things look good, run `ninja
thakis2a46c2d12016-11-29 22:41:3886-C out/gn` to build.
andybons3322f762015-08-24 21:37:0987
Nico Weber14735122019-08-12 13:39:0588Chromium tries to be buildable with its currently pinned clang, and with clang
89trunk. Set `llvm_force_head_revision = true` in your args.gn if the clang you're
90trying to build with is closer to clang trunk than to Chromium's pinned clang
91(which `tools/clang/scripts/update.py --print-revision` prints).
Nico Weber46a1d77a2020-12-07 14:39:1392
93## Related documents
94
95* [Toolchain support](toolchain_support.md) gives an overview of clang
96 rolls, and documents when to revert clang rolls and how to file good
97 toolchain bugs.
98
99* [Updating clang](updating_clang.md) documents the mechanics of updating clang,
100 and which files are included in the default clang package.
101
102* [Clang Sheriffing](clang_sheriffing.md) contains instructions for how to debug
103 compiler bugs, for clang sheriffs.
Nico Weber6a992f32021-11-30 17:48:26104
105* [Clang Tool Refactoring](clang_tool_refactoring.md) has notes on how to build
106 and run refactoring tools based on clang's libraries.
Hans Wennborg4eeedf792025-01-17 14:00:23107
108* [Updating Clang format binaries](updating_clang_format_binaries.md) has notes
109 on how to update clang-format.