From 119f1b5305a7575f47f058fc4eb448fa47df6831 Mon Sep 17 00:00:00 2001 From: Bruno Alexandre Rosa <1791393+brunoalr@users.noreply.github.com> Date: Mon, 2 Mar 2026 22:37:26 -0300 Subject: [PATCH] use ccache on win --- .ci/compile.sh | 34 ++++++++++----- .github/workflows/desktop-build.yml | 68 ++++++++++------------------- cockatrice/CMakeLists.txt | 1 - oracle/CMakeLists.txt | 1 - servatrice/CMakeLists.txt | 1 - 5 files changed, 47 insertions(+), 58 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 3d9516eee..8ccf5622b 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -12,7 +12,7 @@ # --ccache [] uses ccache and shows stats, optionally provide size # --dir sets the name of the build dir, default is "build" # --target-macos-version sets the min os version - only used for macOS builds -# uses env: BUILDTYPE MAKE_INSTALL MAKE_PACKAGE PACKAGE_TYPE PACKAGE_SUFFIX MAKE_SERVER MAKE_NO_CLIENT MAKE_TEST USE_CCACHE CCACHE_SIZE BUILD_DIR CMAKE_GENERATOR TARGET_MACOS_VERSION +# uses env: BUILDTYPE MAKE_INSTALL MAKE_PACKAGE PACKAGE_TYPE PACKAGE_SUFFIX MAKE_SERVER MAKE_NO_CLIENT MAKE_TEST USE_CCACHE CCACHE_SIZE CCACHE_VARIANT BUILD_DIR CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM TARGET_MACOS_VERSION # (correspond to args: --debug/--release --install --package --suffix --server --test --ccache --dir ) # exitcode: 1 for failure, 3 for invalid arguments @@ -129,9 +129,12 @@ if [[ $MAKE_TEST ]]; then fi if [[ $USE_CCACHE ]]; then flags+=("-DUSE_CCACHE=1") - if [[ $CCACHE_SIZE ]]; then + if [[ $CCACHE_VARIANT ]]; then + flags+=("-DCMAKE_C_COMPILER_LAUNCHER=$CCACHE_VARIANT" "-DCMAKE_CXX_COMPILER_LAUNCHER=$CCACHE_VARIANT") + fi + if [[ $CCACHE_SIZE && "$CCACHE_VARIANT" != "sccache" ]]; then # note, this setting persists after running the script - ccache --max-size "$CCACHE_SIZE" + "${CCACHE_VARIANT:-ccache}" --max-size "$CCACHE_SIZE" fi fi if [[ $PACKAGE_TYPE ]]; then @@ -141,16 +144,28 @@ if [[ $USE_VCPKG ]]; then flags+=("-DUSE_VCPKG=1") fi +cmake_args=() +if [[ $CMAKE_GENERATOR ]]; then + cmake_args+=(-G "$CMAKE_GENERATOR") + if [[ $CMAKE_GENERATOR_PLATFORM ]]; then + cmake_args+=(-A "$CMAKE_GENERATOR_PLATFORM") + fi +fi + # Add cmake --build flags buildflags=(--config "$BUILDTYPE") function ccachestatsverbose() { - # note, verbose only works on newer ccache, discard the error - local got - if got="$(ccache --show-stats --verbose 2>/dev/null)"; then - echo "$got" + local launcher="${CCACHE_VARIANT:-ccache}" + if [[ $launcher == "sccache" ]]; then + sccache -s else - ccache --show-stats + local got + if got="$("$launcher" --show-stats --verbose 2>/dev/null)"; then + echo "$got" + else + "$launcher" --show-stats + fi fi } @@ -229,7 +244,6 @@ if [[ $RUNNER_OS == macOS ]]; then elif [[ $RUNNER_OS == Windows ]] && [[ "$CMAKE_GENERATOR" != *Ninja* ]]; then # Enable MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ - # and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true) fi @@ -242,7 +256,7 @@ fi echo "::group::Configure cmake" cmake --version echo "Running cmake with flags: ${flags[*]}" -cmake .. "${flags[@]}" +cmake "${cmake_args[@]}" .. "${flags[@]}" echo "::endgroup::" echo "::group::Build project" diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index 827be92ae..0a21d3bea 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -264,7 +264,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - use_ccache: 1 + ccache_variant: ccache - os: macOS target: 14 @@ -279,7 +279,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - use_ccache: 1 + ccache_variant: ccache - os: macOS target: 15 @@ -294,7 +294,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - use_ccache: 1 + ccache_variant: ccache - os: macOS target: 15 @@ -306,7 +306,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - use_ccache: 1 + ccache_variant: ccache - os: Windows target: 10 @@ -319,43 +319,28 @@ jobs: qt_arch: win64_msvc2022_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja + ccache_variant: sccache name: ${{matrix.os}} ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} needs: configure runs-on: ${{matrix.runner}} - env: - CCACHE_DIR: ${{github.workspace}}/.cache/ - # Cache size over the entire repo is 10Gi: - # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy - CCACHE_SIZE: 500M - steps: - name: Checkout uses: actions/checkout@v6 with: submodules: recursive - # Ninja+MSVC requires developer environment; setup-msbuild does not add cl.exe - - name: Setup MSVC developer environment + - name: Setup ${{ matrix.ccache_variant }} + uses: hendrikmuhs/ccache-action@v1.2.20 + with: + key: ${{ matrix.runner }}-${{ matrix.soc || 'Windows' }}-${{ matrix.type }}-${{ github.ref_name }} + restore-keys: ${{ matrix.runner }}-${{ matrix.soc || 'Windows' }}-${{ matrix.type }}-master + max-size: 500M + variant: ${{ matrix.ccache_variant }} + + - name: Setup MSVC (Windows) if: matrix.os == 'Windows' - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x64 - - - name: Setup ccache - if: matrix.use_ccache == 1 && matrix.os == 'macOS' - run: brew install ccache - - - name: Restore compiler cache (ccache) - if: matrix.use_ccache == 1 - id: ccache_restore - uses: actions/cache/restore@v5 - env: - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - with: - path: ${{env.CCACHE_DIR}} - key: ccache-${{matrix.runner}}-${{matrix.soc}}-${{matrix.type}}-${{env.BRANCH_NAME}} - restore-keys: ccache-${{matrix.runner}}-${{matrix.soc}}-${{matrix.type}}- + uses: ilammy/msvc-dev-cmd@v1.13.0 - name: Install aqtinstall if: matrix.os == 'macOS' @@ -423,13 +408,15 @@ jobs: # uses environment variables, see compile.sh for more details - name: Build Cockatrice id: build + shell: bash env: BUILDTYPE: '${{matrix.type}}' MAKE_PACKAGE: '${{matrix.make_package}}' PACKAGE_SUFFIX: '${{matrix.package_suffix}}' CMAKE_GENERATOR: ${{matrix.cmake_generator}} - CMAKE_GENERATOR_PLATFORM: ${{matrix.cmake_generator_platform}} - USE_CCACHE: ${{matrix.use_ccache}} + CMAKE_GENERATOR_PLATFORM: ${{ matrix.cmake_generator_platform || '' }} + USE_CCACHE: 1 + CCACHE_VARIANT: ${{ matrix.ccache_variant }} VCPKG_DISABLE_METRICS: 1 VCPKG_BINARY_SOURCES: 'clear;files,${{ steps.vcpkg-cache.outputs.path }},readwrite' MACOS_CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }} @@ -438,16 +425,7 @@ jobs: MACOS_CI_KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }} DEVELOPER_DIR: '/Applications/Xcode_${{matrix.xcode}}.app/Contents/Developer' TARGET_MACOS_VERSION: ${{ matrix.override_target }} - run: bash .ci/compile.sh --server --test --vcpkg - - - name: Save compiler cache (ccache) - if: github.ref == 'refs/heads/master' && matrix.use_ccache == 1 - uses: actions/cache/save@v5 - env: - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - with: - path: ${{env.CCACHE_DIR}} - key: ccache-${{matrix.runner}}-${{matrix.soc}}-${{matrix.type}}-${{env.BRANCH_NAME}} + run: .ci/compile.sh --server --test --vcpkg --ccache 500M - name: Sign app bundle if: matrix.os == 'macOS' && matrix.make_package && (github.ref == 'refs/heads/master' || needs.configure.outputs.tag != null) @@ -508,9 +486,9 @@ jobs: with: name: Windows${{matrix.target}}-PDBs path: | - build/cockatrice/*.pdb - build/oracle/*.pdb - build/servatrice/*.pdb + build/cockatrice/**/*.pdb + build/oracle/**/*.pdb + build/servatrice/**/*.pdb if-no-files-found: error - name: Upload to release diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index aae82c2d2..4533448f5 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -527,7 +527,6 @@ if(WIN32) set(plugin_dest_dir Plugins) set(qtconf_dest_dir .) - # Use target runtime dir for both multi-config (VS) and single-config (Ninja) install( DIRECTORY "$/" DESTINATION ./ diff --git a/oracle/CMakeLists.txt b/oracle/CMakeLists.txt index 486b31175..eeacaee76 100644 --- a/oracle/CMakeLists.txt +++ b/oracle/CMakeLists.txt @@ -233,7 +233,6 @@ if(WIN32) set(qtconf_dest_dir .) list(APPEND libSearchDirs ${QT_LIBRARY_DIR}) - # Use target runtime dir for both multi-config (VS) and single-config (Ninja) install( DIRECTORY "$/" DESTINATION ./ diff --git a/servatrice/CMakeLists.txt b/servatrice/CMakeLists.txt index 083166e7d..98290803a 100644 --- a/servatrice/CMakeLists.txt +++ b/servatrice/CMakeLists.txt @@ -183,7 +183,6 @@ if(WIN32) set(plugin_dest_dir Plugins) set(qtconf_dest_dir .) - # Use target runtime dir for both multi-config (VS) and single-config (Ninja) install( DIRECTORY "$/" DESTINATION ./