blob: d9cb1fb8c91d6a385f49a2af7071b6e68c645f65 [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
Daniel Cheng7174602d2018-03-29 20:49:1437Since the plugin is rolled with clang changes, behavior changes to the plugin
38should be guarded by flags to make it easy to roll clang. A general outline:
391. Implement new plugin behavior behind a flag.
401. Wait for a compiler roll to bring in the flag.
411. Start passing the new flag in `GN` and verify the new behavior.
421. Enable the new plugin behavior unconditionally and update the plugin to
43 ignore the flag.
441. Wait for another compiler roll.
451. Stop passing the flag from `GN`.
461. Remove the flag completely.
47
andybons3322f762015-08-24 21:37:0948## Using the clang static analyzer
49
kirillbobyreveed2584d2015-11-02 14:38:2950See [clang_static_analyzer.md](clang_static_analyzer.md).
andybons3322f762015-08-24 21:37:0951
52## Windows
53
Nico Weberb1617012019-09-06 18:20:3254clang is the default compiler on Windows. It uses MSVC's SDK, so you still need
55to have Visual Studio with C++ support installed.
andybons3322f762015-08-24 21:37:0956
57## Using a custom clang binary
58
thakis2a46c2d12016-11-29 22:41:3859Set `clang_base_path` in your args.gn to the llvm build directory containing
Nico Weber8699c0562019-09-06 19:05:5660`bin/clang` (i.e. the directory you ran cmake). This must be an absolute
thakis2a46c2d12016-11-29 22:41:3861path. You also need to disable chromium's clang plugin.
andybons3322f762015-08-24 21:37:0962
andybons6eaa0c0d2015-08-26 20:12:5263Here's an example that also disables debug info and enables the component build
64(both not strictly necessary, but they will speed up your build):
andybons3322f762015-08-24 21:37:0965
thakis2a46c2d12016-11-29 22:41:3866```
67clang_base_path = getenv("HOME") + "/src/llvm-build"
68clang_use_chrome_plugins = false
69is_debug = false
70symbol_level = 1
71is_component_build = true
andybons3322f762015-08-24 21:37:0972```
73
Nico Weberd9b4f452019-10-09 17:58:1674On Windows, for `clang_base_path` use something like this instead:
75
76```
77clang_base_path = "c:/src/llvm-build"
78```
79
Lei Zhang4906c17c2021-05-12 11:31:0180You can then look in `out/gn/toolchain.ninja` and check that the `rule cc` and
81`rule cxx` commands run your clang binary. If things look good, run `ninja
thakis2a46c2d12016-11-29 22:41:3882-C out/gn` to build.
andybons3322f762015-08-24 21:37:0983
Nico Weber14735122019-08-12 13:39:0584Chromium tries to be buildable with its currently pinned clang, and with clang
85trunk. Set `llvm_force_head_revision = true` in your args.gn if the clang you're
86trying to build with is closer to clang trunk than to Chromium's pinned clang
87(which `tools/clang/scripts/update.py --print-revision` prints).
Nico Weber46a1d77a2020-12-07 14:39:1388
89## Related documents
90
91* [Toolchain support](toolchain_support.md) gives an overview of clang
92 rolls, and documents when to revert clang rolls and how to file good
93 toolchain bugs.
94
95* [Updating clang](updating_clang.md) documents the mechanics of updating clang,
96 and which files are included in the default clang package.
97
98* [Clang Sheriffing](clang_sheriffing.md) contains instructions for how to debug
99 compiler bugs, for clang sheriffs.
Nico Weber6a992f32021-11-30 17:48:26100
101* [Clang Tool Refactoring](clang_tool_refactoring.md) has notes on how to build
102 and run refactoring tools based on clang's libraries.
Hans Wennborg4eeedf792025-01-17 14:00:23103
104* [Updating Clang format binaries](updating_clang_format_binaries.md) has notes
105 on how to update clang-format.