From e236ed93c32b10ae83f754e2edc9addc6867368c Mon Sep 17 00:00:00 2001 From: scawful Date: Tue, 14 Oct 2025 13:24:44 -0400 Subject: [PATCH] refactor(ci): enhance caching and dependency management in workflows - Added caching for ccache and CMake dependencies in CI and release workflows to improve build performance. - Updated installation commands to include ccache across Linux, macOS, and Windows environments. - Enhanced CMake configuration steps to utilize ccache for faster builds and added statistics reporting. Benefits: - Reduces build times and improves efficiency in CI processes, facilitating quicker feedback and integration. --- .github/workflows/ci.yml | 51 +++++++++++++++++++++++---- .github/workflows/release.yml | 62 ++++++++++++++++++++++++++++----- cmake/utils.cmake | 1 - src/app/core/core_library.cmake | 2 +- src/app/net/net_library.cmake | 2 +- src/cli/agent.cmake | 2 +- src/cli/z3ed.cmake | 2 +- test/CMakeLists.txt | 4 ++- 8 files changed, 105 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8ce2d6e..b3bc1dc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -248,6 +248,24 @@ jobs: Write-Host "VCPKG_ROOT: $env:VCPKG_ROOT" Write-Host "Workspace: ${{ github.workspace }}" + - name: Restore ccache + uses: actions/cache@v4 + with: + path: ~/.ccache + key: ccache-${{ runner.os }}-${{ matrix.cc }}-${{ hashFiles('CMakeLists.txt', 'src/**', 'test/**', 'cmake/**') }} + restore-keys: | + ccache-${{ runner.os }}-${{ matrix.cc }}- + + - name: Restore CMake dependencies + uses: actions/cache@v4 + with: + path: | + build/_deps + build/vcpkg_installed + key: cmake-deps-${{ runner.os }}-${{ matrix.cc }}-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'src/**/CMakeLists.txt', 'test/CMakeLists.txt') }} + restore-keys: | + cmake-deps-${{ runner.os }}-${{ matrix.cc }}- + - name: Install Dependencies id: deps shell: bash @@ -256,7 +274,7 @@ jobs: if [[ "${{ runner.os }}" == "Linux" ]]; then sudo apt-get update sudo apt-get install -y \ - build-essential ninja-build pkg-config \ + build-essential ninja-build pkg-config ccache \ libglew-dev libxext-dev libwavpack-dev libboost-all-dev \ libpng-dev python3-dev libpython3-dev \ libasound2-dev libpulse-dev libaudio-dev \ @@ -266,10 +284,10 @@ jobs: ${{ matrix.cc }} ${{ matrix.cxx }} # Note: libabsl-dev removed - gRPC uses bundled Abseil via FetchContent when enabled elif [[ "${{ runner.os }}" == "macOS" ]]; then - brew install ninja pkg-config + brew install ninja pkg-config ccache elif [[ "${{ runner.os }}" == "Windows" ]]; then # Install NASM for BoringSSL (required by gRPC) - choco install nasm -y + choco install nasm ccache -y # Add NASM to PATH for this session echo "C:\Program Files\NASM" >> $GITHUB_PATH fi @@ -283,7 +301,7 @@ jobs: sudo apt-get clean sudo apt-get update --fix-missing sudo apt-get install -y \ - build-essential ninja-build pkg-config \ + build-essential ninja-build pkg-config ccache \ libglew-dev libxext-dev libwavpack-dev libboost-all-dev \ libpng-dev python3-dev libpython3-dev \ libasound2-dev libpulse-dev libaudio-dev \ @@ -293,9 +311,9 @@ jobs: ${{ matrix.cc }} ${{ matrix.cxx }} elif [[ "${{ runner.os }}" == "macOS" ]]; then brew update - brew install ninja pkg-config + brew install ninja pkg-config ccache elif [[ "${{ runner.os }}" == "Windows" ]]; then - choco install nasm -y --force + choco install nasm ccache -y --force echo "C:\Program Files\NASM" >> $GITHUB_PATH fi @@ -360,8 +378,13 @@ jobs: shell: pwsh env: VCPKG_DEFAULT_TRIPLET: x64-windows-static + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_DIR: $HOME/.ccache run: | Write-Host "::group::CMake Configuration (Windows)" -ForegroundColor Cyan + if (Get-Command ccache -ErrorAction SilentlyContinue) { + ccache --zero-stats + } if (-not $env:CMAKE_TOOLCHAIN_FILE -or -not (Test-Path $env:CMAKE_TOOLCHAIN_FILE)) { Write-Host "::error::CMAKE_TOOLCHAIN_FILE environment variable missing or invalid: '$env:CMAKE_TOOLCHAIN_FILE'" exit 1 @@ -384,7 +407,7 @@ jobs: $linker = $env:MSVC_LINK_PATH } Write-Host "Using linker: $linker" - + cmake -B build -G "Ninja" ` -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} ` -DCMAKE_C_COMPILER=${{ matrix.cc }} ` @@ -411,6 +434,9 @@ jobs: } Write-Host "::endgroup::" + if (Get-Command ccache -ErrorAction SilentlyContinue) { + ccache --show-stats + } - name: Configure (Unix) if: runner.os != 'Windows' @@ -419,6 +445,11 @@ jobs: run: | set -e echo "::group::CMake Configuration" + if command -v ccache >/dev/null 2>&1; then + export CCACHE_BASEDIR=${GITHUB_WORKSPACE} + export CCACHE_DIR=${HOME}/.ccache + ccache --zero-stats + fi if [[ "${{ runner.os }}" == "Linux" ]]; then # Linux: Use portal backend for file dialogs (more reliable in CI) cmake -B build -G Ninja \ @@ -444,6 +475,9 @@ jobs: -DYAZE_BUILD_TOOLS=ON 2>&1 | tee cmake_config.log fi echo "::endgroup::" + if command -v ccache >/dev/null 2>&1; then + ccache --show-stats + fi # Note: Full-featured build to match release configuration # Note: YAZE_BUILD_EMU=OFF disables standalone emulator executable # but yaze_emulator library is still built for main app/tests @@ -480,6 +514,9 @@ jobs: fi echo "Using $CORES parallel jobs" cmake --build build --parallel $CORES 2>&1 | tee build.log + if command -v ccache >/dev/null 2>&1; then + ccache --show-stats + fi - name: Report Build Failure if: failure() && steps.build.outcome == 'failure' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fff9fd09..11cb1dfb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -318,6 +318,24 @@ jobs: echo "Disk space after cleanup:" df -h + - name: "Restore ccache" + uses: actions/cache@v4 + with: + path: ~/.ccache + key: release-ccache-${{ runner.os }}-${{ matrix.cc || 'default' }}-${{ hashFiles('CMakeLists.txt', 'src/**', 'test/**', 'cmake/**') }} + restore-keys: | + release-ccache-${{ runner.os }}-${{ matrix.cc || 'default' }}- + + - name: "Restore CMake dependencies" + uses: actions/cache@v4 + with: + path: | + build/_deps + build/vcpkg_installed + key: release-cmake-deps-${{ runner.os }}-${{ matrix.cc || 'default' }}-${{ hashFiles('CMakeLists.txt', 'cmake/**', 'src/**/CMakeLists.txt', 'test/CMakeLists.txt') }} + restore-keys: | + release-cmake-deps-${{ runner.os }}-${{ matrix.cc || 'default' }}- + - name: "Install Dependencies" id: deps shell: bash @@ -326,7 +344,7 @@ jobs: if [[ "${{ runner.os }}" == "Linux" ]]; then sudo apt-get update sudo apt-get install -y \ - build-essential ninja-build pkg-config \ + build-essential ninja-build pkg-config ccache \ libglew-dev libxext-dev libwavpack-dev libboost-all-dev \ libpng-dev python3-dev libpython3-dev \ libasound2-dev libpulse-dev libx11-dev libxrandr-dev libxcursor-dev \ @@ -335,10 +353,10 @@ jobs: # Note: Added missing Linux dependencies for full feature support # Note: libabsl-dev removed - gRPC uses bundled Abseil via FetchContent when enabled elif [[ "${{ runner.os }}" == "macOS" ]]; then - brew install ninja cmake pkg-config + brew install ninja cmake pkg-config ccache elif [[ "${{ runner.os }}" == "Windows" ]]; then # Install NASM for BoringSSL (required by gRPC) - choco install nasm -y + choco install nasm ccache -y # Add NASM to PATH for this session echo "C:\Program Files\NASM" >> $GITHUB_PATH fi @@ -352,7 +370,7 @@ jobs: sudo apt-get clean sudo apt-get update --fix-missing sudo apt-get install -y \ - build-essential ninja-build pkg-config \ + build-essential ninja-build pkg-config ccache \ libglew-dev libxext-dev libwavpack-dev libboost-all-dev \ libpng-dev python3-dev libpython3-dev \ libasound2-dev libpulse-dev libx11-dev libxrandr-dev libxcursor-dev \ @@ -360,9 +378,9 @@ jobs: libxss-dev libxxf86vm-dev libxkbcommon-dev libwayland-dev libdecor-0-dev elif [[ "${{ runner.os }}" == "macOS" ]]; then brew update - brew install ninja cmake pkg-config + brew install ninja cmake pkg-config ccache elif [[ "${{ runner.os }}" == "Windows" ]]; then - choco install nasm -y --force + choco install nasm ccache -y --force echo "C:\Program Files\NASM" >> $GITHUB_PATH fi @@ -370,8 +388,14 @@ jobs: if: runner.os == 'Windows' id: configure_windows shell: pwsh + env: + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_DIR: $HOME/.ccache run: | Write-Host "::group::CMake Configuration (Windows)" -ForegroundColor Cyan + if (Get-Command ccache -ErrorAction SilentlyContinue) { + ccache --zero-stats + } if (-not $env:CMAKE_TOOLCHAIN_FILE -or -not (Test-Path $env:CMAKE_TOOLCHAIN_FILE)) { Write-Host "::error::CMAKE_TOOLCHAIN_FILE environment variable missing or invalid: '$env:CMAKE_TOOLCHAIN_FILE'" exit 1 @@ -419,6 +443,9 @@ jobs: } Write-Host "::endgroup::" + if (Get-Command ccache -ErrorAction SilentlyContinue) { + ccache --show-stats + } - name: "Configure (macOS)" if: runner.os == 'macOS' @@ -427,6 +454,11 @@ jobs: run: | set -e echo "::group::CMake Configuration (macOS)" + if command -v ccache >/dev/null 2>&1; then + export CCACHE_BASEDIR=${GITHUB_WORKSPACE} + export CCACHE_DIR=${HOME}/.ccache + ccache --zero-stats + fi cmake -B build -G Ninja \ -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ -DCMAKE_OSX_ARCHITECTURES=${{ matrix.mac_arch }} \ @@ -436,6 +468,9 @@ jobs: -DYAZE_BUILD_TOOLS=ON \ -DYAZE_ENABLE_ROM_TESTS=OFF 2>&1 | tee cmake_config.log echo "::endgroup::" + if command -v ccache >/dev/null 2>&1; then + ccache --show-stats + fi # Note: YAZE_BUILD_EMU=OFF disables standalone emulator executable # but yaze_emulator library is still built for main app # Note: Tests enabled for pre-1.0 releases to catch issues before publishing @@ -447,6 +482,11 @@ jobs: run: | set -e echo "::group::CMake Configuration (Linux)" + if command -v ccache >/dev/null 2>&1; then + export CCACHE_BASEDIR=${GITHUB_WORKSPACE} + export CCACHE_DIR=${HOME}/.ccache + ccache --zero-stats + fi cmake -B build -G Ninja \ -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \ -DYAZE_BUILD_TESTS=ON \ @@ -456,6 +496,9 @@ jobs: -DYAZE_ENABLE_ROM_TESTS=OFF \ -DNFD_PORTAL=ON 2>&1 | tee cmake_config.log echo "::endgroup::" + if command -v ccache >/dev/null 2>&1; then + ccache --show-stats + fi # Note: YAZE_BUILD_EMU=OFF disables standalone emulator executable # but yaze_emulator library is still built for main app # Note: Tests enabled for pre-1.0 releases to catch issues before publishing @@ -494,8 +537,11 @@ jobs: else CORES=2 fi - echo "Using $CORES parallel jobs" - cmake --build build --parallel $CORES 2>&1 | tee build.log + echo "Using $CORES parallel jobs" + cmake --build build --parallel $CORES 2>&1 | tee build.log + if command -v ccache >/dev/null 2>&1; then + ccache --show-stats + fi - name: "Report Build Failure" if: failure() && steps.build.outcome == 'failure' diff --git a/cmake/utils.cmake b/cmake/utils.cmake index e1ef7826..f50baa44 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -45,7 +45,6 @@ function(yaze_add_compiler_flags) /W4 /permissive- /bigobj /utf-8 - /std:c++latest # Required for C++20/23 features like std::span ) target_compile_definitions(yaze_common INTERFACE _CRT_SECURE_NO_WARNINGS diff --git a/src/app/core/core_library.cmake b/src/app/core/core_library.cmake index 9dac977f..c239b459 100644 --- a/src/app/core/core_library.cmake +++ b/src/app/core/core_library.cmake @@ -147,7 +147,7 @@ if(YAZE_WITH_GRPC) ) if(YAZE_PROTOBUF_TARGET) target_link_libraries(yaze_core_lib PUBLIC ${YAZE_PROTOBUF_TARGET}) - if(MSVC) + if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_link_options(yaze_core_lib PUBLIC /WHOLEARCHIVE:$) endif() endif() diff --git a/src/app/net/net_library.cmake b/src/app/net/net_library.cmake index 5af2c1b8..aecc98cd 100644 --- a/src/app/net/net_library.cmake +++ b/src/app/net/net_library.cmake @@ -86,7 +86,7 @@ if(YAZE_WITH_GRPC) ) if(YAZE_PROTOBUF_TARGET) target_link_libraries(yaze_net PUBLIC ${YAZE_PROTOBUF_TARGET}) - if(MSVC) + if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_link_options(yaze_net PUBLIC /WHOLEARCHIVE:$) endif() endif() diff --git a/src/cli/agent.cmake b/src/cli/agent.cmake index 139c95eb..3d6e1714 100644 --- a/src/cli/agent.cmake +++ b/src/cli/agent.cmake @@ -163,7 +163,7 @@ if(YAZE_WITH_GRPC) ) if(YAZE_PROTOBUF_TARGET) target_link_libraries(yaze_agent PUBLIC ${YAZE_PROTOBUF_TARGET}) - if(MSVC) + if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_link_options(yaze_agent PUBLIC /WHOLEARCHIVE:$) endif() endif() diff --git a/src/cli/z3ed.cmake b/src/cli/z3ed.cmake index fb3a30ae..346982fa 100644 --- a/src/cli/z3ed.cmake +++ b/src/cli/z3ed.cmake @@ -42,7 +42,7 @@ if(YAZE_WITH_GRPC) target_link_libraries(z3ed PRIVATE grpc++ grpc++_reflection) if(YAZE_PROTOBUF_TARGET) target_link_libraries(z3ed PRIVATE ${YAZE_PROTOBUF_TARGET}) - if(MSVC) + if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_link_options(z3ed PRIVATE /WHOLEARCHIVE:$) endif() endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e982ef36..54eca127 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -49,7 +49,9 @@ if(YAZE_BUILD_TESTS) target_link_options(${suite_name} PRIVATE /STACK:16777216) # Force whole-archive linking for protobuf to ensure all symbols are included if(YAZE_WITH_GRPC AND YAZE_PROTOBUF_TARGET) - target_link_options(${suite_name} PRIVATE /WHOLEARCHIVE:$) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + target_link_options(${suite_name} PRIVATE /WHOLEARCHIVE:$) + endif() endif() else() target_link_options(${suite_name} PRIVATE -Wl,--stack,16777216)