Skip to content

Commit efad266

Browse files
authored
Add and apply pre-commit hooks (#6)
Adds our typical hooks so that style is standardized. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Bradley Dice (https://github.com/bdice) URL: #6
1 parent c447ec5 commit efad266

12 files changed

Lines changed: 453 additions & 235 deletions

.clang-format

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Refer to: https://releases.llvm.org/8.0.0/tools/clang/docs/ClangFormatStyleOptions.html
4+
---
5+
Language: Cpp
6+
# BasedOnStyle: Google
7+
AccessModifierOffset: -1
8+
AlignAfterOpenBracket: Align
9+
AlignConsecutiveAssignments: true
10+
AlignConsecutiveBitFields: true
11+
AlignConsecutiveDeclarations: false
12+
AlignConsecutiveMacros: true
13+
AlignEscapedNewlines: Left
14+
AlignOperands: true
15+
AlignTrailingComments: true
16+
AllowAllArgumentsOnNextLine: true
17+
AllowAllConstructorInitializersOnNextLine: true
18+
AllowAllParametersOfDeclarationOnNextLine: true
19+
AllowShortBlocksOnASingleLine: true
20+
AllowShortCaseLabelsOnASingleLine: true
21+
AllowShortEnumsOnASingleLine: true
22+
AllowShortFunctionsOnASingleLine: All
23+
AllowShortIfStatementsOnASingleLine: true
24+
AllowShortLambdasOnASingleLine: true
25+
AllowShortLoopsOnASingleLine: false
26+
# This is deprecated
27+
AlwaysBreakAfterDefinitionReturnType: None
28+
AlwaysBreakAfterReturnType: None
29+
AlwaysBreakBeforeMultilineStrings: true
30+
AlwaysBreakTemplateDeclarations: Yes
31+
BinPackArguments: false
32+
BinPackParameters: false
33+
BraceWrapping:
34+
AfterClass: false
35+
AfterControlStatement: false
36+
AfterEnum: false
37+
AfterFunction: false
38+
AfterNamespace: false
39+
AfterObjCDeclaration: false
40+
AfterStruct: false
41+
AfterUnion: false
42+
AfterExternBlock: false
43+
BeforeCatch: false
44+
BeforeElse: false
45+
IndentBraces: false
46+
# disabling the below splits, else, they'll just add to the vertical length of source files!
47+
SplitEmptyFunction: false
48+
SplitEmptyRecord: false
49+
SplitEmptyNamespace: false
50+
BreakAfterJavaFieldAnnotations: false
51+
BreakBeforeBinaryOperators: None
52+
BreakBeforeBraces: WebKit
53+
BreakBeforeInheritanceComma: false
54+
BreakBeforeTernaryOperators: true
55+
BreakConstructorInitializersBeforeComma: false
56+
BreakConstructorInitializers: BeforeColon
57+
BreakInheritanceList: BeforeColon
58+
BreakStringLiterals: true
59+
ColumnLimit: 100
60+
CommentPragmas: '(IWYU pragma:|SPDX-)'
61+
CompactNamespaces: false
62+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
63+
# Kept the below 2 to be the same as `IndentWidth` to keep everything uniform
64+
ConstructorInitializerIndentWidth: 2
65+
ContinuationIndentWidth: 2
66+
Cpp11BracedListStyle: true
67+
DerivePointerAlignment: false
68+
DisableFormat: false
69+
ExperimentalAutoDetectBinPacking: false
70+
FixNamespaceComments: true
71+
ForEachMacros:
72+
- foreach
73+
- Q_FOREACH
74+
- BOOST_FOREACH
75+
IncludeBlocks: Regroup
76+
IncludeCategories:
77+
- Regex: '^"' # quoted includes
78+
Priority: 1
79+
- Regex: '^<(thrust|cub|cuda)/' # CCCL includes
80+
Priority: 2
81+
- Regex: '^<(cooperative_groups|cuco|cuda.h|cuda_runtime|device_types|math_constants|nvtx3)' # CUDA includes
82+
Priority: 3
83+
- Regex: '^<.*\..*' # other system includes (e.g. with a '.')
84+
Priority: 4
85+
- Regex: '^<[^.]+>' # STL includes (no '.')
86+
Priority: 5
87+
IndentCaseLabels: true
88+
IndentPPDirectives: None
89+
IndentWidth: 2
90+
IndentWrappedFunctionNames: false
91+
JavaScriptQuotes: Leave
92+
JavaScriptWrapImports: true
93+
KeepEmptyLinesAtTheStartOfBlocks: false
94+
MacroBlockBegin: ''
95+
MacroBlockEnd: ''
96+
MaxEmptyLinesToKeep: 1
97+
NamespaceIndentation: None
98+
ObjCBinPackProtocolList: Never
99+
ObjCBlockIndentWidth: 2
100+
ObjCSpaceAfterProperty: false
101+
ObjCSpaceBeforeProtocolList: true
102+
PenaltyBreakAssignment: 2
103+
PenaltyBreakBeforeFirstCallParameter: 1
104+
PenaltyBreakComment: 300
105+
PenaltyBreakFirstLessLess: 120
106+
PenaltyBreakString: 1000
107+
PenaltyBreakTemplateDeclaration: 10
108+
PenaltyExcessCharacter: 1000000
109+
PenaltyReturnTypeOnItsOwnLine: 200
110+
PointerAlignment: Left
111+
QualifierAlignment: Right
112+
RawStringFormats:
113+
- Language: Cpp
114+
Delimiters:
115+
- cc
116+
- CC
117+
- cpp
118+
- Cpp
119+
- CPP
120+
- 'c++'
121+
- 'C++'
122+
CanonicalDelimiter: ''
123+
- Language: TextProto
124+
Delimiters:
125+
- pb
126+
- PB
127+
- proto
128+
- PROTO
129+
EnclosingFunctions:
130+
- EqualsProto
131+
- EquivToProto
132+
- PARSE_PARTIAL_TEXT_PROTO
133+
- PARSE_TEST_PROTO
134+
- PARSE_TEXT_PROTO
135+
- ParseTextOrDie
136+
- ParseTextProtoOrDie
137+
CanonicalDelimiter: ''
138+
BasedOnStyle: google
139+
# Enabling comment reflow causes doxygen comments to be messed up in their formats!
140+
ReflowComments: true
141+
SortIncludes: true
142+
SortUsingDeclarations: true
143+
SpaceAfterCStyleCast: false
144+
SpaceAfterTemplateKeyword: true
145+
SpaceBeforeAssignmentOperators: true
146+
SpaceBeforeCpp11BracedList: false
147+
SpaceBeforeCtorInitializerColon: true
148+
SpaceBeforeInheritanceColon: true
149+
SpaceBeforeParens: ControlStatements
150+
SpaceBeforeRangeBasedForLoopColon: true
151+
SpaceBeforeSquareBrackets: false
152+
SpaceInEmptyBlock: false
153+
SpaceInEmptyParentheses: false
154+
SpacesBeforeTrailingComments: 2
155+
SpacesInAngles: false
156+
SpacesInConditionalStatement: false
157+
SpacesInContainerLiterals: true
158+
SpacesInCStyleCastParentheses: false
159+
SpacesInParentheses: false
160+
SpacesInSquareBrackets: false
161+
Standard: c++20
162+
StatementMacros:
163+
- Q_UNUSED
164+
- QT_REQUIRE_VERSION
165+
# Be consistent with indent-width, even for people who use tab for indentation!
166+
TabWidth: 2
167+
UseTab: Never

.pre-commit-config.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
ci:
5+
autofix_commit_msg: "[pre-commit.ci] auto code formatting"
6+
autofix_prs: false
7+
autoupdate_branch: ""
8+
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
9+
autoupdate_schedule: quarterly
10+
skip: []
11+
submodules: false
12+
13+
repos:
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v6.0.0
16+
hooks:
17+
- id: trailing-whitespace
18+
- id: end-of-file-fixer
19+
20+
- repo: https://github.com/pre-commit/mirrors-clang-format
21+
rev: v20.1.8
22+
hooks:
23+
- id: clang-format
24+
types_or: [c, c++]
25+
args: ["-fallback-style=none", "-style=file", "-i"]
26+
- id: clang-format
27+
name: clang-format (libcxx stubs)
28+
files: '^libcxx/'
29+
types: [file]
30+
types_or: []
31+
args: ["-fallback-style=none", "-style=file", "-i"]
32+
33+
- repo: https://github.com/sirosen/texthooks
34+
rev: 0.7.1
35+
hooks:
36+
- id: fix-smartquotes
37+
38+
- repo: https://github.com/codespell-project/codespell
39+
rev: v2.4.2
40+
hooks:
41+
- id: codespell
42+
additional_dependencies: [tomli]
43+
args: ["--toml", "pyproject.toml"]
44+
45+
- repo: https://github.com/rapidsai/pre-commit-hooks
46+
rev: v1.5.1
47+
hooks:
48+
- id: verify-copyright
49+
args: [--fix, --spdx]
50+
files: '\.(cmake|cpp|hpp|sh)$'
51+
52+
- repo: https://github.com/zizmorcore/zizmor-pre-commit
53+
rev: v1.25.2
54+
hooks:
55+
- id: zizmor
56+
57+
- repo: local
58+
hooks:
59+
- id: cmake-format
60+
name: cmake-format
61+
entry: ./ci/checks/run-cmake-format.sh cmake-format
62+
language: python
63+
types: [cmake]
64+
additional_dependencies: [cmakelang==0.6.13]
65+
- id: cmake-lint
66+
name: cmake-lint
67+
entry: ./ci/checks/run-cmake-format.sh cmake-lint
68+
language: python
69+
types: [cmake]
70+
additional_dependencies: [cmakelang==0.6.13]

CMakeLists.txt

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,24 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
1616
rapids_cpm_init()
1717
endif()
1818

19-
project(
20-
rtcx
21-
VERSION 0.1.0
22-
LANGUAGES CXX
23-
)
19+
project(rtcx VERSION 0.1.0 LANGUAGES CXX)
2420

2521
option(RTCX_STATIC_LINK_NVRTC "Use static linking for NVRTC" OFF)
2622
option(RTCX_STATIC_LINK_NVJITLINK "Use static linking for nvJitLink" OFF)
2723

28-
rapids_find_package(
29-
CUDAToolkit REQUIRED
30-
BUILD_EXPORT_SET rtcx-exports
31-
INSTALL_EXPORT_SET rtcx-exports
32-
)
24+
rapids_find_package(CUDAToolkit REQUIRED BUILD_EXPORT_SET rtcx-exports
25+
INSTALL_EXPORT_SET rtcx-exports)
3326

3427
if(NOT TARGET zstd)
3528
set(CPM_DOWNLOAD_zstd ON)
36-
rapids_cpm_find(
37-
zstd 1.5.7
38-
GLOBAL_TARGETS zstd
39-
CPM_ARGS
40-
GIT_REPOSITORY https://github.com/facebook/zstd.git
41-
GIT_TAG v1.5.7
42-
GIT_SHALLOW FALSE SOURCE_SUBDIR build/cmake
43-
OPTIONS "ZSTD_BUILD_STATIC ON" "ZSTD_BUILD_SHARED OFF" "ZSTD_BUILD_TESTS OFF"
44-
"ZSTD_BUILD_PROGRAMS OFF" "BUILD_SHARED_LIBS OFF"
45-
)
29+
rapids_cpm_find(zstd 1.5.7
30+
GLOBAL_TARGETS zstd
31+
CPM_ARGS
32+
GIT_REPOSITORY https://github.com/facebook/zstd.git
33+
GIT_TAG v1.5.7
34+
GIT_SHALLOW FALSE SOURCE_SUBDIR build/cmake
35+
OPTIONS "ZSTD_BUILD_STATIC ON" "ZSTD_BUILD_SHARED OFF" "ZSTD_BUILD_TESTS OFF"
36+
"ZSTD_BUILD_PROGRAMS OFF" "BUILD_SHARED_LIBS OFF")
4637

4738
if(zstd_ADDED)
4839
# disable weak symbols support to hide tracing APIs as well
@@ -63,20 +54,15 @@ endif()
6354
add_library(rtcx STATIC hash.cpp rtcx.cpp)
6455
add_library(rtcx::rtcx ALIAS rtcx)
6556

66-
set_target_properties(
67-
rtcx
68-
PROPERTIES CXX_STANDARD 20
69-
CXX_STANDARD_REQUIRED YES
70-
CXX_VISIBILITY_PRESET hidden
71-
VISIBILITY_INLINES_HIDDEN YES
72-
POSITION_INDEPENDENT_CODE ON
73-
)
74-
75-
target_include_directories(
76-
rtcx
77-
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
78-
PRIVATE ${CUDAToolkit_INCLUDE_DIRS}
79-
)
57+
set_target_properties(rtcx
58+
PROPERTIES CXX_STANDARD 20
59+
CXX_STANDARD_REQUIRED YES
60+
CXX_VISIBILITY_PRESET hidden
61+
VISIBILITY_INLINES_HIDDEN YES
62+
POSITION_INDEPENDENT_CODE ON)
63+
64+
target_include_directories(rtcx PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
65+
PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
8066

8167
target_link_libraries(rtcx PRIVATE zstd ${CMAKE_DL_LIBS} nvtx3::nvtx3-cpp)
8268

@@ -112,56 +98,46 @@ include("${CMAKE_CURRENT_LIST_DIR}/embed.cmake")
11298
11399
# Set rtcx_LIBCXX_DIR for consumers using embed_includes with libcxx headers.
114100
set(rtcx_LIBCXX_DIR "${PACKAGE_PREFIX_DIR}/share/rtcx/libcxx")
115-
]=]
116-
)
101+
]=])
117102

118-
string(
119-
CONFIGURE
120-
[=[
103+
string(CONFIGURE [=[
121104
# Embed functions (add_embed, embed_includes, embed_blob, embed)
122105
# are included automatically so consumers don't need explicit include().
123106
include("@CMAKE_CURRENT_SOURCE_DIR@/embed.cmake")
124107
125108
# Set rtcx_LIBCXX_DIR for consumers using embed_includes with libcxx headers.
126109
set(rtcx_LIBCXX_DIR "@CMAKE_CURRENT_SOURCE_DIR@/libcxx")
127110
]=]
128-
rtcx_build_code_string
129-
@ONLY
130-
)
111+
rtcx_build_code_string
112+
@ONLY)
131113

132114
if(NOT RTCX_INSTALL)
133115
set(rtcx_exclude_from_install EXCLUDE_FROM_ALL)
134116
endif()
135117

136-
install(
137-
TARGETS rtcx
138-
EXPORT rtcx-exports
139-
ARCHIVE DESTINATION ${lib_dir}
140-
INCLUDES
141-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
142-
${rtcx_exclude_from_install}
143-
)
118+
install(TARGETS rtcx
119+
EXPORT rtcx-exports
120+
ARCHIVE DESTINATION ${lib_dir}
121+
INCLUDES
122+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
123+
${rtcx_exclude_from_install})
144124

145125
if(RTCX_INSTALL)
146126
install(FILES rtcx.hpp hash.hpp embed.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rtcx)
147127
install(FILES embed.cmake DESTINATION ${lib_dir}/cmake/rtcx)
148128
install(DIRECTORY embed/ DESTINATION ${lib_dir}/cmake/rtcx/embed)
149129
install(DIRECTORY libcxx/ DESTINATION ${CMAKE_INSTALL_DATADIR}/rtcx/libcxx)
150130

151-
rapids_export(
152-
INSTALL rtcx
153-
EXPORT_SET rtcx-exports
154-
GLOBAL_TARGETS rtcx
155-
NAMESPACE rtcx::
156-
FINAL_CODE_BLOCK rtcx_install_code_string
157-
)
131+
rapids_export(INSTALL rtcx
132+
EXPORT_SET rtcx-exports
133+
GLOBAL_TARGETS rtcx
134+
NAMESPACE rtcx::
135+
FINAL_CODE_BLOCK rtcx_install_code_string)
158136
endif()
159137

160138
# Build-tree export (always, so CPM consumers can find_package from the build tree)
161-
rapids_export(
162-
BUILD rtcx
163-
EXPORT_SET rtcx-exports
164-
GLOBAL_TARGETS rtcx
165-
NAMESPACE rtcx::
166-
FINAL_CODE_BLOCK rtcx_build_code_string
167-
)
139+
rapids_export(BUILD rtcx
140+
EXPORT_SET rtcx-exports
141+
GLOBAL_TARGETS rtcx
142+
NAMESPACE rtcx::
143+
FINAL_CODE_BLOCK rtcx_build_code_string)

0 commit comments

Comments
 (0)