From e3881b7cc0f24ceeaecca4e004debcd601a1c09c Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:03:27 +0530 Subject: [PATCH 01/17] ci: complete elite workflow with vcpkg toolchain fix --- .github/workflows/ci.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51c38a2..f79d215 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,10 @@ jobs: run: sudo apt-get update && sudo apt-get install -y ninja-build - name: Configure CMake - run: cmake --preset ${{ matrix.preset }} + # Use env.VCPKG_ROOT to find the toolchain bridge + run: | + cmake --preset ${{ matrix.preset }} \ + -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake - name: Build run: cmake --build --preset ${{ matrix.preset }} --parallel @@ -53,21 +56,27 @@ jobs: name: Analysis (Clang-Tidy & ASan) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Setup vcpkg # Use vcpkg here too for consistency! + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup vcpkg uses: lukka/run-vcpkg@v11 with: vcpkgJsonGlob: 'vcpkg.json' + - name: Install Tools - run: sudo apt-get update && sudo apt-get install -y ninja-build clang clang-tidy - # ... rest of your cmake commands - + run: | + sudo apt-get update + sudo apt-get install -y ninja-build clang clang-tidy + - name: Configure & Build + # Explicitly passing the toolchain here ensures GTest is found for Analysis run: | cmake -B build -G Ninja \ -DCMAKE_CXX_COMPILER=clang++ \ -DENABLE_SANITIZERS=ON \ - -DENABLE_CLANG_TIDY=ON + -DENABLE_CLANG_TIDY=ON \ + -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake cmake --build build --parallel - name: Run Tests From cde9d59620ec18fc124107e6211149f815152b38 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:20:50 +0530 Subject: [PATCH 02/17] fix: update branch references from main to master in CI workflow --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f79d215..2d911fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [main, develop] + branches: [master, develop] pull_request: - branches: [main] + branches: [master] workflow_dispatch: jobs: From 2df5acb11760b8a045c14a97aab2656c40284f91 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:24:00 +0530 Subject: [PATCH 03/17] fix: update CMake configuration to use PowerShell syntax for toolchain file --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d911fb..e359440 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,10 +40,9 @@ jobs: run: sudo apt-get update && sudo apt-get install -y ninja-build - name: Configure CMake - # Use env.VCPKG_ROOT to find the toolchain bridge run: | - cmake --preset ${{ matrix.preset }} \ - -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake + cmake --preset ${{ matrix.preset }} ` + -DCMAKE_TOOLCHAIN_FILE="$($env:VCPKG_ROOT)/scripts/buildsystems/vcpkg.cmake" - name: Build run: cmake --build --preset ${{ matrix.preset }} --parallel From 11ad0e13d0fcc77d76bb96046376ba39577309c6 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:25:03 +0530 Subject: [PATCH 04/17] fix: update CMake configuration to correctly reference VCPKG_TOOLCHAIN_FILE --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e359440..2a0cf13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,13 +69,12 @@ jobs: sudo apt-get install -y ninja-build clang clang-tidy - name: Configure & Build - # Explicitly passing the toolchain here ensures GTest is found for Analysis run: | cmake -B build -G Ninja \ -DCMAKE_CXX_COMPILER=clang++ \ -DENABLE_SANITIZERS=ON \ -DENABLE_CLANG_TIDY=ON \ - -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake + -DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" cmake --build build --parallel - name: Run Tests From 0f7a610d5b5ebf18e4be8bc131581320e36cc318 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:27:01 +0530 Subject: [PATCH 05/17] fix: update CMake configuration to use bash syntax for toolchain file --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a0cf13..b427637 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,8 +40,9 @@ jobs: run: sudo apt-get update && sudo apt-get install -y ninja-build - name: Configure CMake + shell: bash run: | - cmake --preset ${{ matrix.preset }} ` + cmake --preset ${{ matrix.preset }} \ -DCMAKE_TOOLCHAIN_FILE="$($env:VCPKG_ROOT)/scripts/buildsystems/vcpkg.cmake" - name: Build From a07f91b2f7c587e987d2f4214ead499bf088fe34 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:30:12 +0530 Subject: [PATCH 06/17] fix: update CI workflow to use bash shell for build configuration --- .github/workflows/ci.yml | 1 + vcpkg.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b427637..b40be97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,7 @@ jobs: sudo apt-get install -y ninja-build clang clang-tidy - name: Configure & Build + shell: bash run: | cmake -B build -G Ninja \ -DCMAKE_CXX_COMPILER=clang++ \ diff --git a/vcpkg.json b/vcpkg.json index e10d5da..c37e8db 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -4,6 +4,6 @@ "builtin-baseline": "1e199d32ad53aab1defda61ce41c380302e3f95c", "dependencies": [ "gtest", - "google-benchmark" + "benchmark" ] } \ No newline at end of file From 6787db14b88cd389e1c467529db2fd6704ebac9d Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:39:20 +0530 Subject: [PATCH 07/17] fix: update CI workflow to ensure consistent bash shell usage and improve CMake configuration --- .github/workflows/ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b40be97..baf45d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,18 +37,24 @@ jobs: - name: Install Ninja & Tools (Linux) if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y ninja-build + run: | + sudo apt-get update + sudo apt-get install -y ninja-build - name: Configure CMake + # Use bash everywhere to keep variable syntax consistent shell: bash run: | cmake --preset ${{ matrix.preset }} \ - -DCMAKE_TOOLCHAIN_FILE="$($env:VCPKG_ROOT)/scripts/buildsystems/vcpkg.cmake" + -DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" - name: Build + # Adding shell: bash here ensures the environment remains consistent + shell: bash run: cmake --build --preset ${{ matrix.preset }} --parallel - name: Test + shell: bash run: ctest --preset ${{ matrix.preset }} --output-on-failure # --- Code Quality & Sanitizers --- @@ -80,4 +86,5 @@ jobs: cmake --build build --parallel - name: Run Tests + shell: bash run: ctest --test-dir build --output-on-failure \ No newline at end of file From 42506cd42e4b07cd22de615ae151c1a1b9efd9fa Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 22:42:19 +0530 Subject: [PATCH 08/17] fix: include in hello.cpp for string usage --- libs/core/src/hello.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/core/src/hello.cpp b/libs/core/src/hello.cpp index b45d470..53f7f57 100644 --- a/libs/core/src/hello.cpp +++ b/libs/core/src/hello.cpp @@ -1,4 +1,5 @@ #include "core/hello.hpp" +#include namespace core { From a566ceb59034136ec807130ac8336d448b315f52 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 23:02:18 +0530 Subject: [PATCH 09/17] fix: add .clang-tidy configuration and enable clang-tidy in CMakeLists.txt --- .clang-tidy | 23 +++++++++++++++++++++++ CMakeLists.txt | 15 +++++++++++++++ libs/core/include/core/hello.hpp | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..9ad0c78 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,23 @@ +--- +# Enable all checks by default, then disable the annoying ones +Checks: 'bugprone-*, + cppcoreguidelines-*, + modernize-*, + performance-*, + readability-*, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -modernize-use-trailing-return-type' + +# Treat all enabled warnings as errors to keep CI green +WarningsAsErrors: '*' + +# Specific settings for C++23 +CheckOptions: + - key: readability-identifier-naming.NamespaceCase + value: lower_case + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.FunctionCase + value: camelCase +--- \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c11595f..d48ec50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,20 @@ project( LANGUAGES C CXX ) +option(ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy" ON) + +if(ENABLE_CLANG_TIDY) + find_program(CLANG_TIDY_EXE NAMES "clang-tidy") + if(CLANG_TIDY_EXE) + message(STATUS "Clang-Tidy found: ${CLANG_TIDY_EXE}") + # CMake 3.7.2+ automatically looks for a .clang-tidy file in the source tree + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}") + else() + message(AUTHOR_WARNING "Clang-Tidy requested but not found.") + endif() +endif() + + # Set global C++ standard set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -70,4 +84,5 @@ message(STATUS " Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VER message(STATUS " Build Type: ${CMAKE_BUILD_TYPE}") message(STATUS " Benchmarks: ${BUILD_BENCHMARKS}") message(STATUS " Tests: ${BUILD_TESTS}") +message(STATUS " Clang Tidy: ${ENABLE_CLANG_TIDY}") message(STATUS "-----------------------------------------------------------") \ No newline at end of file diff --git a/libs/core/include/core/hello.hpp b/libs/core/include/core/hello.hpp index ea9ba94..e2bf9f7 100644 --- a/libs/core/include/core/hello.hpp +++ b/libs/core/include/core/hello.hpp @@ -4,4 +4,4 @@ namespace core { std::string hello(); -} \ No newline at end of file +} // namespace core \ No newline at end of file From 201032ec82ad86a133fff691c962aca50c53b6ce Mon Sep 17 00:00:00 2001 From: Sagar P Date: Sun, 8 Mar 2026 23:04:38 +0530 Subject: [PATCH 10/17] fix: remove unnecessary newline in .clang-tidy configuration --- .clang-tidy | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9ad0c78..b6d2bb1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,3 @@ ---- # Enable all checks by default, then disable the annoying ones Checks: 'bugprone-*, cppcoreguidelines-*, @@ -19,5 +18,4 @@ CheckOptions: - key: readability-identifier-naming.ClassCase value: CamelCase - key: readability-identifier-naming.FunctionCase - value: camelCase ---- \ No newline at end of file + value: camelCase \ No newline at end of file From 6284823d5ca6aa38313fa2329dc9f8b3b01f68b7 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Mon, 9 Mar 2026 09:40:10 +0530 Subject: [PATCH 11/17] experimental changes --- .clang-format | 22 +++++++++ .clang-tidy | 94 +++++++++++++++++++++++++++++-------- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 30 ++++-------- apps/app/CMakeLists.txt | 9 +++- apps/app/main.cpp | 6 ++- benchmarks/CMakeLists.txt | 2 + cmake/ClangFormat.cmake | 18 +++++++ cmake/ProjectOptions.cmake | 33 +++++++++++++ cmake/ProjectWarnings.cmake | 25 ++++++++++ cmake/Sanitizers.cmake | 25 ++++++---- cmake/StaticAnalyzers.cmake | 25 ++++++---- libs/core/CMakeLists.txt | 15 +++++- libs/core/src/hello.cpp | 10 ++-- tests/CMakeLists.txt | 6 +-- tests/test_hello.cpp | 5 +- 16 files changed, 253 insertions(+), 74 deletions(-) create mode 100644 .clang-format create mode 100644 cmake/ClangFormat.cmake create mode 100644 cmake/ProjectOptions.cmake create mode 100644 cmake/ProjectWarnings.cmake diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..caf5d52 --- /dev/null +++ b/.clang-format @@ -0,0 +1,22 @@ +BasedOnStyle: LLVM + +IndentWidth: 4 +TabWidth: 4 +UseTab: Never + +ColumnLimit: 100 + +BreakBeforeBraces: Allman + +AllowShortFunctionsOnASingleLine: Empty +AllowShortBlocksOnASingleLine: Never + +NamespaceIndentation: All + +PointerAlignment: Left +ReferenceAlignment: Left + +SpaceBeforeParens: ControlStatements + +SortIncludes: true +IncludeBlocks: Regroup \ No newline at end of file diff --git a/.clang-tidy b/.clang-tidy index b6d2bb1..475130e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,21 +1,75 @@ -# Enable all checks by default, then disable the annoying ones -Checks: 'bugprone-*, - cppcoreguidelines-*, - modernize-*, - performance-*, - readability-*, - -cppcoreguidelines-pro-type-vararg, - -cppcoreguidelines-pro-bounds-array-to-pointer-decay, - -modernize-use-trailing-return-type' - -# Treat all enabled warnings as errors to keep CI green -WarningsAsErrors: '*' - -# Specific settings for C++23 +# .clang-tidy +Checks: > + -*, + + # High-value bug detection + bugprone-*, + clang-analyzer-*, + + # Performance improvements + performance-*, + + # Modern C++ suggestions + modernize-*, + + # Selected core guidelines + cppcoreguidelines-avoid-magic-numbers, + cppcoreguidelines-init-variables, + cppcoreguidelines-narrowing-conversions, + cppcoreguidelines-slicing, + cppcoreguidelines-special-member-functions, + + # Useful readability checks (not noisy ones) + readability-braces-around-statements, + readability-const-return-type, + readability-implicit-bool-conversion, + readability-redundant-control-flow, + readability-simplify-boolean-expr, + + # Disabled noisy checks + -modernize-use-trailing-return-type, + -modernize-use-auto, + -modernize-use-nodiscard, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-type-vararg, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-avoid-c-arrays, + -readability-magic-numbers + +WarningsAsErrors: > + bugprone-*, + clang-analyzer-* + +HeaderFilterRegex: 'src/.*|include/.*' + CheckOptions: - - key: readability-identifier-naming.NamespaceCase - value: lower_case - - key: readability-identifier-naming.ClassCase - value: CamelCase - - key: readability-identifier-naming.FunctionCase - value: camelCase \ No newline at end of file + + # Identifier naming + - key: readability-identifier-naming.NamespaceCase + value: lower_case + + - key: readability-identifier-naming.ClassCase + value: CamelCase + + - key: readability-identifier-naming.StructCase + value: CamelCase + + - key: readability-identifier-naming.FunctionCase + value: lower_case + + - key: readability-identifier-naming.MethodCase + value: lower_case + + - key: readability-identifier-naming.VariableCase + value: lower_case + + - key: readability-identifier-naming.PrivateMemberSuffix + value: _ + + # Magic numbers ignored in common cases + - key: readability-magic-numbers.IgnoredIntegerValues + value: '0;1;2;-1' + + # Allow short functions to skip braces rule + - key: readability-braces-around-statements.ShortStatementLines + value: '1' \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index baf45d4..92d4f21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,7 +81,7 @@ jobs: cmake -B build -G Ninja \ -DCMAKE_CXX_COMPILER=clang++ \ -DENABLE_SANITIZERS=ON \ - -DENABLE_CLANG_TIDY=ON \ + -DENABLE_CLANG_TIDY=OFF \ -DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" cmake --build build --parallel diff --git a/CMakeLists.txt b/CMakeLists.txt index d48ec50..c24a747 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,20 +13,6 @@ project( LANGUAGES C CXX ) -option(ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy" ON) - -if(ENABLE_CLANG_TIDY) - find_program(CLANG_TIDY_EXE NAMES "clang-tidy") - if(CLANG_TIDY_EXE) - message(STATUS "Clang-Tidy found: ${CLANG_TIDY_EXE}") - # CMake 3.7.2+ automatically looks for a .clang-tidy file in the source tree - set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}") - else() - message(AUTHOR_WARNING "Clang-Tidy requested but not found.") - endif() -endif() - - # Set global C++ standard set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -38,17 +24,21 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # ----------------------------------------------------------------------------- # 2. Global Options & Modules # ----------------------------------------------------------------------------- -option(BUILD_BENCHMARKS "Build performance benchmarks" OFF) -option(BUILD_TESTS "Build unit tests" ON) -option(BUILD_SHARED_LIBS "Build libraries as shared" OFF) +# option(BUILD_BENCHMARKS "Build performance benchmarks" OFF) +# option(BUILD_TESTS "Build unit tests" ON) +# option(BUILD_SHARED_LIBS "Build libraries as shared" OFF) +# option(ENABLE_CLANG_TIDY "Enable clang-tidy static analysis" ON) # Extend module path to find custom scripts in /cmake list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Include Professional Tooling Modules -include(CompilerWarnings) # Sets strict warnings per compiler -include(Sanitizers) # Configures ASan/UBSan -include(StaticAnalyzers) # Configures Clang-Tidy/IWYU +include(ProjectOptions) # Global options and feature toggles +include(ProjectWarnings) # Sets strict warnings per compiler +#include(CompilerWarnings) # Sets strict warnings per compiler +include(StaticAnalyzers) # Configures Clang-Tidy/IWYU +include(Sanitizers) # Configures ASan/UBSan +include(ClangFormat) # Configures clang-format targets # ----------------------------------------------------------------------------- # 3. Target Orchestration diff --git a/apps/app/CMakeLists.txt b/apps/app/CMakeLists.txt index 82d534b..8472812 100644 --- a/apps/app/CMakeLists.txt +++ b/apps/app/CMakeLists.txt @@ -8,8 +8,15 @@ add_executable(${APP_TARGET} main.cpp) target_link_libraries(${APP_TARGET} PRIVATE ${PROJECT_NAME}::Core + project_options + project_warnings + project_sanitizers ) +if(COMMAND enable_clang_tidy) + enable_clang_tidy(${MY_LIB_NAME}) +endif() + # 4. Enforce the "Flat Binary" Output Contract set_target_properties(${APP_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" @@ -20,4 +27,4 @@ set_target_properties(${APP_TARGET} PROPERTIES ) # 5. Apply your template's strict warning configuration -set_project_warnings(${APP_TARGET}) \ No newline at end of file +#set_project_warnings(${APP_TARGET}) \ No newline at end of file diff --git a/apps/app/main.cpp b/apps/app/main.cpp index f37a4da..4037b7c 100644 --- a/apps/app/main.cpp +++ b/apps/app/main.cpp @@ -1,7 +1,9 @@ -#include #include "core/hello.hpp" +#include int main() { - std::cout << core::hello() << std::endl; + std::cout << core::hello() << '\n'; + return 0; + } \ No newline at end of file diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 11c5a35..b568b23 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -10,6 +10,8 @@ add_executable(${BENCH_TARGET} bench_hello.cpp) target_link_libraries(${BENCH_TARGET} PRIVATE ${PROJECT_NAME}::Core # Use the Alias for consistency + project_options + project_warnings benchmark::benchmark ) diff --git a/cmake/ClangFormat.cmake b/cmake/ClangFormat.cmake new file mode 100644 index 0000000..74b38cf --- /dev/null +++ b/cmake/ClangFormat.cmake @@ -0,0 +1,18 @@ +include_guard(GLOBAL) + +find_program(CLANG_FORMAT_EXE NAMES clang-format) + +if(CLANG_FORMAT_EXE) + +file(GLOB_RECURSE ALL_SOURCE_FILES + ${PROJECT_SOURCE_DIR}/src/*.cpp + ${PROJECT_SOURCE_DIR}/include/*.hpp +) + +add_custom_target(format + COMMAND ${CLANG_FORMAT_EXE} + -i + ${ALL_SOURCE_FILES} +) + +endif() \ No newline at end of file diff --git a/cmake/ProjectOptions.cmake b/cmake/ProjectOptions.cmake new file mode 100644 index 0000000..469d56e --- /dev/null +++ b/cmake/ProjectOptions.cmake @@ -0,0 +1,33 @@ +include_guard(GLOBAL) + +option(BUILD_BENCHMARKS "Build performance benchmarks" OFF) +option(BUILD_TESTS "Build unit tests" ON) +option(BUILD_SHARED_LIBS "Build libraries as shared" OFF) +option(ENABLE_CLANG_TIDY "Enable clang-tidy static analysis" ON) +option(ENABLE_IPO "Enable Interprocedural Optimization" ON) +option(ENABLE_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) +option(ENABLE_SANITIZERS "Enable sanitizers" OFF) + +add_library(project_options INTERFACE) + +# Require modern C++ +target_compile_features(project_options INTERFACE cxx_std_20) + +# LTO / IPO +include(CheckIPOSupported) + +if(ENABLE_IPO) + check_ipo_supported(RESULT ipo_supported OUTPUT error) + + if(ipo_supported) + set_property(TARGET project_options PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() +endif() + +# warnings as errors +if(ENABLE_WARNINGS_AS_ERRORS) + target_compile_options(project_options INTERFACE + $<$:-Werror> + $<$:/WX> + ) +endif() \ No newline at end of file diff --git a/cmake/ProjectWarnings.cmake b/cmake/ProjectWarnings.cmake new file mode 100644 index 0000000..8b2bcb4 --- /dev/null +++ b/cmake/ProjectWarnings.cmake @@ -0,0 +1,25 @@ +include_guard(GLOBAL) + +add_library(project_warnings INTERFACE) + +target_compile_options(project_warnings INTERFACE + $<$: + -Wall + -Wextra + -Wpedantic + -Wconversion + -Wshadow + > + + $<$: + -Wall + -Wextra + -Wpedantic + -Wconversion + -Wshadow + > + + $<$: + /W4 + > +) \ No newline at end of file diff --git a/cmake/Sanitizers.cmake b/cmake/Sanitizers.cmake index 749f85c..8192545 100644 --- a/cmake/Sanitizers.cmake +++ b/cmake/Sanitizers.cmake @@ -1,15 +1,20 @@ -option(ENABLE_SANITIZERS "Enable sanitizers" OFF) +include_guard(GLOBAL) -if(ENABLE_SANITIZERS AND NOT MSVC) +add_library(project_sanitizers INTERFACE) -add_compile_options( - -fsanitize=address - -fsanitize=undefined -) +option(ENABLE_ADDRESS_SANITIZER "Enable ASan" OFF) +option(ENABLE_UNDEFINED_SANITIZER "Enable UBSan" OFF) -add_link_options( - -fsanitize=address - -fsanitize=undefined -) +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") + + if(ENABLE_ADDRESS_SANITIZER) + target_compile_options(project_sanitizers INTERFACE -fsanitize=address) + target_link_options(project_sanitizers INTERFACE -fsanitize=address) + endif() + + if(ENABLE_UNDEFINED_SANITIZER) + target_compile_options(project_sanitizers INTERFACE -fsanitize=undefined) + target_link_options(project_sanitizers INTERFACE -fsanitize=undefined) + endif() endif() \ No newline at end of file diff --git a/cmake/StaticAnalyzers.cmake b/cmake/StaticAnalyzers.cmake index 3c7ee27..2031903 100644 --- a/cmake/StaticAnalyzers.cmake +++ b/cmake/StaticAnalyzers.cmake @@ -1,11 +1,20 @@ -option(ENABLE_CLANG_TIDY "Enable clang-tidy" OFF) +include_guard(GLOBAL) -if(ENABLE_CLANG_TIDY) +#option(ENABLE_CLANG_TIDY "Enable clang-tidy" OFF) -set(CMAKE_CXX_CLANG_TIDY - clang-tidy; - -checks=*; - -warnings-as-errors=* -) +function(enable_clang_tidy target) -endif() \ No newline at end of file + if(NOT ENABLE_CLANG_TIDY) + return() + endif() + + find_program(CLANG_TIDY_EXE NAMES clang-tidy) + + if(CLANG_TIDY_EXE) + set_target_properties(${target} PROPERTIES + CXX_CLANG_TIDY + "${CLANG_TIDY_EXE};-checks=*;-warnings-as-errors=*" + ) + endif() + +endfunction() \ No newline at end of file diff --git a/libs/core/CMakeLists.txt b/libs/core/CMakeLists.txt index c37b818..5cc6c77 100644 --- a/libs/core/CMakeLists.txt +++ b/libs/core/CMakeLists.txt @@ -2,6 +2,19 @@ add_library(${MY_LIB_NAME} src/hello.cpp) add_library(${PROJECT_NAME}::Core ALIAS ${MY_LIB_NAME}) +# --- Link to Global Options, Warnings, and Sanitizers --- +target_link_libraries(${MY_LIB_NAME} + PRIVATE + project_options + project_warnings + project_sanitizers +) + +# --- Clang-Tidy Integration --- +if(COMMAND enable_clang_tidy) + enable_clang_tidy(${MY_LIB_NAME}) +endif() + # --- Include Directories --- target_include_directories(${MY_LIB_NAME} PUBLIC @@ -11,4 +24,4 @@ target_include_directories(${MY_LIB_NAME} # --- Compiler Tooling --- # Assuming your include(CompilerWarnings) defines this function -set_project_warnings(${MY_LIB_NAME}) \ No newline at end of file +#set_project_warnings(${MY_LIB_NAME}) \ No newline at end of file diff --git a/libs/core/src/hello.cpp b/libs/core/src/hello.cpp index 53f7f57..cd24b98 100644 --- a/libs/core/src/hello.cpp +++ b/libs/core/src/hello.cpp @@ -1,12 +1,10 @@ -#include "core/hello.hpp" +#include #include -namespace core -{ +namespace core { -std::string hello() -{ +std::string hello() { return "Hello from core library"; } -} \ No newline at end of file +} // namespace core \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d479740..429b8ef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,9 @@ add_executable(${TEST_TARGET} test_hello.cpp) target_link_libraries(${TEST_TARGET} PRIVATE ${PROJECT_NAME}::Core # <--- Project-agnostic Alias + project_options + project_warnings + project_sanitizers GTest::gtest_main ) @@ -32,6 +35,3 @@ gtest_discover_tests(${TEST_TARGET} ENVIRONMENT "PATH=$;$ENV{PATH}" EXTRA_ARGS --gtest_color=yes ) - -# 6. Apply Template Warnings -set_project_warnings(${TEST_TARGET}) \ No newline at end of file diff --git a/tests/test_hello.cpp b/tests/test_hello.cpp index 22fb402..a99f5b6 100644 --- a/tests/test_hello.cpp +++ b/tests/test_hello.cpp @@ -1,7 +1,8 @@ -#include #include "core/hello.hpp" +#include +#include TEST(CoreTest, Hello) { - EXPECT_EQ(core::hello(), "Hello from core library"); + EXPECT_EQ(core::hello(), std::string("Hello from core library")); } \ No newline at end of file From 438d456dd3acd3cfdf106b484cde523379990091 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Mon, 9 Mar 2026 10:57:09 +0530 Subject: [PATCH 12/17] fix: update CMake configuration for C++20, enable auto-formatting, and adjust build scripts --- CMakeLists.txt | 5 ++--- CMakePresets.json | 2 +- apps/app/CMakeLists.txt | 7 ++++++- benchmarks/CMakeLists.txt | 7 ++++++- cmake/ClangFormat.cmake | 26 ++++++++++++++++++++++++-- cmake/ProjectOptions.cmake | 9 ++++++--- cmake/Sanitizers.cmake | 12 ++++++++++-- cmake/StaticAnalyzers.cmake | 2 +- libs/core/CMakeLists.txt | 5 +++++ scripts/build.bat | 9 ++++++++- scripts/build.sh | 3 ++- scripts/build_all.bat | 10 ++++++++-- scripts/build_all.sh | 5 ++++- tests/CMakeLists.txt | 5 +++++ 14 files changed, 88 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c24a747..d3efe7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,12 @@ set(MY_LIB_NAME "${MY_PROJECT_NAME}Core") project( ${MY_PROJECT_NAME} VERSION 1.0.0 - DESCRIPTION "Universal C++23 Template" + DESCRIPTION "Universal C++20 Template" LANGUAGES C CXX ) # Set global C++ standard -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -35,7 +35,6 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") # Include Professional Tooling Modules include(ProjectOptions) # Global options and feature toggles include(ProjectWarnings) # Sets strict warnings per compiler -#include(CompilerWarnings) # Sets strict warnings per compiler include(StaticAnalyzers) # Configures Clang-Tidy/IWYU include(Sanitizers) # Configures ASan/UBSan include(ClangFormat) # Configures clang-format targets diff --git a/CMakePresets.json b/CMakePresets.json index c02c0cb..0488347 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -26,7 +26,7 @@ "name": "msvc-base", "displayName": "MSVC", "hidden": true, - "generator": "Visual Studio 18 2026", + "generator": "Visual Studio 17 2022", "inherits": "vcpkg-base", "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" }, diff --git a/apps/app/CMakeLists.txt b/apps/app/CMakeLists.txt index 8472812..82bf005 100644 --- a/apps/app/CMakeLists.txt +++ b/apps/app/CMakeLists.txt @@ -26,5 +26,10 @@ set_target_properties(${APP_TARGET} PROPERTIES OUTPUT_NAME "app" ) -# 5. Apply your template's strict warning configuration +# 5. Auto-format before build (if enabled) +if(DEFINED AUTO_FORMAT_DEP) + add_dependencies(${APP_TARGET} ${AUTO_FORMAT_DEP}) +endif() + +# 6. Apply your template's strict warning configuration #set_project_warnings(${APP_TARGET}) \ No newline at end of file diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index b568b23..5023c83 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -22,4 +22,9 @@ set_target_properties(${BENCH_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin" OUTPUT_NAME "bench" -) \ No newline at end of file +) + +# 5. Auto-format before build (if enabled) +if(DEFINED AUTO_FORMAT_DEP) + add_dependencies(${BENCH_TARGET} ${AUTO_FORMAT_DEP}) +endif() \ No newline at end of file diff --git a/cmake/ClangFormat.cmake b/cmake/ClangFormat.cmake index 74b38cf..9305684 100644 --- a/cmake/ClangFormat.cmake +++ b/cmake/ClangFormat.cmake @@ -1,18 +1,40 @@ include_guard(GLOBAL) +option(ENABLE_AUTO_FORMAT "Run clang-format automatically before build" OFF) + find_program(CLANG_FORMAT_EXE NAMES clang-format) if(CLANG_FORMAT_EXE) file(GLOB_RECURSE ALL_SOURCE_FILES - ${PROJECT_SOURCE_DIR}/src/*.cpp - ${PROJECT_SOURCE_DIR}/include/*.hpp + ${PROJECT_SOURCE_DIR}/libs/**/*.cpp + ${PROJECT_SOURCE_DIR}/libs/**/*.hpp + ${PROJECT_SOURCE_DIR}/apps/**/*.cpp + ${PROJECT_SOURCE_DIR}/apps/**/*.hpp + ${PROJECT_SOURCE_DIR}/tests/**/*.cpp + ${PROJECT_SOURCE_DIR}/tests/**/*.hpp + ${PROJECT_SOURCE_DIR}/benchmarks/**/*.cpp ) add_custom_target(format COMMAND ${CLANG_FORMAT_EXE} -i ${ALL_SOURCE_FILES} + COMMENT "Formatting source files with clang-format" ) +# Auto-format before build if enabled +# This sets a variable that subdirectories can use to add dependencies +if(ENABLE_AUTO_FORMAT AND CLANG_FORMAT_EXE) + # Create format-all target that depends on format + add_custom_target(format-all + COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target format + COMMENT "Running clang-format before build..." + ) + add_dependencies(format-all format) + + set(AUTO_FORMAT_DEP "format-all") + message(STATUS "Auto-format enabled: clang-format will run before build") +endif() + endif() \ No newline at end of file diff --git a/cmake/ProjectOptions.cmake b/cmake/ProjectOptions.cmake index 469d56e..a790bf1 100644 --- a/cmake/ProjectOptions.cmake +++ b/cmake/ProjectOptions.cmake @@ -3,16 +3,19 @@ include_guard(GLOBAL) option(BUILD_BENCHMARKS "Build performance benchmarks" OFF) option(BUILD_TESTS "Build unit tests" ON) option(BUILD_SHARED_LIBS "Build libraries as shared" OFF) -option(ENABLE_CLANG_TIDY "Enable clang-tidy static analysis" ON) -option(ENABLE_IPO "Enable Interprocedural Optimization" ON) +option(ENABLE_CLANG_TIDY "Enable clang-tidy static analysis" OFF) +option(ENABLE_IPO "Enable Interprocedural Optimization (LTO)" OFF) option(ENABLE_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) -option(ENABLE_SANITIZERS "Enable sanitizers" OFF) +option(ENABLE_SANITIZERS "Enable sanitizers (ASan/UBSan)" OFF) add_library(project_options INTERFACE) # Require modern C++ target_compile_features(project_options INTERFACE cxx_std_20) +# Allow users to opt-in to C++23 features if desired +# target_compile_features(project_options INTERFACE cxx_std_23) + # LTO / IPO include(CheckIPOSupported) diff --git a/cmake/Sanitizers.cmake b/cmake/Sanitizers.cmake index 8192545..f7e99bd 100644 --- a/cmake/Sanitizers.cmake +++ b/cmake/Sanitizers.cmake @@ -2,9 +2,10 @@ include_guard(GLOBAL) add_library(project_sanitizers INTERFACE) -option(ENABLE_ADDRESS_SANITIZER "Enable ASan" OFF) -option(ENABLE_UNDEFINED_SANITIZER "Enable UBSan" OFF) +option(ENABLE_ADDRESS_SANITIZER "Enable AddressSanitizer (ASan)" OFF) +option(ENABLE_UNDEFINED_SANITIZER "Enable UndefinedBehaviorSanitizer (UBSan)" OFF) +# Sanitizers only work on Clang/GCC, not MSVC if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") if(ENABLE_ADDRESS_SANITIZER) @@ -17,4 +18,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") target_link_options(project_sanitizers INTERFACE -fsanitize=undefined) endif() +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # MSVC has no built-in sanitizer support via command line + # Use /fsanitize=address with Clang-CL or external tools + if(ENABLE_ADDRESS_SANITIZER OR ENABLE_UNDEFINED_SANITIZER) + message(STATUS "Sanitizers not supported on MSVC. Use Clang-CL or external tooling.") + endif() + endif() \ No newline at end of file diff --git a/cmake/StaticAnalyzers.cmake b/cmake/StaticAnalyzers.cmake index 2031903..c0ae29d 100644 --- a/cmake/StaticAnalyzers.cmake +++ b/cmake/StaticAnalyzers.cmake @@ -1,6 +1,6 @@ include_guard(GLOBAL) -#option(ENABLE_CLANG_TIDY "Enable clang-tidy" OFF) +# Note: ENABLE_CLANG_TIDY option is defined in ProjectOptions.cmake function(enable_clang_tidy target) diff --git a/libs/core/CMakeLists.txt b/libs/core/CMakeLists.txt index 5cc6c77..9332c22 100644 --- a/libs/core/CMakeLists.txt +++ b/libs/core/CMakeLists.txt @@ -22,6 +22,11 @@ target_include_directories(${MY_LIB_NAME} $ ) +# --- Auto-format before build (if enabled) --- +if(DEFINED AUTO_FORMAT_DEP) + add_dependencies(${MY_LIB_NAME} ${AUTO_FORMAT_DEP}) +endif() + # --- Compiler Tooling --- # Assuming your include(CompilerWarnings) defines this function #set_project_warnings(${MY_LIB_NAME}) \ No newline at end of file diff --git a/scripts/build.bat b/scripts/build.bat index b4359e2..eb6bfe5 100644 --- a/scripts/build.bat +++ b/scripts/build.bat @@ -8,8 +8,15 @@ if /i "%~2"=="Release" set "CONFIG=Release" set "BASE_PRESET=msvc" if not "%~1"=="" set "BASE_PRESET=%~1" +:: Enable auto-format if requested (3rd argument) +set "AUTO_FORMAT=OFF" +if /i "%~3"=="ON" set "AUTO_FORMAT=ON" + +:: Only msvc and clang-cl are supported in this script (native Windows tools) +:: For mingw presets, use ucrt64 shell environment if /i "%BASE_PRESET%" neq "msvc" if /i "%BASE_PRESET%" neq "clang-cl" ( echo [ERROR] "%BASE_PRESET%" is not a native Windows preset. + echo Use ucrt64 shell for mingw-gcc/mingw-clang presets. exit /b 1 ) @@ -45,7 +52,7 @@ echo [BUILD] %TARGET_PRESET% ^(%CONFIG%^) echo ────────────────────────────────────────────── :: Using the 'Flat Binary' contract for the bench check -cmake --preset "%TARGET_PRESET%" || exit /b !ERRORLEVEL! +cmake --preset "%TARGET_PRESET%" -DENABLE_AUTO_FORMAT=%AUTO_FORMAT% || exit /b !ERRORLEVEL! cmake --build "%BUILD_DIR%" --config %CONFIG% --parallel || exit /b !ERRORLEVEL! ctest --test-dir "%BUILD_DIR%" -C %CONFIG% --output-on-failure diff --git a/scripts/build.sh b/scripts/build.sh index 0ec4003..f06fb61 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -11,6 +11,7 @@ fi BASE_PRESET="${1:-$DEFAULT_PRESET}" CONFIG="${2:-Debug}" +AUTO_FORMAT="${3:-OFF}" # Normalize to lowercase for directory and preset matching CONFIG_LOWER=$(echo "$CONFIG" | tr '[:upper:]' '[:lower:]') @@ -39,7 +40,7 @@ echo "──────────────────────── # 3. Configure echo "[STEP 1/3] Configuring preset: $TARGET_PRESET" -cmake --preset "$TARGET_PRESET" +cmake --preset "$TARGET_PRESET" -DENABLE_AUTO_FORMAT=$AUTO_FORMAT # 4. Build echo "[STEP 2/3] Building $CONFIG..." diff --git a/scripts/build_all.bat b/scripts/build_all.bat index ffd82ea..1fdb839 100644 --- a/scripts/build_all.bat +++ b/scripts/build_all.bat @@ -1,12 +1,18 @@ @echo off setlocal EnableDelayedExpansion -:: 1. Define the Windows Matrix +:: 1. Define the Windows Matrix (native tools only - msvc/clang-cl) +:: For mingw builds, use ucrt64 shell with build.sh set "COMPILERS=msvc clang-cl" set "CONFIGS=Debug Release" +:: Auto-format support (pass as argument, e.g., build_all.bat ON) +set "AUTO_FORMAT=OFF" +if /i "%~1"=="ON" set "AUTO_FORMAT=ON" + echo ================================================= echo [MASTER BUILD] Testing all Windows Configurations +echo [AUTO_FORMAT=%AUTO_FORMAT%] echo ================================================= :: 2. Execution Loop @@ -20,7 +26,7 @@ for %%c in (%COMPILERS%) do ( :: %~dp0 is the directory of THIS script. :: We wrap it in quotes to handle spaces in folder names. if exist "%~dp0build.bat" ( - call "%~dp0build.bat" %%c %%g + call "%~dp0build.bat" %%c %%g %AUTO_FORMAT% ) else ( echo [ERROR] Could not find build.bat in %~dp0 exit /b 1 diff --git a/scripts/build_all.sh b/scripts/build_all.sh index 4674806..74e7ec2 100644 --- a/scripts/build_all.sh +++ b/scripts/build_all.sh @@ -16,6 +16,9 @@ fi # 2. Define the Matrix CONFIGS=("Debug" "Release") +# Auto-format support (pass as argument, e.g., ./build_all.sh ON) +AUTO_FORMAT="${1:-OFF}" + if [ "$IS_MSYS" = true ]; then PRESETS=("mingw-gcc" "mingw-clang") else @@ -36,7 +39,7 @@ for preset in "${PRESETS[@]}"; do echo "⚒️ Building Node: $preset | $config" # Use SCRIPT_DIR to find build.sh reliably - bash "$SCRIPT_DIR/build.sh" "$preset" "$config" + bash "$SCRIPT_DIR/build.sh" "$preset" "$config" "$AUTO_FORMAT" echo "✅ Finished: $preset-$config" done diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 429b8ef..6fb069f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -35,3 +35,8 @@ gtest_discover_tests(${TEST_TARGET} ENVIRONMENT "PATH=$;$ENV{PATH}" EXTRA_ARGS --gtest_color=yes ) + +# 6. Auto-format before build (if enabled) +if(DEFINED AUTO_FORMAT_DEP) + add_dependencies(${TEST_TARGET} ${AUTO_FORMAT_DEP}) +endif() From 539565d332d0710b2c721d06339331c8e48d2bdb Mon Sep 17 00:00:00 2001 From: Sagar P Date: Mon, 9 Mar 2026 18:40:56 +0530 Subject: [PATCH 13/17] fix: update CI workflow to separate build steps for Linux and Windows --- .github/workflows/ci.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92d4f21..8a99871 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,14 +48,21 @@ jobs: cmake --preset ${{ matrix.preset }} \ -DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" - - name: Build - # Adding shell: bash here ensures the environment remains consistent - shell: bash - run: cmake --build --preset ${{ matrix.preset }} --parallel + - name: Build (Linux) + if: runner.os == 'Linux' + run: | + BASE_PRESET=$(echo '${{ matrix.preset }}' | cut -d'-' -f1,2) + CONFIG=$(echo '${{ matrix.preset }}' | cut -d'-' -f3) + ./scripts/build.sh "$BASE_PRESET" "$CONFIG" - - name: Test - shell: bash - run: ctest --preset ${{ matrix.preset }} --output-on-failure + - name: Build (Windows) + if: runner.os == 'Windows' + run: | + for /f "tokens=1,2,3 delims=-" %%a in ("${{ matrix.preset }}") do ( + set "BASE_PRESET=%%a-%%b" + set "CONFIG=%%c" + ) + call scripts\build.bat "%BASE_PRESET%" "%CONFIG%" # --- Code Quality & Sanitizers --- analysis: From 9544ed637feb288522a02c1ace4e6a63deff7f3a Mon Sep 17 00:00:00 2001 From: Sagar P Date: Mon, 9 Mar 2026 18:49:39 +0530 Subject: [PATCH 14/17] fix: ensure consistent shell usage in build steps for Linux and Windows --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a99871..ad505f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,10 +53,11 @@ jobs: run: | BASE_PRESET=$(echo '${{ matrix.preset }}' | cut -d'-' -f1,2) CONFIG=$(echo '${{ matrix.preset }}' | cut -d'-' -f3) - ./scripts/build.sh "$BASE_PRESET" "$CONFIG" + bash ./scripts/build.sh "$BASE_PRESET" "$CONFIG" - name: Build (Windows) if: runner.os == 'Windows' + shell: cmd run: | for /f "tokens=1,2,3 delims=-" %%a in ("${{ matrix.preset }}") do ( set "BASE_PRESET=%%a-%%b" From a7db4b5fdc16f2157c3dc2da41cdbbf1cc92c246 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Mon, 9 Mar 2026 19:19:55 +0530 Subject: [PATCH 15/17] fix: enhance Windows build step to handle different preset configurations --- .github/workflows/ci.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad505f5..9154198 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,11 +59,16 @@ jobs: if: runner.os == 'Windows' shell: cmd run: | + @echo off for /f "tokens=1,2,3 delims=-" %%a in ("${{ matrix.preset }}") do ( - set "BASE_PRESET=%%a-%%b" - set "CONFIG=%%c" + if "%%c"=="" ( + :: Case: msvc-release (2 parts) + call scripts\build.bat %%a %%b + ) else ( + :: Case: clang-cl-release (3 parts) + call scripts\build.bat %%a-%%b %%c + ) ) - call scripts\build.bat "%BASE_PRESET%" "%CONFIG%" # --- Code Quality & Sanitizers --- analysis: From 6e30063857ef3f18e551ade5dcc88ee7a76f575b Mon Sep 17 00:00:00 2001 From: Sagar P Date: Mon, 9 Mar 2026 19:27:22 +0530 Subject: [PATCH 16/17] fix: refine CI workflow by separating Linux and Windows build steps and improving variable handling --- .github/workflows/ci.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9154198..90039bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,14 +35,20 @@ jobs: with: vcpkgJsonGlob: 'vcpkg.json' - - name: Install Ninja & Tools (Linux) + - name: Install Ninja (Linux) if: runner.os == 'Linux' run: | sudo apt-get update sudo apt-get install -y ninja-build + - name: Set up MSVC (Windows) + # This is the critical fix for the link.exe error + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + - name: Configure CMake - # Use bash everywhere to keep variable syntax consistent shell: bash run: | cmake --preset ${{ matrix.preset }} \ @@ -50,9 +56,12 @@ jobs: - name: Build (Linux) if: runner.os == 'Linux' + shell: bash run: | - BASE_PRESET=$(echo '${{ matrix.preset }}' | cut -d'-' -f1,2) - CONFIG=$(echo '${{ matrix.preset }}' | cut -d'-' -f3) + # Split by the last hyphen to handle names like linux-clang-release + PRESET="${{ matrix.preset }}" + BASE_PRESET="${PRESET%-*}" + CONFIG="${PRESET##*-}" bash ./scripts/build.sh "$BASE_PRESET" "$CONFIG" - name: Build (Windows) @@ -62,15 +71,12 @@ jobs: @echo off for /f "tokens=1,2,3 delims=-" %%a in ("${{ matrix.preset }}") do ( if "%%c"=="" ( - :: Case: msvc-release (2 parts) call scripts\build.bat %%a %%b ) else ( - :: Case: clang-cl-release (3 parts) call scripts\build.bat %%a-%%b %%c ) ) - # --- Code Quality & Sanitizers --- analysis: name: Analysis (Clang-Tidy & ASan) runs-on: ubuntu-latest From 1201a1d2b86199a91a69e29ab748e26dc4964595 Mon Sep 17 00:00:00 2001 From: Sagar P Date: Mon, 9 Mar 2026 19:51:54 +0530 Subject: [PATCH 17/17] fix: update CI workflow to correctly set up MSVC and adjust linker settings in CMake presets --- .github/workflows/ci.yml | 13 ++++++------- CMakePresets.json | 32 +++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90039bf..5bf6f9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,12 @@ jobs: with: submodules: true + - name: Set up MSVC (Windows) + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + - name: Setup vcpkg uses: lukka/run-vcpkg@v11 with: @@ -41,13 +47,6 @@ jobs: sudo apt-get update sudo apt-get install -y ninja-build - - name: Set up MSVC (Windows) - # This is the critical fix for the link.exe error - if: runner.os == 'Windows' - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - - name: Configure CMake shell: bash run: | diff --git a/CMakePresets.json b/CMakePresets.json index 0488347..5ce4857 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -39,7 +39,7 @@ "cacheVariables": { "CMAKE_C_COMPILER": "clang-cl", "CMAKE_CXX_COMPILER": "clang-cl", - "CMAKE_LINKER": "link.exe", + "CMAKE_LINKER": "lld-link.exe", "CMAKE_AR": "llvm-lib.exe" }, "environment": { @@ -86,7 +86,10 @@ }, { "name": "msvc-release", - "inherits": ["msvc-base", "benchmark-base"], + "inherits": [ + "msvc-base", + "benchmark-base" + ], "binaryDir": "${sourceDir}/build/msvc/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" @@ -102,7 +105,10 @@ }, { "name": "clang-cl-release", - "inherits": ["clang-cl-base", "benchmark-base"], + "inherits": [ + "clang-cl-base", + "benchmark-base" + ], "binaryDir": "${sourceDir}/build/clang-cl/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" @@ -118,7 +124,10 @@ }, { "name": "mingw-gcc-release", - "inherits": ["mingw-gcc", "benchmark-base"], + "inherits": [ + "mingw-gcc", + "benchmark-base" + ], "binaryDir": "${sourceDir}/build/mingw-gcc/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" @@ -134,7 +143,10 @@ }, { "name": "mingw-clang-release", - "inherits": ["mingw-clang", "benchmark-base"], + "inherits": [ + "mingw-clang", + "benchmark-base" + ], "binaryDir": "${sourceDir}/build/mingw-clang/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" @@ -150,7 +162,10 @@ }, { "name": "linux-gcc-release", - "inherits": ["linux-gcc", "benchmark-base"], + "inherits": [ + "linux-gcc", + "benchmark-base" + ], "binaryDir": "${sourceDir}/build/linux-gcc/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" @@ -166,7 +181,10 @@ }, { "name": "linux-clang-release", - "inherits": ["linux-clang", "benchmark-base"], + "inherits": [ + "linux-clang", + "benchmark-base" + ], "binaryDir": "${sourceDir}/build/linux-clang/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release"