Skip to content
Open
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
11 changes: 6 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential zlib1g-dev libzip-dev opencl-headers ocl-icd-opencl-dev
sudo apt-get install -y cmake build-essential zlib1g-dev libzip-dev opencl-headers ocl-icd-opencl-dev clang-tidy

- name: Cache CMake build
uses: actions/cache@v4
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Configure CMake
working-directory: cpp
run: |
cmake . -DUSE_BACKEND=OPENCL -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-s"
cmake . -DUSE_BACKEND=OPENCL -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-s" -DUSE_CLANG_TIDY=1

- name: Build
working-directory: cpp
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:

- name: Install dependencies
run: |
brew install zlib libzip opencl-headers
brew install zlib libzip opencl-headers llvm
- name: Cache CMake build
uses: actions/cache@v4
with:
Expand All @@ -81,7 +81,7 @@ jobs:
- name: Configure CMake
working-directory: cpp
run: |
cmake . -G Ninja -DUSE_BACKEND=OPENCL -DCMAKE_BUILD_TYPE=Release
cmake . -G Ninja -DUSE_BACKEND=OPENCL -DCMAKE_BUILD_TYPE=Release -DUSE_CLANG_TIDY=1
- name: Build
working-directory: cpp
run: |
Expand Down Expand Up @@ -128,7 +128,8 @@ jobs:
run: |
cmake . -G "Visual Studio 17 2022" -A x64 `
-DUSE_BACKEND=OPENCL `
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake"
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" `
-DUSE_CLANG_TIDY=1

- name: Build
working-directory: cpp
Expand Down
34 changes: 34 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ set(USE_BIGGER_BOARDS_EXPENSIVE 0 CACHE BOOL "Allow boards up to size 50. Compil
set(USE_CACHE_TENSORRT_PLAN 0 CACHE BOOL "Use TENSORRT plan cache. May use a lot of disk space. Only applies when USE_BACKEND is TENSORRT.")
mark_as_advanced(USE_CACHE_TENSORRT_PLAN)

set(USE_CLANG_TIDY 1 CACHE BOOL "Run clang-tidy static analysis during build")

#--------------------------- NEURAL NET BACKEND ------------------------------------------------------------------------

message(STATUS "Building 'katago' executable for GTP engine and other tools.")
Expand Down Expand Up @@ -610,5 +612,37 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "C

endif()

if(USE_CLANG_TIDY)
message(STATUS "Setting up clang-tidy checks.")

set(CLANG_TIDY_HINTS)
if(WIN32)
if(MSVC)
set(_vs_root "$ENV{ProgramFiles}/Microsoft Visual Studio")
if(EXISTS "${_vs_root}")
file(GLOB _vs_install_dirs LIST_DIRECTORIES true "${_vs_root}/*/*")
foreach(_vs_dir ${_vs_install_dirs})
list(APPEND CLANG_TIDY_HINTS "${_vs_dir}/VC/Tools/Llvm/bin")
endforeach()
endif()
else()
list(APPEND CLANG_TIDY_HINTS "$ENV{ProgramFiles}/LLVM/bin")
endif()
elseif(APPLE)
set(CLANG_TIDY_HINTS /opt/homebrew/opt/llvm/bin)
endif()

find_program(CLANG_TIDY_EXE NAMES clang-tidy HINTS ${CLANG_TIDY_HINTS} REQUIRED)

if(MSVC)
set(CLANG_TIDY_EXTRA_ARGS "--extra-arg=/EHsc")
else()
set(CLANG_TIDY_EXTRA_ARGS "--extra-arg=-fexceptions")
endif()

set_target_properties(katago PROPERTIES
CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-checks=-*,performance-inefficient-vector-operation,performance-unnecessary-copy-initialization,readability-non-const-parameter,readability-make-member-function-const;${CLANG_TIDY_EXTRA_ARGS}")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably could enable all performance-related lints:

performance-*

But it provokes too many warnings and most of them aren't valuable.

endif()

target_include_directories(katago PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

2 changes: 1 addition & 1 deletion cpp/core/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ unique_ptr_void make_unique_void(T* ptr)
});
}

template<typename T, typename DeleterRet, DeleterRet (*deleter)(T)>
template<typename T, typename DeleterRet, auto deleter>
struct WrappedWithDeleter {
bool assigned;
T val;
Expand Down
Loading