Skip to content

Commit 4d94209

Browse files
committed
Change fixed clang-format version to 15
* We commit statically linked x64 binaries for clang-format-15 for windows and linux to make the transition easier for anyone running a linux distro that doesn't yet support llvm 15, or in future for distros that drop support for it.
1 parent 5e7b25e commit 4d94209

File tree

9 files changed

+70
-23
lines changed

9 files changed

+70
-23
lines changed

.clang-format

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
Language: Cpp
32
# BasedOnStyle: Chromium
43
AccessModifierOffset: -2
54
AlignAfterOpenBracket: Align
@@ -11,7 +10,8 @@ AlignTrailingComments: true
1110
AllowAllParametersOfDeclarationOnNextLine: false
1211
AllowShortBlocksOnASingleLine: false
1312
AllowShortCaseLabelsOnASingleLine: true
14-
AllowShortFunctionsOnASingleLine: Inline
13+
AllowShortFunctionsOnASingleLine: InlineOnly
14+
AllowShortLambdasOnASingleLine: All
1515
AllowShortIfStatementsOnASingleLine: false
1616
AllowShortLoopsOnASingleLine: false
1717
AlwaysBreakAfterDefinitionReturnType: None
@@ -21,6 +21,7 @@ AlwaysBreakTemplateDeclarations: true
2121
BinPackArguments: true
2222
BinPackParameters: true
2323
BraceWrapping:
24+
AfterCaseLabel: true
2425
AfterClass: true
2526
AfterControlStatement: true
2627
AfterEnum: true
@@ -44,7 +45,9 @@ ContinuationIndentWidth: 4
4445
Cpp11BracedListStyle: true
4546
DerivePointerAlignment: false
4647
DisableFormat: false
48+
EmptyLineBeforeAccessModifier: Leave
4749
ExperimentalAutoDetectBinPacking: false
50+
FixNamespaceComments: false
4851
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
4952
IncludeCategories:
5053
- Regex: '<.*\.h>'
@@ -55,6 +58,7 @@ IncludeCategories:
5558
Priority: 3
5659
- Regex: '.*'
5760
Priority: 4
61+
IncludeIsMainRegex: ''
5862
IndentCaseLabels: true
5963
IndentWidth: 2
6064
IndentWrappedFunctionNames: false
@@ -63,7 +67,9 @@ MacroBlockBegin: ''
6367
MacroBlockEnd: ''
6468
MaxEmptyLinesToKeep: 1
6569
NamespaceIndentation: None
70+
ObjCBinPackProtocolList: Never
6671
ObjCBlockIndentWidth: 2
72+
ObjCBreakBeforeNestedBlockParam: true
6773
ObjCSpaceAfterProperty: false
6874
ObjCSpaceBeforeProtocolList: false
6975
PenaltyBreakBeforeFirstCallParameter: 1
@@ -75,18 +81,33 @@ PenaltyReturnTypeOnItsOwnLine: 2000
7581
PointerAlignment: Right
7682
ReflowComments: true
7783
SortIncludes: true
84+
SortUsingDeclarations: false
7885
SpaceAfterCStyleCast: false
7986
SpaceBeforeAssignmentOperators: true
8087
SpaceBeforeParens: Never
8188
SpaceInEmptyParentheses: false
8289
SpacesBeforeTrailingComments: 4
83-
SpacesInAngles: false
90+
SpacesInAngles: Never
8491
SpacesInContainerLiterals: true
8592
SpacesInCStyleCastParentheses: false
8693
SpacesInParentheses: false
8794
SpacesInSquareBrackets: false
8895
Standard: Auto
96+
StatementMacros:
97+
- Q_UNUSED
98+
- QT_REQUIRE_VERSION
99+
- BEGIN_ENUM_STRINGISE
100+
- BEGIN_ENUM_CLASS_STRINGISE
101+
- STRINGISE_ENUM
102+
- STRINGISE_ENUM_CLASS
103+
- STRINGISE_ENUM_NAMED
104+
- STRINGISE_ENUM_CLASS_NAMED
105+
- STRINGISE_BITFIELD_BIT
89106
TabWidth: 2
90107
UseTab: Never
108+
---
109+
Language: Cpp
110+
---
111+
Language: ObjC
91112
...
92113

.github/workflows/ci.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,7 @@ jobs:
4242
- uses: actions/checkout@v3
4343
with:
4444
fetch-depth: 5
45-
- name: Add LLVM apt repository
46-
run: |
47-
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
48-
sudo add-apt-repository -y 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.8 main'
49-
sudo apt-get update
50-
curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
51-
sudo dpkg -i libffi6_3.2.1-8_amd64.deb
52-
- name: Install clang-format-3.8
53-
run: |
54-
sudo apt-get install -y clang-format-3.8
55-
- name: Run clang-format-3.8
45+
- name: Run clang-format
5646
run: |
5747
. ./util/clang_format_all.sh
5848
git clean -f

docs/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Commit messages should have a first line with a **maximum of 72 characters**, th
4141

4242
For more information, check the section about [commit messages](CONTRIBUTING/Preparing-Commits.md#commit-messages).
4343

44-
Code should be formatted using **clang-format 3.8**. The reason we fix a specific version of clang-format is that unfortunately different versions can format code in different ways using the same config file, so this would cause problems with automatic verification of code formatting.
44+
Code should be formatted using **clang-format 15.0**. The reason we fix a specific version of clang-format is that unfortunately different versions can format code in different ways using the same config file, so this would cause problems with automatic verification of code formatting.
4545

4646
For more information, check the section about [code formatting](CONTRIBUTING/Preparing-Commits.md#code-formatting).
4747

docs/CONTRIBUTING/Preparing-Commits.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ Likewise commits for code formatting or compile fixes should be squashed into th
2020

2121
To make things easier for everyone, I've adopted clang-format for keeping code consistently formatted.
2222

23-
| :warning: | | :warning: |
24-
| --------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------- |
25-
| :warning: | **Unfortunately clang-format output changes between versions even with the same config.** | :warning: |
26-
| :warning: | **I have fixed the version used for RenderDoc at [clang-format-3.8](http://releases.llvm.org/download.html#3.8.1).** | :warning: |
27-
| :warning: | **This formatting is enforced by CI checks that run on PRs, so if you aren't running the same version locally it will show up there.** | :warning: |
23+
| :warning: | | :warning: |
24+
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------- | --------- |
25+
| :warning: | **Unfortunately clang-format output changes between versions even with the same config.** | :warning: |
26+
| :warning: | **I have fixed the version used for RenderDoc at [clang-format-15.0](https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7).** | :warning: |
27+
| :warning: | **This formatting is enforced by CI checks that run on PRs, so if you aren't running the same version locally it will show up there.** | :warning: |
28+
29+
This version changed as of 2023-09-02, from clang-format-3.8 to clang-format-15.0. A statically linked binary of clang-format-15.0.7 for x64 windows and linux is committed to the repo under util/clangformat.
2830

2931
If you want to format a single file, run: `clang-format -i file.cpp`. If you want to format any changes you make before you commit them, you'll need python installed and then run: `git clang-format`. To clang-format the whole codebase, you can run the bash script `util/clang_format_all.sh` but be sure to squash any changes into the right commits.
3032

util/clang_format_all.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

3-
CLANG_MAJOR=3
4-
CLANG_MINOR=8
3+
CLANG_MAJOR=15
4+
CLANG_MINOR=0
55

66
CLANG_FORMAT_VERSION=$CLANG_MAJOR.$CLANG_MINOR
77

@@ -47,12 +47,24 @@ fi;
4747

4848
# Check if we have a valid $CLANG_FORMAT
4949
if ! valid_clang_format; then
50-
# If we didn't find one, bail out
50+
SCRIPTDIR=$(dirname $(readlink -f $0));
51+
# If we didn't find one, fall back to repo-included binary. Check it can run
52+
if "${SCRIPTDIR}"/clangformat/clang-format-15.0.exe --version 2>&1 | grep -q 15.0.7;
53+
then
54+
CLANG_FORMAT="${SCRIPTDIR}"/clangformat/clang-format-15.0.exe
55+
elif "${SCRIPTDIR}"/clangformat/clang-format-15.0 --version 2>&1 | grep -q 15.0.7;
56+
then
57+
CLANG_FORMAT="${SCRIPTDIR}"/clangformat/clang-format-15.0
58+
fi
59+
fi
60+
61+
if ! valid_clang_format; then
5162
echo "Couldn't find correct clang-format version, was looking for $CLANG_FORMAT_VERSION"
5263
echo "Renderdoc requires a very specific clang-format version to ensure there isn't any"
5364
echo "variance between versions that can happen. You can install it as"
5465
echo "'clang-format-$CLANG_FORMAT_VERSION' so that it doesn't interfere with any other"
5566
echo "versions you might have installed, and this script will find it there"
67+
echo "The repository includes a windows and linux x64 binary version, but it failed to run."
5668
exit 1;
5769
fi;
5870

util/clangformat/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Building static clang-format
2+
3+
The docker script will build and static link clang-format to make a portable static linked binary.
4+
5+
```
6+
docker run --rm -v $(pwd):/script:ro -v $(pwd):/out ubuntu:jammy bash /script/build.sh
7+
```
8+

util/clangformat/build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
apt-get update
6+
apt-get install -y git cmake python3 gcc g++
7+
8+
git clone --depth=5 https://github.com/llvm/llvm-project --branch llvmorg-15.0.7
9+
mkdir llvm-build
10+
cd llvm-build
11+
cmake /llvm-project/llvm -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_EXE_LINKER_FLAGS=-static -DCMAKE_BUILD_TYPE=Release
12+
make -j8 clang-format
13+
strip --strip-unneeded bin/clang-format
14+
cp bin/clang-format /out

util/clangformat/clang-format-15.0

1.91 MB
Binary file not shown.
1.12 MB
Binary file not shown.

0 commit comments

Comments
 (0)