mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Let CI check C++ includes
The commit adds a CI workflow that uses the included-what-you-use (IWYU) tool to check for missing or superfluous includes in .cpp files and their corresponding .h files. This means that some .h files (especially in the nnue folder) are not checked yet. The CI setup looks like this: - We build IWYU from source to include some yet unreleased fixes. This IWYU version targets LLVM 17. Thus, we get the latest release candidate of LLVM 17 from LLVM's nightly packages. - The Makefile now has an analyze target that just build the object files (without linking) - The CI uses the analyze target with the IWYU tool as compiler to analyze the compiled .cpp file and its corresponding .h file. - If IWYU suggests a change the build fails (-Xiwyu --error). - To avoid false positives we use LLVM's libc++ as standard library - We have a custom mappings file that adds some mappings that are missing in IWYU's default mappings We also had to add one IWYU pragma to prevent a false positive in movegen.h. https://github.com/official-stockfish/Stockfish/pull/4783 No functional change
This commit is contained in:
parent
e594aa7429
commit
952740b36c
6 changed files with 76 additions and 4 deletions
21
.github/workflows/libcxx17.imp
vendored
Normal file
21
.github/workflows/libcxx17.imp
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
[
|
||||||
|
# Mappings for libcxx's internal headers
|
||||||
|
{ include: [ "<__fwd/fstream.h>", private, "<iosfwd>", public ] },
|
||||||
|
{ include: [ "<__fwd/ios.h>", private, "<iosfwd>", public ] },
|
||||||
|
{ include: [ "<__fwd/istream.h>", private, "<iosfwd>", public ] },
|
||||||
|
{ include: [ "<__fwd/ostream.h>", private, "<iosfwd>", public ] },
|
||||||
|
{ include: [ "<__fwd/sstream.h>", private, "<iosfwd>", public ] },
|
||||||
|
{ include: [ "<__fwd/streambuf.h>", private, "<iosfwd>", public ] },
|
||||||
|
{ include: [ "<__fwd/string_view.h>", private, "<string_view>", public ] },
|
||||||
|
|
||||||
|
# Mappings for includes between public headers
|
||||||
|
{ include: [ "<ios>", public, "<iostream>", public ] },
|
||||||
|
{ include: [ "<streambuf>", public, "<iostream>", public ] },
|
||||||
|
{ include: [ "<istream>", public, "<iostream>", public ] },
|
||||||
|
{ include: [ "<ostream>", public, "<iostream>", public ] },
|
||||||
|
{ include: [ "<iosfwd>", public, "<iostream>", public ] },
|
||||||
|
|
||||||
|
# Missing mappings in include-what-you-use's libcxx.imp
|
||||||
|
{ include: ["@<__condition_variable/.*>", private, "<condition_variable>", public ] },
|
||||||
|
{ include: ["@<__mutex/.*>", private, "<mutex>", public ] },
|
||||||
|
]
|
2
.github/workflows/stockfish.yml
vendored
2
.github/workflows/stockfish.yml
vendored
|
@ -33,6 +33,8 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
Analyzers:
|
||||||
|
uses: ./.github/workflows/stockfish_analyzers.yml
|
||||||
Sanitizers:
|
Sanitizers:
|
||||||
uses: ./.github/workflows/stockfish_sanitizers.yml
|
uses: ./.github/workflows/stockfish_sanitizers.yml
|
||||||
Tests:
|
Tests:
|
||||||
|
|
47
.github/workflows/stockfish_analyzers.yml
vendored
Normal file
47
.github/workflows/stockfish_analyzers.yml
vendored
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
name: Stockfish
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
jobs:
|
||||||
|
Analyzers:
|
||||||
|
name: Check includes
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: Stockfish/src
|
||||||
|
shell: bash
|
||||||
|
steps:
|
||||||
|
- name: Checkout Stockfish
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
path: Stockfish
|
||||||
|
|
||||||
|
- name: Checkout include-what-you-use
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: include-what-you-use/include-what-you-use
|
||||||
|
ref: f25caa280dc3277c4086ec345ad279a2463fea0f
|
||||||
|
path: include-what-you-use
|
||||||
|
|
||||||
|
- name: Download required linux packages
|
||||||
|
run: |
|
||||||
|
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main'
|
||||||
|
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y libclang-17-dev clang-17 libc++-17-dev
|
||||||
|
|
||||||
|
- name: Set up include-what-you-use
|
||||||
|
run: |
|
||||||
|
mkdir build && cd build
|
||||||
|
cmake -G "Unix Makefiles" -DCMAKE_PREFIX_PATH="/usr/lib/llvm-17" ..
|
||||||
|
sudo make install
|
||||||
|
working-directory: include-what-you-use
|
||||||
|
|
||||||
|
- name: Check include-what-you-use
|
||||||
|
run: include-what-you-use --version
|
||||||
|
|
||||||
|
- name: Check includes
|
||||||
|
run: >
|
||||||
|
make analyze
|
||||||
|
COMP=clang
|
||||||
|
CXX=include-what-you-use
|
||||||
|
CXXFLAGS="-stdlib=libc++ -Xiwyu --comment_style=long -Xiwyu --mapping='${{ github.workspace }}/Stockfish/.github/workflows/libcxx17.imp' -Xiwyu --error"
|
|
@ -837,12 +837,15 @@ ifneq ($(SUPPORTED_ARCH), true)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
.PHONY: help build profile-build strip install clean net objclean profileclean \
|
.PHONY: help analyze build profile-build strip install clean net \
|
||||||
config-sanity \
|
objclean profileclean config-sanity \
|
||||||
icx-profile-use icx-profile-make \
|
icx-profile-use icx-profile-make \
|
||||||
gcc-profile-use gcc-profile-make \
|
gcc-profile-use gcc-profile-make \
|
||||||
clang-profile-use clang-profile-make FORCE
|
clang-profile-use clang-profile-make FORCE
|
||||||
|
|
||||||
|
analyze: net config-sanity objclean
|
||||||
|
$(MAKE) -k ARCH=$(ARCH) COMP=$(COMP) $(OBJS)
|
||||||
|
|
||||||
build: net config-sanity
|
build: net config-sanity
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) all
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
namespace Stockfish {
|
namespace Stockfish {
|
||||||
|
|
||||||
class Position;
|
class Position;
|
||||||
enum Value : int;
|
|
||||||
|
|
||||||
namespace Eval {
|
namespace Eval {
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#ifndef MOVEGEN_H_INCLUDED
|
#ifndef MOVEGEN_H_INCLUDED
|
||||||
#define MOVEGEN_H_INCLUDED
|
#define MOVEGEN_H_INCLUDED
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm> // IWYU pragma: keep
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
Loading…
Add table
Reference in a new issue