Skip to content

Commit 110f049

Browse files
Add clang-format support (#913)
Adds the mechanics for using clang-format but does not reformat the sources or enable checking in CI. - A git-blame ignore file has been committed to the repo which instructs GitHub's blame functionality on the web interface to keep attribution of lines affected by formatting. Local clones may be [configured told similarly](https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/).
1 parent 01cf628 commit 110f049

File tree

16 files changed

+112
-8
lines changed

16 files changed

+112
-8
lines changed

.clang-format

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2024 The Khronos Group Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
---
4+
# Use defaults from the Google style with the following exceptions:
5+
Language: Cpp
6+
BasedOnStyle: Google
7+
IndentWidth: 4
8+
IndentCaseLabels: false
9+
AccessModifierOffset: -2
10+
ColumnLimit: 100
11+
SortIncludes: false
12+
IndentPPDirectives: BeforeHash
13+
...

.git-blame-ignore-revs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2024 The Khronos Group Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Some note about why this hash is ignored (placeholder for initial formatting)

.github/workflows/formatting.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2024 The Khronos Group Inc.
2+
# Copyright 2024 RasterGrid Kft.
3+
# SPDX-License-Identifier: Apache-2.0
4+
name: Formatting
5+
6+
on:
7+
workflow_call:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
clang-format:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Run clang-format
18+
uses: jidicula/[email protected]
19+
with:
20+
clang-format-version: '17'

.github/workflows/windows.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ on:
2525
workflow_dispatch:
2626

2727
jobs:
28+
#formatting:
29+
# uses: ./.github/workflows/formatting.yml
2830
windows:
31+
# Shortcircuit and don't burn CI time when formatting will reject
32+
#needs: formatting
2933
strategy:
3034
matrix:
3135
os: [ windows-latest ]

BUILDING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,5 +638,17 @@ directory of your KTX-Software workarea or set the value of the
638638
`KTX_SPECIFICATION` CMake cache variable to the location of your specification
639639
clone.
640640
641+
Formatting
642+
------------
643+
644+
The KTX repository is transitioning to enforcing a set of formatting guides, checked during CI.
645+
The tool used for this is [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html).
646+
To minimize friction, it is advised that one configure their environment to run ClangFormat in an automated fashion,
647+
minimally before committing to source control, ideally on every save.
648+
649+
### Visual Studio Code
650+
651+
Set the [`editor.formatOnSave`](https://code.visualstudio.com/docs/editor/codebasics#_formatting) option and use one of the C/C++ formatting extensions available, most notably [ms-vscode.cpptools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) or [llvm-vs-code-extensions.vscode-clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd).
652+
641653
642654
{# vim: set ai ts=4 sts=4 sw=2 expandtab textwidth=75:}

external/.clang-format

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2024 The Khronos Group Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
---
4+
# Disable clang-format in this directory
5+
DisableFormat: true
6+
SortIncludes: false
7+
...

external/fmt/.clang-format

Lines changed: 0 additions & 8 deletions
This file was deleted.

include/.clang-format

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2024 The Khronos Group Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
---
4+
# Disable clang-format in this directory
5+
DisableFormat: true
6+
SortIncludes: false
7+
...

lib/.clang-format

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2024 The Khronos Group Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
---
4+
# Use defaults from the Google style with the following exceptions:
5+
Language: Cpp
6+
BasedOnStyle: Google
7+
IndentWidth: 4
8+
IndentCaseLabels: false
9+
AccessModifierOffset: -2
10+
ColumnLimit: 100
11+
SortIncludes: false
12+
AlwaysBreakAfterDefinitionReturnType: TopLevel
13+
IndentPPDirectives: BeforeHash
14+
...

lib/vkformat_check.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
** SPDX-License-Identifier: Apache-2.0
1010
*/
1111

12+
// clang-format off: CI is complicated if formatting checks on generated files are enforced.
1213
#include <stdint.h>
1314
#include <stdbool.h>
1415

@@ -211,3 +212,4 @@ isValidFormat(VkFormat format)
211212
}
212213
}
213214

215+
// clang-format on

0 commit comments

Comments
 (0)