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 | |
Hans Wennborg | d1eec55 | 2019-05-02 14:59:07 | [diff] [blame] | 29 | 1. Run `./tools/clang/scripts/build.py --without-android` |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 30 | to build the plugin. |
jyasskin | 37110bc | 2015-12-04 03:40:24 | [diff] [blame] | 31 | 1. Run `ninja -C third_party/llvm-build/Release+Asserts/` to build incrementally. |
| 32 | 1. Build with clang like described above, but, if you use goma, disable it. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 33 | |
jyasskin | 37110bc | 2015-12-04 03:40:24 | [diff] [blame] | 34 | To test the FindBadConstructs plugin, run: |
| 35 | |
| 36 | (cd tools/clang/plugins/tests && \ |
vmpstr | 0b23ec1a | 2016-02-11 21:01:50 | [diff] [blame] | 37 | ./test.py ../../../../third_party/llvm-build/Release+Asserts/bin/clang \ |
jyasskin | 37110bc | 2015-12-04 03:40:24 | [diff] [blame] | 38 | ../../../../third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so) |
| 39 | |
Daniel Cheng | 7174602d | 2018-03-29 20:49:14 | [diff] [blame] | 40 | Since the plugin is rolled with clang changes, behavior changes to the plugin |
| 41 | should be guarded by flags to make it easy to roll clang. A general outline: |
| 42 | 1. Implement new plugin behavior behind a flag. |
| 43 | 1. Wait for a compiler roll to bring in the flag. |
| 44 | 1. Start passing the new flag in `GN` and verify the new behavior. |
| 45 | 1. Enable the new plugin behavior unconditionally and update the plugin to |
| 46 | ignore the flag. |
| 47 | 1. Wait for another compiler roll. |
| 48 | 1. Stop passing the flag from `GN`. |
| 49 | 1. Remove the flag completely. |
| 50 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 51 | ## Using the clang static analyzer |
| 52 | |
kirillbobyrev | eed2584d | 2015-11-02 14:38:29 | [diff] [blame] | 53 | See [clang_static_analyzer.md](clang_static_analyzer.md). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 54 | |
| 55 | ## Windows |
| 56 | |
Nico Weber | b161701 | 2019-09-06 18:20:32 | [diff] [blame] | 57 | clang is the default compiler on Windows. It uses MSVC's SDK, so you still need |
| 58 | to have Visual Studio with C++ support installed. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 59 | |
| 60 | ## Using a custom clang binary |
| 61 | |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 62 | 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] | 63 | `bin/clang` (i.e. the directory you ran cmake). This must be an absolute |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 64 | path. You also need to disable chromium's clang plugin. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 65 | |
andybons | 6eaa0c0d | 2015-08-26 20:12:52 | [diff] [blame] | 66 | Here'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): |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 68 | |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 69 | ``` |
| 70 | clang_base_path = getenv("HOME") + "/src/llvm-build" |
| 71 | clang_use_chrome_plugins = false |
| 72 | is_debug = false |
| 73 | symbol_level = 1 |
| 74 | is_component_build = true |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 75 | ``` |
| 76 | |
Nico Weber | d9b4f45 | 2019-10-09 17:58:16 | [diff] [blame] | 77 | On Windows, for `clang_base_path` use something like this instead: |
| 78 | |
| 79 | ``` |
| 80 | clang_base_path = "c:/src/llvm-build" |
| 81 | ``` |
| 82 | |
Lei Zhang | 4906c17c | 2021-05-12 11:31:01 | [diff] [blame] | 83 | You 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 |
thakis | 2a46c2d1 | 2016-11-29 22:41:38 | [diff] [blame] | 85 | -C out/gn` to build. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 86 | |
Nico Weber | 1473512 | 2019-08-12 13:39:05 | [diff] [blame] | 87 | Chromium tries to be buildable with its currently pinned clang, and with clang |
| 88 | trunk. Set `llvm_force_head_revision = true` in your args.gn if the clang you're |
| 89 | trying 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 Weber | 46a1d77a | 2020-12-07 14:39:13 | [diff] [blame] | 91 | |
| 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. |