diff --git a/.github/workflows/iwyu.yml b/.github/workflows/iwyu.yml new file mode 100644 index 0000000..7f34c2d --- /dev/null +++ b/.github/workflows/iwyu.yml @@ -0,0 +1,47 @@ +name: IWYU + +on: + workflow_call: # Can also run on PRs by changing this to 'pull_request' + pull_request: +jobs: + Analyzers: + name: Check headers (IWYU) + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ github.workspace }} + shell: bash + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y cmake ninja-build clang-17 libc++-17-dev libclang-17-dev wget + + - name: Checkout IWYU + uses: actions/checkout@v4 + with: + repository: include-what-you-use/include-what-you-use + ref: f25caa280dc3277c4086ec345ad279a2463fea0f + path: include-what-you-use + persist-credentials: false + + - name: Build IWYU + run: | + mkdir -p build_iwyu && cd build_iwyu + cmake -G "Ninja" -DCMAKE_PREFIX_PATH="/usr/lib/llvm-17" ../include-what-you-use + ninja + sudo ninja install + + - name: Check IWYU version + run: include-what-you-use --version + + - name: Run IWYU analysis + run: | + # Generate compile_commands.json for your library + cmake -B build_iwyu_analysis -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -S . + + # Run IWYU on all source files + iwyu_tool.py -p build_iwyu_analysis -- -Xiwyu --mapping="${{ github.workspace }}/.github/ci/libcxx17.imp" -Xiwyu --error diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e1a665..9c8cc1d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,33 @@ on: branches: [ "main" ] jobs: + determine_changes: + name: Determine if functional changes exist + runs-on: ubuntu-latest + outputs: + skip_full_tests: ${{ steps.check.outputs.skip_full_tests }} + steps: + - uses: actions/checkout@v4 + - id: check + run: | + # Check if PR body contains "no functional change" + if echo "${{ github.event.pull_request.body }}" | grep -iq "no functional changes"; then + echo "skip_full_tests=true" >> $GITHUB_OUTPUT + exit 0 + fi + # List changed files between PR base and head + CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) + + # Check if any .cpp or .c files changed + if echo "$CHANGED" | grep -E '\.(cpp|c)$' >/dev/null; then + echo "skip_full_tests=false" >> "$GITHUB_OUTPUT" + else + echo "skip_full_tests=true" >> "$GITHUB_OUTPUT" + fi + build: - if: ${{ !endsWith(github.event.pull_request.title, 'no functional change') }} + needs: determine_changes + if: ${{ needs.determine_changes.outputs.skip_full_tests != 'true' }} runs-on: ${{ matrix.os }} strategy: @@ -52,7 +77,7 @@ jobs: shell: bash run: | if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then - if "${{ matrix.cpp_compiler }}" == "clang++" ]]; then + if [[ "${{ matrix.cpp_compiler }}" == "clang++" ]]; then SANITIZERS="memory,undefined" else SANITIZERS="address,undefined" diff --git a/.github/workflows/try_compile.yml b/.github/workflows/try_compile.yml index e436057..a1759f3 100644 --- a/.github/workflows/try_compile.yml +++ b/.github/workflows/try_compile.yml @@ -2,7 +2,7 @@ name: Compilation on: push: - + branches-ignore: main jobs: build: runs-on: ${{ matrix.os }} diff --git a/attacks.cpp b/attacks.cpp index 69d0efc..899f960 100644 --- a/attacks.cpp +++ b/attacks.cpp @@ -1,5 +1,8 @@ #include "attacks.h" - +#include "bitboard.h" +#include +#include +#include namespace chess::_chess { // [INTERNAL] @@ -190,4 +193,4 @@ inline static std::array, SQ_NONE + 1> generat return squares_between_bb; } std::array, SQ_NONE + 1> SQUARES_BETWEEN_BB = generate_between(); -} // namespace chess::movegen \ No newline at end of file +} // namespace chess::movegen diff --git a/attacks.h b/attacks.h index 5027d84..08d4b22 100644 --- a/attacks.h +++ b/attacks.h @@ -1,6 +1,4 @@ #pragma once -#include "bitboard.h" -#include "fwd_decl.h" #include "types.h" #include #include diff --git a/moves_io.cpp b/moves_io.cpp index 06a89fe..6d613da 100644 --- a/moves_io.cpp +++ b/moves_io.cpp @@ -1,11 +1,11 @@ #include "moves_io.h" +#include "attacks.h" #include "position.h" #include "types.h" #include -#include -#include +#include +#include #include -#if defined(__EXCEPTIONS) #define THROW_IF_EXCEPTIONS_ON(stuff) throw stuff #else #define THROW_IF_EXCEPTIONS_ON(stuff) ((void)0) diff --git a/moves_io.h b/moves_io.h index 5dccb74..b94cda1 100644 --- a/moves_io.h +++ b/moves_io.h @@ -1,9 +1,11 @@ #pragma once -#include "fwd_decl.h" -#include -#include +#include "types.h" +#include #include #include +namespace chess { +template class _Position; +} namespace chess::uci { std::string moveToUci(Move move, bool chess960 = false); diff --git a/position.cpp b/position.cpp index fb0b5b7..b35fe13 100644 --- a/position.cpp +++ b/position.cpp @@ -4,6 +4,7 @@ #include "printers.h" #include "zobrist.h" #include +#include #include #include #include diff --git a/position.h b/position.h index 178e886..e7113a2 100644 --- a/position.h +++ b/position.h @@ -1,11 +1,17 @@ #pragma once #include "attacks.h" #include "bitboard.h" +#include "fwd_decl.h" #include "movegen.h" #include "types.h" #include "zobrist.h" +#include +#include +#include +#include #include #include +#include #include namespace chess { diff --git a/printers.cpp b/printers.cpp index 74e69cc..f13315b 100644 --- a/printers.cpp +++ b/printers.cpp @@ -2,8 +2,10 @@ #include "moves_io.h" #include "position.h" #include +#include #include #include +#include #include namespace chess { template using DescriptiveNameNotation = std::unordered_map; @@ -146,4 +148,4 @@ template std::ostream &operator<<(std::ostream &os, INSTANTITATE(EnginePiece) INSTANTITATE(PolyglotPiece) INSTANTITATE(ContiguousMappingPiece) -} // namespace chess \ No newline at end of file +} // namespace chess diff --git a/printers.h b/printers.h index 42581c0..96bec90 100644 --- a/printers.h +++ b/printers.h @@ -1,6 +1,5 @@ #pragma once -#include "fwd_decl.h" -#include +#include "types.h" #include #include namespace chess { @@ -16,4 +15,4 @@ template class _Position; template ::value>> std::ostream &operator<<(std::ostream &os, const _Position &pos); -} // namespace chess \ No newline at end of file +} // namespace chess