diff --git a/.github/workflows/pawn-tests.yaml b/.github/workflows/pawn-tests.yaml index b225992..6ed5b2b 100644 --- a/.github/workflows/pawn-tests.yaml +++ b/.github/workflows/pawn-tests.yaml @@ -1,4 +1,4 @@ -name: Pawn tests +name: Build and test pawn on: push: @@ -11,20 +11,87 @@ on: jobs: build: - name: Building and testing pawn - runs-on: ubuntu-latest + name: ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }} + env: + CC: ${{ matrix.config.cc }} + CXX: ${{ matrix.config.cxx }} + strategy: + fail-fast: false + matrix: + config: + - name: "Ubuntu Latest - GCC" + os: ubuntu-latest + cc: gcc + cxx: g++ + shell: bash + - name: "Ubuntu Latest - Clang" + os: ubuntu-latest + cc: clang + cxx: clang++ + shell: bash + - name: "Ubuntu 20.04 - GCC" + os: ubuntu-20.04 + cc: gcc + cxx: g++ + shell: bash + - name: "Ubuntu 20.04 - Clang" + os: ubuntu-20.04 + cc: clang + cxx: clang++ + shell: bash + - name: "MacOS - GCC 11" + os: macos-latest + cc: gcc-11 + cxx: g++-11 + shell: bash + - name: "MacOS - Clang" + os: macos-latest + cc: clang + cxx: clang++ + shell: bash + - name: "Windows 2022 - GCC" + os: windows-2022 + cc: gcc + cxx: g++ + sys: mingw64 + packages: mingw-w64-x86_64-gcc + shell: msys2 {0} + - name: "Windows 2022 - Clang" + os: windows-2022 + cc: clang + cxx: clang++ + sys: mingw64 + packages: mingw-w64-x86_64-clang mingw-w64-x86_64-lld + shell: msys2 {0} + defaults: + run: + shell: ${{ matrix.config.shell }} steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Extract bench signature - run: "git log HEAD | grep 'Bench: ' | head -n 1 | awk '{print $2}' > bench.sig" + - name: Prepare Windows with MSYS2 + if: runner.os == 'Windows' + uses: msys2/setup-msys2@v2 + with: + msystem: ${{matrix.config.sys}} + install: make git diffutils ${{matrix.config.packages}} + - name: Fetch bench signature + run: "git log HEAD | grep 'Bench: ' | head -n 1 | awk '{print $2}' > bench.sig_ref" - name: Build pawn run: "make" - name: Run bench - run: "build/pawn bench 2>&1 | grep 'Nodes searched:' | awk '{print $3}' > bench.out" - - name: Verify bench signature - run: "cmp bench.sig bench.out" + run: | + build/pawn bench > bench.out 2>&1 + cat bench.out + - name: Extract and verify bench signature + run: | + cat bench.out | grep 'Nodes searched:' | awk '{print $3}' > bench.sig + cmp bench.sig bench.sig_ref - name: Run tests - run: "build/pawn test | grep -q 'All tests passed'" + run: | + build/pawn test > test.out + cat test.out + grep -q 'All tests passed' test.out diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..aa9f0a2 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,77 @@ +name: Upload binaries to release + +on: + release: + types: [published] + +permissions: + contents: write + +jobs: + build: + name: ${{matrix.config.name}} + runs-on: ${{matrix.config.os}} + env: + CC: ${{matrix.config.cc}} + CXX: ${{matrix.config.cxx}} + strategy: + fail-fast: false + matrix: + config: + - name: ubuntu + os: ubuntu-20.04 + cc: gcc + cxx: g++ + shell: bash + - name: macos + os: macos-latest + cc: gcc-11 + cxx: g++-11 + shell: bash + - name: windows + os: windows-2022 + cc: gcc + cxx: g++ + sys: mingw64 + packages: mingw-w64-x86_64-gcc + shell: msys2 {0} + binaries: + - x86-64 + - haswell + defaults: + run: + shell: ${{matrix.config.shell}} + steps: + - name: Check out repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Prepare Windows with MSYS2 + if: runner.os == 'Windows' + uses: msys2/setup-msys2@v2 + with: + msystem: ${{matrix.config.sys}} + install: make git diffutils mingw-w64-x86_64-github-cli ${{matrix.config.packages}} + - name: Build + run: make ARCH=${{matrix.binaries}} -j + - name: Verify bench signature + run: | + git log HEAD | grep 'Bench: ' | head -n 1 | awk '{print $2}' > bench.sig_ref + build/pawn bench > bench.out 2>&1 + cat bench.out + cat bench.out | grep 'Nodes searched:' | awk '{print $3}' > bench.sig + cmp bench.sig bench.sig_ref + - name: Upload Release Asset + if: runner.os != 'Windows' + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + cp build/pawn pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}} + gh release upload ${{github.event.release.tag_name}} pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}} + - name: Upload Release Asset (Windows) + if: runner.os == 'Windows' + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + cp build/pawn.exe pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}}.exe + gh release upload ${{github.event.release.tag_name}} pawn-${{github.event.release.tag_name}}-${{matrix.config.name}}-${{matrix.binaries}}.exe diff --git a/Makefile b/Makefile index 7cbd3a7..61cabc0 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,26 @@ SRC_DIR=src ARCH = native # Compiler flags -CFLAGS = -Wall -Isrc/syzygy/Fathom/src -O3 -flto -march=$(ARCH) -CXXFLAGS = -Wall -std=c++17 -Isrc/syzygy/Fathom/src -O3 -flto -march=$(ARCH) -LDFLAGS = -pthread -flto -march=$(ARCH) +COMMON = -Wall -Isrc/syzygy/Fathom/src -O3 -flto -march=$(ARCH) +CFLAGS = $(COMMON) +CXXFLAGS = $(COMMON) -std=c++17 +LDFLAGS = -flto -march=$(ARCH) # Windows-specific stuff ifeq ($(OS), Windows_NT) LDFLAGS += -static BIN_NAME := $(BIN_NAME).exe + ifeq ($(CC), clang) +# Needed for -flto to work on Windows Clang +# This is also the only case where we don't use -pthread + CFLAGS += -fuse-ld=lld + CXXFLAGS += -fuse-ld=lld + LDFLAGS += -fuse-ld=lld + else + LDFLAGS += -pthread + endif +else + LDFLAGS += -pthread endif SRC_FILES := $(shell find $(SRC_DIR) -name *.cpp) src/syzygy/Fathom/src/tbprobe.c diff --git a/src/NNUE.cpp b/src/NNUE.cpp index 9e7baa0..518a34b 100644 --- a/src/NNUE.cpp +++ b/src/NNUE.cpp @@ -1,3 +1,4 @@ +#include "incbin/incbin.h" #include "Types.hpp" #include "NNUE.hpp" #include diff --git a/src/NNUE.hpp b/src/NNUE.hpp index 96a165e..1c17f96 100644 --- a/src/NNUE.hpp +++ b/src/NNUE.hpp @@ -1,7 +1,7 @@ #pragma once -#include "incbin/incbin.h" #include "Types.hpp" + #define NNUE_Default_File "nnue-10427ad1e4e6.dat" diff --git a/src/Tests.cpp b/src/Tests.cpp index 4fead34..75d794d 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp @@ -115,8 +115,8 @@ namespace Tests for (auto& test : tests) { Position pos(test.fen()); - Histories hists; - auto result = Search::perft(pos, test.depth(), hists); + auto hists = std::make_unique(); + auto result = Search::perft(pos, test.depth(), *hists); if (result == test.result()) { std::cout << "[ OK ] " << test.fen() << " (" << result << ")" << std::endl; diff --git a/src/Tests.hpp b/src/Tests.hpp index 3a1bb4b..5e220db 100644 --- a/src/Tests.hpp +++ b/src/Tests.hpp @@ -48,10 +48,10 @@ namespace Tests int n_failed = 0; for (auto& test : tests) { - Histories hists; Position pos(test.fen()); - auto result_base = Search::perft(pos, test.depth() - 1, hists); - auto result_test = Search::template perft(pos, test.depth() - 1, hists); + auto hists = std::make_unique(); + auto result_base = Search::perft(pos, test.depth() - 1, *hists); + auto result_test = Search::template perft(pos, test.depth() - 1, *hists); if (result_base == result_test) { std::cout << "[ OK ] " << test.fen() << " (" << result_test << ")" << std::endl;