Skip to content

Add clang format file #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
Language: Cpp
BasedOnStyle: LLVM

# Indentation
IndentWidth: 4 # 4 spaces per indent
AccessModifierOffset: -4
IndentAccessModifiers: false # Align access modifiers to braces
NamespaceIndentation: Inner # Indent namspace contents

# Comments which match this regex will be unformatted (and therefore can be longer or have more whitespace than other comments)
CommentPragmas: '^\*\*'


# Alignment
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
AlignCompound: true
PadOperators: true
AlignConsecutiveBitFields:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
# For future versions of clang-format
# AlignFunctionDeclarations: false
# AlignFunctionPointers: false
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true

# Newlines
ColumnLimit: 120
BreakBeforeBraces: Allman # Braces on their own lines
SeparateDefinitionBlocks: Always # Separate definitions (functions etc.) with an empty line
AlwaysBreakTemplateDeclarations: true # Put template on their own lines
AllowShortBlocksOnASingleLine: Never
# On a newer version of clang-format, replace with BinPackArguments: OnePerLine
BinPackArguments: false # Don't allow multiple function arguments on the same line unless they all fit
BinPackParameters: false # Same but for parameters
PackConstructorInitializers: NextLine
AllowShortFunctionsOnASingleLine: None
BreakBeforeBinaryOperators: NonAssignment # Put binary operators after a line break, rather than before

# Spaces
SpaceBeforeParens: ControlStatementsExceptControlMacros
SpaceAfterCStyleCast: true
PointerAlignment: Left

# Includes
IncludeBlocks: Regroup # Regroup includes based on config
IncludeCategories:
- Regex: '(^"|\.hpp)' # 'local' includes
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '\/' # Library includes
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*' # Everything else
Priority: 1
SortPriority: 0
CaseSensitive: false
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,14 @@ class Matrix // No, class is outside GridKit namespace
{
// matrix code
};
```

## Developer tooling

### Auto-formatting

To help enforce the above code style guidelines, we use autoformatting provided by [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html), which is distributed as a part of `clang` and `llvm`. Pull-requests must be formatted using the version of `clang-format` distributed by the version of `llvm` required by development with Enzyme.

VS Code users can use `clang-format` to automatically format their code by installing the [C/C++ Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) and using the `Format Document` command in the command palette with the file to be formatted open. As well, you can enabled the `editor.formatOnSave` option to auto-format any file when you save it.

Other users can use the [`git clang-format`](https://clang.llvm.org/docs/ClangFormat.html#git-integration) subcommand installed along with `clang-format` to auto-format all staged files.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ You should have all of the following installed before installing GridKit™
- [CMake](https://cmake.org/) >= 3.12
- C++ 17 compliant compiler

#### Developer Dependencies
- `clang-format`, which can be obtained through most linux distribution package managers, or through the [LLVM project](https://github.com/llvm/llvm-project) >= 15.0.0

### Installing

GridKit™ uses CMake for build configuration. Per CMake best practices it is recommended
Expand Down