From 90f5d7462cb9672a51a92418370713187b0133e5 Mon Sep 17 00:00:00 2001 From: winapiadmin Date: Sat, 25 Oct 2025 17:50:19 +0700 Subject: [PATCH 1/6] Fixes failed workflow https://github.com/winapiadmin/chesslib/actions/runs/18802005646 --- CMakeLists.txt | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 307da05..d3e1305 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,16 +29,25 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") endif() # --- AddressSanitizer for Debug builds --- + if(CMAKE_BUILD_TYPE STREQUAL "Debug") - message(STATUS "Enabling AddressSanitizer") - if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(SANITIZER_FLAGS "/fsanitize=address") - else() - message(STATUS "Enabling UndefinedBehaviorSanitizer") - set(SANITIZER_FLAGS "-fsanitize=address -fsanitize=undefined") + include(CheckCXXCompilerFlag) + # Check for the ASan flag used by GCC/Clang + check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORTS_ASAN_GCC_CLANG) + + # Check for the ASan flag used by MSVC + check_cxx_compiler_flag("/fsanitize=address" COMPILER_SUPPORTS_ASAN_MSVC) + if(COMPILER_SUPPORTS_ASAN_GCC_CLANG OR COMPILER_SUPPORTS_ASAN_MSVC) + message(STATUS "Enabling AddressSanitizer") + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(SANITIZER_FLAGS "/fsanitize=address") + else() + message(STATUS "Enabling UndefinedBehaviorSanitizer") + set(SANITIZER_FLAGS "-fsanitize=address -fsanitize=undefined") + endif() + add_compile_options(${SANITIZER_FLAGS}) + add_link_options(${SANITIZER_FLAGS}) endif() - add_compile_options(${SANITIZER_FLAGS}) - add_link_options(${SANITIZER_FLAGS}) endif() add_compile_definitions(GENERATE_AT_RUNTIME) # --- Core Library --- From 86852b198ca65e4097c4b8f53b526a7f5288ecf8 Mon Sep 17 00:00:00 2001 From: winapiadmin Date: Sat, 25 Oct 2025 17:57:49 +0700 Subject: [PATCH 2/6] Fixed failed workflow --- attacks.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/attacks.h b/attacks.h index 585f703..a5cfe77 100644 --- a/attacks.h +++ b/attacks.h @@ -2,6 +2,12 @@ #include "bitboard.h" #include "types.h" #include +#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \ + defined(__BMI2__) || defined(__M_INTRINSIC_PROMOTE__) +#include +#else +#include +#endif namespace chess::attacks { // clang-format off // pre-calculated lookup table for pawn attacks From cd1d777b95f54fd6860c21db32caf88833c02aa6 Mon Sep 17 00:00:00 2001 From: winapiadmin Date: Sat, 25 Oct 2025 17:59:38 +0700 Subject: [PATCH 3/6] now i realized bmi2intrin.h shouldn't be included directly --- attacks.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/attacks.h b/attacks.h index a5cfe77..8bedbb7 100644 --- a/attacks.h +++ b/attacks.h @@ -2,12 +2,7 @@ #include "bitboard.h" #include "types.h" #include -#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \ - defined(__BMI2__) || defined(__M_INTRINSIC_PROMOTE__) -#include -#else #include -#endif namespace chess::attacks { // clang-format off // pre-calculated lookup table for pawn attacks From f2492ed708ee05e52867605ee7c146562197b1cd Mon Sep 17 00:00:00 2001 From: winapiadmin Date: Sat, 25 Oct 2025 18:05:11 +0700 Subject: [PATCH 4/6] fixed failed workflow --- attacks.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/attacks.cpp b/attacks.cpp index 77200af..473114a 100644 --- a/attacks.cpp +++ b/attacks.cpp @@ -6,7 +6,7 @@ namespace chess::attacks { #define _POSSIBLY_CONSTEXPR const #endif template - _POSSIBLY_CONSTEXPR auto generate_magic_table() { + _POSSIBLY_CONSTEXPR std::pair, std::array> generate_magic_table() { std::array table{}; std::array attacks{}; @@ -44,13 +44,13 @@ namespace chess::attacks { return std::pair{ table, attacks }; } - _POSSIBLY_CONSTEXPR auto bishopData = + _POSSIBLY_CONSTEXPR std::pair, std::array> bishopData = generate_magic_table<_chess::_HyperbolaBishopAttacks, attacks::BishopMagics, 0x1480>(); - _POSSIBLY_CONSTEXPR auto BishopTable = bishopData.first; - _POSSIBLY_CONSTEXPR auto BishopAttacks = bishopData.second; + _POSSIBLY_CONSTEXPR std::array BishopTable = bishopData.first; + _POSSIBLY_CONSTEXPR std::array BishopAttacks = bishopData.second; - _POSSIBLY_CONSTEXPR auto rookData = + _POSSIBLY_CONSTEXPR std::pair, std::array> rookData = generate_magic_table<_chess::_HyperbolaRookAttacks, attacks::RookMagics, 0x19000>(); - _POSSIBLY_CONSTEXPR auto RookTable = rookData.first; - _POSSIBLY_CONSTEXPR auto RookAttacks = rookData.second; + _POSSIBLY_CONSTEXPR std::array RookTable = rookData.first; + _POSSIBLY_CONSTEXPR std::array RookAttacks = rookData.second; } \ No newline at end of file From 8c28a208e1808333f7e7ee9fc1ed50df0344bf3b Mon Sep 17 00:00:00 2001 From: winapiadmin Date: Sat, 25 Oct 2025 18:09:50 +0700 Subject: [PATCH 5/6] fixed ASan/UBSan missing on runtime --- CMakeLists.txt | 84 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3e1305..f82c805 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,22 +32,82 @@ endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") include(CheckCXXCompilerFlag) - # Check for the ASan flag used by GCC/Clang - check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORTS_ASAN_GCC_CLANG) + include(CheckCXXSourceCompiles) - # Check for the ASan flag used by MSVC - check_cxx_compiler_flag("/fsanitize=address" COMPILER_SUPPORTS_ASAN_MSVC) - if(COMPILER_SUPPORTS_ASAN_GCC_CLANG OR COMPILER_SUPPORTS_ASAN_MSVC) - message(STATUS "Enabling AddressSanitizer") - if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(SANITIZER_FLAGS "/fsanitize=address") + # ---------------------------- + # Sanitizer flags per compiler + # ---------------------------- + if(MSVC) + set(ASAN_FLAG "/fsanitize=address") + set(UBSAN_FLAG "/fsanitize=undefined") + else() + set(ASAN_FLAG "-fsanitize=address") + set(UBSAN_FLAG "-fsanitize=undefined") + endif() + + # ---------------------------- + # Helper function to check a sanitizer + # ---------------------------- + function(check_sanitizer FLAG VAR_NAME) + check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORTS_FLAG) + + if(COMPILER_SUPPORTS_FLAG) + message(STATUS "Compiler supports ${FLAG}") + + # Compile + link test + set(CMAKE_REQUIRED_FLAGS "${FLAG}") + check_cxx_source_compiles(" + int main() { return 0; } + " CAN_LINK) + + if(CAN_LINK) + # Optional runtime check + file(WRITE "${CMAKE_BINARY_DIR}/sanitizer_test.cpp" "int main() { return 0; }") + try_run(RUN_RESULT COMPILE_RESULT + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/sanitizer_test.cpp" + CMAKE_FLAGS "-DCMAKE_CXX_FLAGS=${FLAG}" + ) + if(RUN_RESULT EQUAL 0) + message(STATUS "${FLAG} works at runtime") + set(${VAR_NAME} TRUE PARENT_SCOPE) + else() + message(WARNING "${FLAG} compile/link succeeded but runtime test failed") + set(${VAR_NAME} FALSE PARENT_SCOPE) + endif() + else() + message(WARNING "Cannot compile/link with ${FLAG}") + set(${VAR_NAME} FALSE PARENT_SCOPE) + endif() else() - message(STATUS "Enabling UndefinedBehaviorSanitizer") - set(SANITIZER_FLAGS "-fsanitize=address -fsanitize=undefined") + message(STATUS "Compiler does not support ${FLAG}") + set(${VAR_NAME} FALSE PARENT_SCOPE) endif() - add_compile_options(${SANITIZER_FLAGS}) - add_link_options(${SANITIZER_FLAGS}) + endfunction() + + # ---------------------------- + # Check ASan + # ---------------------------- + check_sanitizer(${ASAN_FLAG} ENABLE_ASAN) + + # ---------------------------- + # Check UBSan + # ---------------------------- + check_sanitizer(${UBSAN_FLAG} ENABLE_UBSAN) + + # ---------------------------- + # Set CXX flags if supported + # ---------------------------- + if(ENABLE_ASAN) + message(STATUS "Enabling ASan for build") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_FLAG}" CACHE STRING "CXX flags" FORCE) endif() + + if(ENABLE_UBSAN) + message(STATUS "Enabling UBSan for build") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UBSAN_FLAG}" CACHE STRING "CXX flags" FORCE) + endif() + endif() add_compile_definitions(GENERATE_AT_RUNTIME) # --- Core Library --- From 9d1da377e237a744e13880c069e6596a263b83d9 Mon Sep 17 00:00:00 2001 From: winapiadmin Date: Sat, 25 Oct 2025 18:12:24 +0700 Subject: [PATCH 6/6] disabled ASan (since you'll have to manually do it anyways) --- CMakeLists.txt | 81 -------------------------------------------------- 1 file changed, 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f82c805..e8b7f16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,87 +28,6 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options(/constexpr:steps2000000000 /constexpr:depth1024 /arch:AVX) # I'll assume everybody has this since this is 2025. endif() -# --- AddressSanitizer for Debug builds --- - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - include(CheckCXXCompilerFlag) - include(CheckCXXSourceCompiles) - - # ---------------------------- - # Sanitizer flags per compiler - # ---------------------------- - if(MSVC) - set(ASAN_FLAG "/fsanitize=address") - set(UBSAN_FLAG "/fsanitize=undefined") - else() - set(ASAN_FLAG "-fsanitize=address") - set(UBSAN_FLAG "-fsanitize=undefined") - endif() - - # ---------------------------- - # Helper function to check a sanitizer - # ---------------------------- - function(check_sanitizer FLAG VAR_NAME) - check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORTS_FLAG) - - if(COMPILER_SUPPORTS_FLAG) - message(STATUS "Compiler supports ${FLAG}") - - # Compile + link test - set(CMAKE_REQUIRED_FLAGS "${FLAG}") - check_cxx_source_compiles(" - int main() { return 0; } - " CAN_LINK) - - if(CAN_LINK) - # Optional runtime check - file(WRITE "${CMAKE_BINARY_DIR}/sanitizer_test.cpp" "int main() { return 0; }") - try_run(RUN_RESULT COMPILE_RESULT - "${CMAKE_BINARY_DIR}" - "${CMAKE_BINARY_DIR}/sanitizer_test.cpp" - CMAKE_FLAGS "-DCMAKE_CXX_FLAGS=${FLAG}" - ) - if(RUN_RESULT EQUAL 0) - message(STATUS "${FLAG} works at runtime") - set(${VAR_NAME} TRUE PARENT_SCOPE) - else() - message(WARNING "${FLAG} compile/link succeeded but runtime test failed") - set(${VAR_NAME} FALSE PARENT_SCOPE) - endif() - else() - message(WARNING "Cannot compile/link with ${FLAG}") - set(${VAR_NAME} FALSE PARENT_SCOPE) - endif() - else() - message(STATUS "Compiler does not support ${FLAG}") - set(${VAR_NAME} FALSE PARENT_SCOPE) - endif() - endfunction() - - # ---------------------------- - # Check ASan - # ---------------------------- - check_sanitizer(${ASAN_FLAG} ENABLE_ASAN) - - # ---------------------------- - # Check UBSan - # ---------------------------- - check_sanitizer(${UBSAN_FLAG} ENABLE_UBSAN) - - # ---------------------------- - # Set CXX flags if supported - # ---------------------------- - if(ENABLE_ASAN) - message(STATUS "Enabling ASan for build") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_FLAG}" CACHE STRING "CXX flags" FORCE) - endif() - - if(ENABLE_UBSAN) - message(STATUS "Enabling UBSan for build") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UBSAN_FLAG}" CACHE STRING "CXX flags" FORCE) - endif() - -endif() add_compile_definitions(GENERATE_AT_RUNTIME) # --- Core Library --- set(SOURCES