ci: integrate clang-tidy checks - #239
Open
kilinchange wants to merge 1 commit into
Open
kilinchange wants to merge 1 commit into
kilinchange wants to merge 1 commit into
Conversation
kilinchange
force-pushed
the
style/clang-tidy-bootstrap
branch
10 times, most recently
from
September 24, 2026 10:59
95cf552 to
c2eb7d6
Compare
Chamberlain0w0
requested changes
Sep 28, 2026
| location = source_manager.getSpellingLoc(location); | ||
| if (source_manager.isInSystemHeader(location) || | ||
| source_manager.isWrittenInMainFile(location)) { | ||
| return; |
Contributor
There was a problem hiding this comment.
这里不能直接跳过主文件。本地增量检查会把修改的 .h 文件直接传给 clang-tidy,此时头文件本身就是主文件,其中的违规成员函数也会被跳过,导致本地检查漏报、CI 全量检查才报错。建议区分头文件和源文件,不要仅根据是否为主文件来跳过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
本 PR 为 InfiniTrain 接入 clang-tidy 静态检查基础设施,提供统一的规则配置、本地执行入口和 CI 检查流程,并支持通过 clang-tidy plugin 扩展项目自定义检查规则。
本次接入以建立基础能力为主,不尝试一次性覆盖完整的 Google C++ Style。对于 clang-tidy 已有且能够准确表达的规则优先直接复用;对于需要额外语义判断、容易产生误报的规范,后续按需通过项目自定义 check 实现。
主要改动
1. 新增 clang-tidy 配置
新增仓库级
.clang-tidy配置,当前启用:其中:
infinitrain-no-member-definitions-in-headers为 InfiniTrain 自定义规则;readability-identifier-naming为 clang-tidy 内置规则,本次仅选择能够明确映射到现有代码规范的命名项作为使用示例,避免通过复杂豁免规则强行模拟 clang-tidy 无法准确表达的语义。例如枚举值使用 constant-style 命名:
所有 clang-tidy diagnostics 当前统一作为 error 处理。
2. 新增 InfiniTrain clang-tidy plugin
在
tools/clang_tidy/下新增项目自定义 clang-tidy plugin,并实现:该规则用于约束 InfiniTrain 项目中的普通成员函数实现位置。
对于不需要在头文件中提供实现的成员函数,应在头文件中保留声明,并将具体实现放到对应源文件中,以减少头文件中的实现细节和不必要的编译依赖。
以下情况不会触发该规则:
constexpr/consteval函数;= default/= delete函数;该规则属于 InfiniTrain 项目自身的额外约束,并非用于完整复刻 Google C++ Style。
3. 新增统一执行脚本
新增:
作为本地开发和 CI 的统一 clang-tidy 执行入口,支持:
检查报告输出到:
其中去重仅用于改善报告可读性,不改变 clang-tidy 的原始退出状态。
4. 接入 GitHub Actions
新增
clang-tidyworkflow,在以下场景运行:master。CI 首先执行轻量的变更检测。不存在 C/C++、CMake、clang-tidy 配置或相关基础设施修改时,直接跳过后续依赖安装和静态检查。
存在相关修改时,CI 会:
CI 的变更检测仅用于决定是否执行 clang-tidy,实际执行时仍对 compilation database 中符合条件的 translation unit 进行完整扫描。
当前扫描排除:
当前 compilation database 为 CPU-only,不包含 CUDA translation unit,因此纯
.cu修改不会触发本轮 clang-tidy 扫描。CUDA 静态检查后续在具备对应 toolchain 和 compilation database 后单独接入。5. 补充使用文档
新增:
说明:
本地运行
构建 clang-tidy plugin:
生成 compilation database:
cmake -S . -B build/lint -G Ninja \ -DCMAKE_CXX_COMPILER=clang++-18 \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DCMAKE_CXX_SCAN_FOR_MODULES=OFF \ -DUSE_CUDA=OFF \ -DUSE_NCCL=OFF \ -DUSE_OMP=OFF \ -DBUILD_TEST=ON执行与 CI 相同的全量检查:
检查当前分支相对于
master修改行产生的 diagnostics: