From e77760f5d55905230f20b3837af170ab920eeffd Mon Sep 17 00:00:00 2001 From: Omar Aglan Date: Thu, 12 Nov 2026 12:46:25 +0300 Subject: [PATCH 1/2] build(ci): Cache MinGW-w64 compilation with ccache --- .github/workflows/ci.yml | 2 +- .github/workflows/reusable-build-mingw.yml | 40 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 206879b7ca6..4890b5ef138 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -203,7 +203,7 @@ jobs: # Runs separately so the build jobs, which also run for pull requests, do not need actions: write. cleanup-ccache: name: Delete Superseded Compiler Caches - needs: [build-generals-vc6, build-generals-win32, build-generalsmd-vc6, build-generalsmd-win32] + needs: [build-generals-vc6, build-generals-win32, build-generalsmd-vc6, build-generalsmd-win32, build-mingw-generals, build-mingw-generalsmd] if: ${{ !cancelled() && github.event_name != 'pull_request' }} runs-on: ubuntu-latest timeout-minutes: 5 diff --git a/.github/workflows/reusable-build-mingw.yml b/.github/workflows/reusable-build-mingw.yml index 2c32a69918e..15dfaabad69 100644 --- a/.github/workflows/reusable-build-mingw.yml +++ b/.github/workflows/reusable-build-mingw.yml @@ -28,7 +28,7 @@ jobs: - name: Install MinGW-w64 Toolchain run: | sudo apt-get update - sudo apt-get install -y mingw-w64 cmake + sudo apt-get install -y mingw-w64 cmake ccache - name: Install Wine and widl run: | @@ -58,9 +58,32 @@ jobs: path: build/${{ inputs.preset }}/_deps key: cmake-deps-mingw-${{ inputs.preset }}-${{ hashFiles('CMakePresets.json','cmake/**/*.cmake','**/CMakeLists.txt') }} + - name: Set Up ccache + id: ccache + run: | + echo "CCACHE_DIR=$RUNNER_TEMP/ccache-cache" >> "$GITHUB_ENV" + # Runner image updates can change timestamps without changing the compiler. + echo "CCACHE_COMPILERCHECK=content" >> "$GITHUB_ENV" + # GCC precompiled headers bypass ccache without this sloppiness. + echo "CCACHE_SLOPPINESS=pch_defines,time_macros" >> "$GITHUB_ENV" + # Bound each game/preset cache to limit storage across the build matrix. + echo "CCACHE_MAXSIZE=500M" >> "$GITHUB_ENV" + echo "toolchain=$(i686-w64-mingw32-g++ -dumpfullversion)" >> "$GITHUB_OUTPUT" + + - name: Restore MinGW-w64 Compilation Cache + id: ccache-restore + uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 + with: + path: ${{ env.CCACHE_DIR }} + key: ccache-v1-${{ runner.os }}-${{ runner.arch }}-${{ inputs.game }}-${{ inputs.preset }}-${{ steps.ccache.outputs.toolchain }}-${{ github.sha }} + restore-keys: | + ccache-v1-${{ runner.os }}-${{ runner.arch }}-${{ inputs.game }}-${{ inputs.preset }}-${{ steps.ccache.outputs.toolchain }}- + - name: Configure ${{ inputs.game }} with CMake (${{ inputs.preset }}) run: | cmake --preset ${{ inputs.preset }} \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DRTS_BUILD_ZEROHOUR=${{ inputs.game == 'GeneralsMD' && 'ON' || 'OFF' }} \ -DRTS_BUILD_GENERALS=${{ inputs.game == 'Generals' && 'ON' || 'OFF' }} \ -DRTS_BUILD_CORE_TOOLS=OFF \ @@ -70,9 +93,24 @@ jobs: -DRTS_BUILD_GENERALS_EXTRAS=OFF \ -DRTS_BUILD_ZEROHOUR_EXTRAS=OFF + - name: Reset ccache Statistics + run: ccache --zero-stats + - name: Build ${{ inputs.game }} (${{ inputs.preset }}) run: cmake --build build/${{ inputs.preset }} --target ${{ inputs.game == 'Generals' && 'g_generals' || 'z_generals' }} -j$(nproc) + - name: Show ccache Statistics + if: ${{ always() }} + run: ccache --show-stats --verbose + + # Pull requests only restore, so caches change only after changes reach main. + - name: Save MinGW-w64 Compilation Cache + if: ${{ github.event_name != 'pull_request' && steps.ccache-restore.outputs.cache-hit != 'true' }} + uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 + with: + path: ${{ env.CCACHE_DIR }} + key: ${{ steps.ccache-restore.outputs.cache-primary-key }} + - name: Collect ${{ inputs.game }} Artifacts run: | ARTIFACTS_DIR="build/${{ inputs.preset }}/${{ inputs.game }}/artifacts" From 5beda9fd896368dc7da465e13648f3e908d9f8ad Mon Sep 17 00:00:00 2001 From: Omar Aglan Date: Mon, 16 Nov 2026 17:58:10 +0300 Subject: [PATCH 2/2] ci(build): Disable precompiled headers instead of relaxing time macro checks in MinGW-w64 ccache builds --- .github/workflows/reusable-build-mingw.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reusable-build-mingw.yml b/.github/workflows/reusable-build-mingw.yml index 15dfaabad69..963a1f8707a 100644 --- a/.github/workflows/reusable-build-mingw.yml +++ b/.github/workflows/reusable-build-mingw.yml @@ -64,8 +64,6 @@ jobs: echo "CCACHE_DIR=$RUNNER_TEMP/ccache-cache" >> "$GITHUB_ENV" # Runner image updates can change timestamps without changing the compiler. echo "CCACHE_COMPILERCHECK=content" >> "$GITHUB_ENV" - # GCC precompiled headers bypass ccache without this sloppiness. - echo "CCACHE_SLOPPINESS=pch_defines,time_macros" >> "$GITHUB_ENV" # Bound each game/preset cache to limit storage across the build matrix. echo "CCACHE_MAXSIZE=500M" >> "$GITHUB_ENV" echo "toolchain=$(i686-w64-mingw32-g++ -dumpfullversion)" >> "$GITHUB_OUTPUT" @@ -81,9 +79,11 @@ jobs: - name: Configure ${{ inputs.game }} with CMake (${{ inputs.preset }}) run: | + # GCC PCH consumers bypass ccache unless time-macro checking is relaxed. cmake --preset ${{ inputs.preset }} \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON \ -DRTS_BUILD_ZEROHOUR=${{ inputs.game == 'GeneralsMD' && 'ON' || 'OFF' }} \ -DRTS_BUILD_GENERALS=${{ inputs.game == 'Generals' && 'ON' || 'OFF' }} \ -DRTS_BUILD_CORE_TOOLS=OFF \