andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 1 | # Clang |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
Nico Weber | b161701 | 2019-09-06 18:20:32 | [diff] [blame] | 3 | Chromium ships a prebuilt [clang](http://clang.llvm.org) binary. |
| 4 | It's just upstream clang built at a known-good revision that we |
| 5 | bump every two weeks or so. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 6 | |
Nico Weber | b161701 | 2019-09-06 18:20:32 | [diff] [blame] | 7 | This is the only supported compiler for building Chromium. |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 8 | |
| 9 | [TOC] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 10 | |
Nico Weber | b161701 | 2019-09-06 18:20:32 | [diff] [blame] | 11 | ## Using gcc on Linux |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 12 | |
Nico Weber | b161701 | 2019-09-06 18:20:32 | [diff] [blame] | 13 | `is_clang = false` will make the build use system gcc on Linux. There are no |
| 14 | bots that test this and there is no guarantee it will work, but we accept |
| 15 | patches for this configuration. |
rnk | c052ba3 | 2016-04-13 21:13:00 | [diff] [blame] | 16 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 17 | ## Mailing List |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 18 | |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 19 | https://groups.google.com/a/chromium.org/group/clang/topics |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 20 | |
| 21 | ## Using plugins |
| 22 | |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 23 | The |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 24 | [chromium style plugin](https://dev.chromium.org/developers/coding-style/chromium-style-checker-errors) |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 25 | is used by default when clang is used. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 26 | |
| 27 | If you're working on the plugin, you can build it locally like so: |
| 28 | |
Will Cassella | ee18027 | 2021-12-03 18:16:21 | [diff] [blame] | 29 | 1. Run `./tools/clang/scripts/build.py --without-android --without-fuchsia` |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 30 | to build the plugin. |
Tom Sepez | 7b8dfca | 2025-02-19 19:36:38 | [diff] [blame] | 31 | 1. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build |
| 32 | incrementally after making changes. |
| 33 | 1. Run `(cd tools/clang/plugins/tests && ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang)` |
| 34 | to test the plugin after making changes. |
| 35 | 1. Build Chromium with clang as usual, but, if you use reclient, disable it. |
jyasskin | 37110bc | 2015-12-04 03:40:24 | [diff] [blame] | 36 | |
Daniel Cheng | 7174602d | 2018-03-29 20:49:14 | [diff] [blame] | 37 | Since the plugin is rolled with clang changes, behavior changes to the plugin |
| 38 | should be guarded by flags to make it easy to roll clang. A general outline: |
| 39 | 1. Implement new plugin behavior behind a flag. |
| 40 | 1. Wait for a compiler roll to bring in the flag. |
| 41 | 1. Start passing the new flag in `GN` and verify the new behavior. |
| 42 | 1. Enable the new plugin behavior unconditionally and update the plugin to |
| 43 | ignore the flag. |
| 44 | 1. Wait for another compiler roll. |
| 45 | 1. Stop passing the flag from `GN`. |
| 46 | 1. Remove the flag completely. |
| 47 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 48 | ## Using the clang static analyzer |
| 49 | |
kirillbobyrev | eed2584d | 2015-11-02 14:38:29 | [diff] [blame] | 50 | See [clang_static_analyzer.md](clang_static_analyzer.md). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 51 | |
| 52 | ## Windows |
| 53 | |
Nico Weber | b161701 | 2019-09-06 18:20:32 | [diff] [blame] | 54 | clang is the default compiler on Windows. It uses MSVC's SDK, so you still need |
| 55 | to have Visual Studio with C++ support installed. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 56 | |
| 57 | ## Using a custom clang binary |
| 58 | |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 59 | Set `clang_base_path` in your args.gn to the llvm build directory containing |
Nico Weber | 8699c056 | 2019-09-06 19:05:56 | [diff] [blame] | 60 | `bin/clang` (i.e. the directory you ran cmake). This must be an absolute |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 61 | path. You also need to disable chromium's clang plugin. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 62 | |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 63 | Here'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): |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 65 | |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 66 | ``` |
| 67 | clang_base_path = getenv("HOME") + "/src/llvm-build" |
| 68 | clang_use_chrome_plugins = false |
| 69 | is_debug = false |
| 70 | symbol_level = 1 |
| 71 | is_component_build = true |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 72 | ``` |
| 73 | |
Nico Weber | d9b4f45 | 2019-10-09 17:58:16 | [diff] [blame] | 74 | On Windows, for `clang_base_path` use something like this instead: |
| 75 | |
| 76 | ``` |
| 77 | clang_base_path = "c:/src/llvm-build" |
| 78 | ``` |
| 79 | |
Lei Zhang | 4906c17c | 2021-05-12 11:31:01 | [diff] [blame] | 80 | You 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 |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 82 | -C out/gn` to build. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 83 | |
Nico Weber | 1473512 | 2019-08-12 13:39:05 | [diff] [blame] | 84 | Chromium tries to be buildable with its currently pinned clang, and with clang |
| 85 | trunk. Set `llvm_force_head_revision = true` in your args.gn if the clang you're |
| 86 | trying 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 Weber | 46a1d77a | 2020-12-07 14:39:13 | [diff] [blame] | 88 | |
| 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 Weber | 6a992f3 | 2021-11-30 17:48:26 | [diff] [blame] | 100 | |
| 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 Wennborg | 4eeedf79 | 2025-01-17 14:00:23 | [diff] [blame] | 103 | |
| 104 | * [Updating Clang format binaries](updating_clang_format_binaries.md) has notes |
| 105 | on how to update clang-format. |