nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 1 | # Updating Clang format binaries |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 3 | Instructions on how to update the [clang-format binaries](clang_format.md) that |
| 4 | come with a checkout of Chromium. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 5 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 6 | ## Prerequisites |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 7 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 8 | You'll need a Windows machine, a Linux machine, and a Mac; all capable of |
| 9 | building clang-format. You'll also need permissions to upload to the appropriate |
| 10 | google storage bucket. Chromium infrastructure team members have this, and |
| 11 | others can be granted the permission based on need. Talk to ncarter or hinoka |
| 12 | about getting access. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 13 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 14 | ## Pick a head svn revision |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 15 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 16 | Consult http://llvm.org/svn/llvm-project/ for the current head revision. This |
| 17 | will be the CLANG_REV you'll use later to check out each platform to a |
| 18 | consistent state. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 19 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 20 | ## Build a release-mode clang-format on each platform |
| 21 | |
qyearsley | c0dc6f4 | 2016-12-02 22:13:39 | [diff] [blame] | 22 | Follow the official instructions here: |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 23 | http://clang.llvm.org/get_started.html. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 24 | |
| 25 | Windows step-by-step: |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 26 | |
| 27 | ```shell |
| 28 | # [double check you have the tools you need] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 29 | where cmake.exe # You need to install this. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 30 | |
Hans Wennborg | 045f4cd | 2020-03-03 13:15:18 | [diff] [blame] | 31 | # In chromium/src |
| 32 | tools\win\setenv amd64_x86 |
| 33 | set CLANG_REV=56ac9d30d35632969baa39829ebc8465ed5937ef # You must change this value (see above) |
| 34 | rmdir /S /Q llvm-project |
| 35 | git clone https://github.com/llvm/llvm-project |
| 36 | cd llvm-project |
| 37 | git checkout %CLANG_REV% |
| 38 | mkdir build |
| 39 | cd build |
| 40 | set CC=..\..\third_party\llvm-build\Release+Asserts\bin\clang-cl.exe |
| 41 | set CXX=..\..\third_party\llvm-build\Release+Asserts\bin\clang-cl.exe |
| 42 | set CFLAGS=-m32 |
| 43 | set CXXLAGS=-m32 |
dbeam | b71beb8 | 2017-01-26 05:52:40 | [diff] [blame] | 44 | cmake -G Ninja ..\llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT ^ |
| 45 | -DLLVM_ENABLE_ASSERTIONS=NO -DLLVM_ENABLE_THREADS=NO ^ |
Hans Wennborg | 045f4cd | 2020-03-03 13:15:18 | [diff] [blame] | 46 | -DLLVM_ENABLE_PROJECTS=clang |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 47 | ninja clang-format |
| 48 | bin\clang-format.exe --version |
| 49 | ``` |
| 50 | |
| 51 | Mac & Linux step-by-step: |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 52 | |
| 53 | ```shell |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 54 | # Check out. |
Tim van der Lippe | 3f8a4984 | 2020-03-03 12:31:24 | [diff] [blame] | 55 | export CLANG_REV=56ac9d30d35632969baa39829ebc8465ed5937ef # You must change this value (see above) |
| 56 | git clone https://github.com/llvm/llvm-project |
| 57 | cd llvm-project |
| 58 | git checkout $CLANG_REV |
| 59 | mkdir build |
| 60 | cd build |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 61 | |
Sam Maier | 9b5c0a7 | 2018-12-06 17:35:46 | [diff] [blame] | 62 | # On Mac, do the following: |
dbeam | b71beb8 | 2017-01-26 05:52:40 | [diff] [blame] | 63 | MACOSX_DEPLOYMENT_TARGET=10.9 cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \ |
Tim van der Lippe | cd5f8b2 | 2020-03-03 13:12:49 | [diff] [blame] | 64 | -DLLVM_ENABLE_PROJECTS=clang \ |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 65 | -DLLVM_ENABLE_ASSERTIONS=NO -DLLVM_ENABLE_THREADS=NO ../llvm/ |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 66 | |
Tim van der Lippe | 3f8a4984 | 2020-03-03 12:31:24 | [diff] [blame] | 67 | # On Linux, do the following: |
| 68 | # Note the relative paths that point to your local Chromium checkout. |
Sam Maier | 9b5c0a7 | 2018-12-06 17:35:46 | [diff] [blame] | 69 | cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \ |
Tim van der Lippe | 3f8a4984 | 2020-03-03 12:31:24 | [diff] [blame] | 70 | -DLLVM_ENABLE_PROJECTS=clang \ |
Sam Maier | 9b5c0a7 | 2018-12-06 17:35:46 | [diff] [blame] | 71 | -DLLVM_ENABLE_ASSERTIONS=NO -DLLVM_ENABLE_THREADS=NO \ |
Tim van der Lippe | 3f8a4984 | 2020-03-03 12:31:24 | [diff] [blame] | 72 | -DCMAKE_C_COMPILER=$PWD/../../chromium/src/third_party/llvm-build/Release+Asserts/bin/clang \ |
| 73 | -DCMAKE_CXX_COMPILER=$PWD/../../chromium/src/third_party/llvm-build/Release+Asserts/bin/clang++ \ |
| 74 | -DCMAKE_ASM_COMPILER=$PWD/../../chromium/src/third_party/llvm-build/Release+Asserts/bin/clang \ |
Sam Maier | 9b5c0a7 | 2018-12-06 17:35:46 | [diff] [blame] | 75 | -DLLVM_ENABLE_TERMINFO=OFF -DCMAKE_CXX_STANDARD_LIBRARIES="-static-libgcc -static-libstdc++" ../llvm/ |
Tim van der Lippe | cd5f8b2 | 2020-03-03 13:12:49 | [diff] [blame] | 76 | |
| 77 | # Finally, build the actual clang-format binary with Ninja |
Sam Maier | 9b5c0a7 | 2018-12-06 17:35:46 | [diff] [blame] | 78 | ninja clang-format |
| 79 | strip bin/clang-format |
| 80 | |
| 81 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 82 | ``` |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 83 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 84 | Platform specific notes: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 85 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 86 | * Windows: Visual Studio 2013 only. |
| 87 | * Linux: so far (as of January 2014) we've just included a 64-bit binary. It's |
| 88 | important to disable threading, else clang-format will depend on |
| 89 | libatomic.so.1 which doesn't exist on Precise. |
| 90 | * Mac: Remember to set `MACOSX_DEPLOYMENT_TARGET` when building! If you get |
| 91 | configure warnings, you may need to install XCode 5 and avoid a goma |
| 92 | environment. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 93 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 94 | ## Upload each binary to google storage |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 95 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 96 | Copy the binaries into your chromium checkout (under |
| 97 | `src/buildtools/(win|linux64|mac)/clang-format(.exe?)`). For each binary, you'll |
| 98 | need to run upload_to_google_storage.py according to the instructions in |
Glen Robertson | 6170fab | 2019-09-26 01:41:38 | [diff] [blame] | 99 | [README.txt](https://chromium.googlesource.com/chromium/src/+/master/buildtools/clang_format/README.txt). |
thakis | b4016a5 | 2017-02-28 00:06:07 | [diff] [blame] | 100 | This will upload the binary into a publicly accessible google storage bucket, |
| 101 | and update `.sha1` file in your Chrome checkout. You'll check in the `.sha1` |
| 102 | file (but NOT the clang-format binary) into source control. In order to be able |
| 103 | to upload, you'll need write permission to the bucket -- see the prerequisites. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 104 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 105 | ## Copy the helper scripts and update README.chromium |
| 106 | |
| 107 | There are some auxiliary scripts that ought to be kept updated in lockstep with |
| 108 | the clang-format binary. These get copied into |
| 109 | third_party/clang_format/scripts in your Chromium checkout. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 110 | |
| 111 | The `README.chromium` file ought to be updated with version and date info. |
| 112 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 113 | ## Upload a CL according to the following template |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 114 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 115 | Update clang-format binaries and scripts for all platforms. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 116 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 117 | I followed these instructions: |
| 118 | https://chromium.googlesource.com/chromium/src/+/master/docs/updating_clang_format_binaries.md |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 119 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 120 | The binaries were built at clang revision ####### on ####DATETIME####. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 121 | |
Henrique Ferreiro | 804beaf | 2020-03-06 20:56:59 | [diff] [blame^] | 122 | Bug: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 123 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 124 | The change should **always** include new `.sha1` files for each platform (we |
| 125 | want to keep these in lockstep), should **never** include `clang-format` |
| 126 | binaries directly. The change should **always** update `README.chromium` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 127 | |
nodir | 06cbaa0 | 2015-08-25 17:15:24 | [diff] [blame] | 128 | clang-format binaries should weigh in at 1.5MB or less. Watch out for size |
| 129 | regressions. |