diff --git a/.ci/compile.sh b/.ci/compile.sh index 3fdd7b839..da32b6810 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 CCACHE_VARIANT BUILD_DIR CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM 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 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 @@ -128,15 +128,10 @@ if [[ $MAKE_TEST ]]; then flags+=("-DTEST=1") fi if [[ $USE_CCACHE ]]; then - if [[ $CCACHE_VARIANT ]]; then - # COMPILER_LAUNCHER only; USE_CCACHE=OFF prevents RULE_LAUNCH_COMPILE (avoids Strawberry ccache on Windows) - flags+=("-DUSE_CCACHE=OFF" "-DCMAKE_C_COMPILER_LAUNCHER=$CCACHE_VARIANT" "-DCMAKE_CXX_COMPILER_LAUNCHER=$CCACHE_VARIANT") - else - flags+=("-DUSE_CCACHE=1") - fi - if [[ $CCACHE_SIZE && "$CCACHE_VARIANT" != "sccache" ]]; then + flags+=("-DUSE_CCACHE=1") + if [[ $CCACHE_SIZE ]]; then # note, this setting persists after running the script - "${CCACHE_VARIANT:-ccache}" --max-size "$CCACHE_SIZE" + ccache --max-size "$CCACHE_SIZE" fi fi if [[ $PACKAGE_TYPE ]]; then @@ -158,16 +153,12 @@ fi buildflags=(--config "$BUILDTYPE") function ccachestatsverbose() { - local launcher="${CCACHE_VARIANT:-ccache}" - if [[ $launcher == "sccache" ]]; then - sccache -s + # note, verbose only works on newer ccache, discard the error + local got + if got="$(ccache --show-stats --verbose 2>/dev/null)"; then + echo "$got" else - local got - if got="$("$launcher" --show-stats --verbose 2>/dev/null)"; then - echo "$got" - else - "$launcher" --show-stats - fi + ccache --show-stats fi } diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index cb6f3d7b6..539c38f09 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -268,7 +268,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - ccache_variant: ccache + use_ccache: 1 - os: macOS target: 14 @@ -282,7 +282,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - ccache_variant: ccache + use_ccache: 1 - os: macOS target: 15 @@ -296,7 +296,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - ccache_variant: ccache + use_ccache: 1 - os: macOS target: 15 @@ -308,7 +308,7 @@ jobs: qt_arch: clang_64 qt_modules: qtimageformats qtmultimedia qtwebsockets cmake_generator: Ninja - ccache_variant: ccache + use_ccache: 1 - os: Windows target: 10 @@ -320,14 +320,14 @@ 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/ - SCCACHE_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: @@ -336,23 +336,20 @@ jobs: with: submodules: recursive + - 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: ${{ github.workspace }}/.cache/ - key: ${{ matrix.ccache_variant }}-${{ matrix.runner }}-${{ matrix.soc || 'Windows' }}-${{ matrix.type }}-master - restore-keys: | - ${{ matrix.ccache_variant }}-${{ matrix.runner }}-${{ matrix.soc || 'Windows' }}-${{ matrix.type }}-master- - - - name: Setup ${{ matrix.ccache_variant }} - uses: hendrikmuhs/ccache-action@v1.2.20 - with: - key: ${{ matrix.runner }}-${{ matrix.soc || 'Windows' }}-${{ matrix.type }}-master - restore-keys: ${{ matrix.runner }}-${{ matrix.soc || 'Windows' }}-${{ matrix.type }}-master- - max-size: 500M - variant: ${{ matrix.ccache_variant }} - save: false + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ matrix.runner }}-${{ matrix.soc }}-${{ matrix.type }}-${{ env.BRANCH_NAME }} + restore-keys: ccache-${{ matrix.runner }}-${{ matrix.soc }}-${{ matrix.type }}- - name: Setup MSVC (Windows) if: matrix.os == 'Windows' @@ -431,8 +428,7 @@ jobs: PACKAGE_SUFFIX: '${{matrix.package_suffix}}' CMAKE_GENERATOR: ${{matrix.cmake_generator}} CMAKE_GENERATOR_PLATFORM: ${{ matrix.cmake_generator_platform || '' }} - USE_CCACHE: 1 - CCACHE_VARIANT: ${{ matrix.ccache_variant }} + USE_CCACHE: ${{ matrix.use_ccache }} VCPKG_DISABLE_METRICS: 1 VCPKG_BINARY_SOURCES: 'clear;files,${{ steps.vcpkg-cache.outputs.path }},readwrite' MACOS_CERTIFICATE: ${{ secrets.PROD_MACOS_CERTIFICATE }} @@ -445,17 +441,19 @@ jobs: # Delete used cache to emulate a cache update. See https://github.com/actions/cache/issues/342. - name: Delete old compiler cache (ccache) - if: github.ref == 'refs/heads/master' && steps.ccache_restore.outputs.cache-hit && steps.build.outcome == 'success' + if: github.ref == 'refs/heads/master' && matrix.use_ccache == 1 && steps.ccache_restore.outputs.cache-hit && steps.build.outcome == 'success' env: GH_TOKEN: ${{ github.token }} run: gh cache delete --repo ${{ github.repository }} ${{ steps.ccache_restore.outputs.cache-primary-key }} - name: Save compiler cache (ccache) - if: github.ref == 'refs/heads/master' && steps.build.outcome == 'success' + 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: ${{ github.workspace }}/.cache/ - key: ${{ steps.ccache_restore.outputs.cache-primary-key }} + path: ${{ env.CCACHE_DIR }} + key: ccache-${{ matrix.runner }}-${{ matrix.soc }}-${{ matrix.type }}-${{ env.BRANCH_NAME }} - name: Sign app bundle if: matrix.os == 'macOS' && matrix.make_package && needs.configure.outputs.tag != null diff --git a/CMakeLists.txt b/CMakeLists.txt index c838cd05d..50ed9727a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,15 +140,9 @@ endif() # Define proper compilation flags if(MSVC) - # /Z7 when using compiler launcher (sccache): avoids C1041 PDB lock with parallel cached compiles - # /Zi /FS otherwise for Ninja + /MP parallel builds - if(CMAKE_CXX_COMPILER_LAUNCHER) - set(_msvc_debug_format " /Z7") - else() - set(_msvc_debug_format " /Zi /FS") - endif() # Disable Warning C4251, C++20 compatibility, Multi-threaded Builds, Warn Detection, Unwind Semantics, Debug Symbols - set(CMAKE_CXX_FLAGS "/wd4251 /Zc:__cplusplus /std:c++20 /permissive- /W4 /MP /EHsc${_msvc_debug_format}") + # /Zi /FS for Ninja + /MP parallel builds (FS allows multiple cl.exe to write PDB) + set(CMAKE_CXX_FLAGS "/wd4251 /Zc:__cplusplus /std:c++20 /permissive- /W4 /MP /EHsc /Zi /FS") # Visual Studio: Maximum Optimization, Multi-threaded DLL set(CMAKE_CXX_FLAGS_RELEASE "/Ox /MD") # Visual Studio: No Optimization, Multi-threaded Debug DLL