From cf92999f3f9d00ca65c7924fac9d1d0eae49a51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Mon, 20 Apr 2026 21:31:55 +0800 Subject: [PATCH 1/6] ci: add ccache/sccache compilation caching to speed up CI builds - Use hendrikmuhs/ccache-action@v1.2 for Linux/macOS/iOS/Android/clang-tidy (auto-installs ccache, manages cache, sets env vars, shows stats) - Use mozilla-actions/sccache-action@v0.0.9 for Windows (MSVC compatible) - Add CMAKE_C/CXX_COMPILER_LAUNCHER to all CMake build steps - Exclude wheel build and nightly coverage workflows per decision --- .github/workflows/03-macos-linux-build.yml | 15 +++++++++++++-- .github/workflows/04-android-build.yml | 16 ++++------------ .github/workflows/05-windows-build.yml | 19 +++++++++++++++++-- .github/workflows/06-ios-build.yml | 13 +++++++++++-- .github/workflows/clang_tidy.yml | 9 ++++++++- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index 1dd1e45c7..a3c4a874d 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -40,6 +40,11 @@ jobs: with: submodules: recursive + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ${{ inputs.platform }} + - name: Set up Python uses: actions/setup-python@v6 with: @@ -100,6 +105,8 @@ jobs: python -m pip install -v . \ --no-build-isolation \ --config-settings='cmake.define.BUILD_TOOLS="ON"' \ + --config-settings='cmake.define.CMAKE_C_COMPILER_LAUNCHER="ccache"' \ + --config-settings='cmake.define.CMAKE_CXX_COMPILER_LAUNCHER="ccache"' \ ${{ matrix.arch_flag }} shell: bash @@ -119,7 +126,9 @@ jobs: run: | cd "$GITHUB_WORKSPACE/examples/c++" mkdir build && cd build - cmake .. -DCMAKE_BUILD_TYPE=Release + cmake .. -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache make -j $NPROC ./db-example ./core-example @@ -130,7 +139,9 @@ jobs: run: | cd "$GITHUB_WORKSPACE/examples/c" mkdir build && cd build - cmake .. -DCMAKE_BUILD_TYPE=Release + cmake .. -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache make -j $NPROC ./c_api_basic_example ./c_api_collection_schema_example diff --git a/.github/workflows/04-android-build.yml b/.github/workflows/04-android-build.yml index 19a414792..a010bca4c 100644 --- a/.github/workflows/04-android-build.yml +++ b/.github/workflows/04-android-build.yml @@ -25,11 +25,6 @@ jobs: matrix: abi: [x86_64] api: ${{ github.event.inputs.api && fromJSON(format('["{0}"]', github.event.inputs.api)) || fromJSON('["34"]') }} - env: - CCACHE_BASEDIR: ${{ github.workspace }} - CCACHE_NOHASHDIR: '1' - CCACHE_SLOPPINESS: clang_index_store,file_stat_matches,include_file_mtime,locale,time_macros - steps: # ── Environment setup ────────────────────────────────────────────── - name: Checkout @@ -42,15 +37,12 @@ jobs: sudo apt-get update sudo apt-get install -y --no-install-recommends \ cmake ninja-build git ca-certificates python3 \ - build-essential make ccache unzip curl + build-essential make unzip curl - - name: Cache ccache - uses: actions/cache@v5 + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1.2 with: - path: ~/.ccache - key: ${{ runner.os }}-ccache-android-${{ matrix.abi }}-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-ccache-android-${{ matrix.abi }}- + key: android-${{ matrix.abi }} - name: Setup Java 17 uses: actions/setup-java@v5 diff --git a/.github/workflows/05-windows-build.yml b/.github/workflows/05-windows-build.yml index ca0be0c70..56ed37474 100644 --- a/.github/workflows/05-windows-build.yml +++ b/.github/workflows/05-windows-build.yml @@ -20,6 +20,9 @@ jobs: - platform: windows-2022 - platform: windows-2025 + env: + SCCACHE_GHA_ENABLED: 'true' + steps: - name: Show env info run: | @@ -50,6 +53,9 @@ jobs: with: arch: x64 + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.9 + - name: Set up environment variables run: | $nproc = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors @@ -75,7 +81,9 @@ jobs: $env:CMAKE_BUILD_PARALLEL_LEVEL = "$env:NPROC" python -m pip install -v . ` --no-build-isolation ` - --config-settings='cmake.define.BUILD_TOOLS=ON' + --config-settings='cmake.define.BUILD_TOOLS=ON' ` + --config-settings='cmake.define.CMAKE_C_COMPILER_LAUNCHER=sccache' ` + --config-settings='cmake.define.CMAKE_CXX_COMPILER_LAUNCHER=sccache' shell: powershell - name: Run C++ Tests @@ -95,9 +103,16 @@ jobs: cd "$env:GITHUB_WORKSPACE\examples\c++" mkdir build cd build - cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release ` + -DCMAKE_C_COMPILER_LAUNCHER=sccache ` + -DCMAKE_CXX_COMPILER_LAUNCHER=sccache cmake --build . --config Release --parallel $env:NPROC .\db-example.exe .\core-example.exe .\ailego-example.exe + shell: powershell + + - name: Show sccache statistics + if: always() + run: ${env:SCCACHE_PATH} --show-stats shell: powershell \ No newline at end of file diff --git a/.github/workflows/06-ios-build.yml b/.github/workflows/06-ios-build.yml index 26ffbbfc6..bdc652829 100644 --- a/.github/workflows/06-ios-build.yml +++ b/.github/workflows/06-ios-build.yml @@ -31,6 +31,11 @@ jobs: with: submodules: recursive + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ios-${{ matrix.platform }} + - name: Cache host protoc build uses: actions/cache@v5 with: @@ -42,7 +47,9 @@ jobs: - name: Build host protoc run: | if [ ! -f "build_host/bin/protoc" ]; then - cmake -S . -B build_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + cmake -S . -B build_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache cmake --build build_host --target protoc --parallel $(sysctl -n hw.ncpu) else echo "Using cached host protoc" @@ -72,7 +79,9 @@ jobs: -DCMAKE_INSTALL_PREFIX="./install" \ -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build_host/bin/protoc" \ -DIOS=ON \ - -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache cmake --build build_ios_${{ matrix.platform }} --parallel $NPROC diff --git a/.github/workflows/clang_tidy.yml b/.github/workflows/clang_tidy.yml index 49e85eb67..67c63c8ab 100644 --- a/.github/workflows/clang_tidy.yml +++ b/.github/workflows/clang_tidy.yml @@ -29,11 +29,18 @@ jobs: sudo apt-get update sudo apt-get install -y clang-tidy=1:18.0-59~exp2 cmake ninja-build + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: clang-tidy + - name: Configure CMake and export compile commands run: | cmake -S . -B build -G Ninja \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DBUILD_TOOLS=ON + -DBUILD_TOOLS=ON \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: Collect changed C/C++ files id: changed_files From 920a0f3c6642aaaa66192a0fa37a93d306ced3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Tue, 21 Apr 2026 14:35:48 +0800 Subject: [PATCH 2/6] ci: switch MacOS & Linux build from Unix Makefiles to Ninja generator - Replace CMAKE_GENERATOR='Unix Makefiles' with 'Ninja' in pip build - Replace 'make unittest -j' with 'cmake --build --target unittest --parallel' - Add '-G Ninja' to C++ and C example cmake configure steps - Replace 'make -j' with 'cmake --build --parallel' for examples - Aligns with Windows and Android workflows which already use Ninja --- .github/workflows/03-macos-linux-build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index a3c4a874d..24e71ff2d 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -100,7 +100,7 @@ jobs: run: | cd "$GITHUB_WORKSPACE" - CMAKE_GENERATOR="Unix Makefiles" \ + CMAKE_GENERATOR="Ninja" \ CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \ python -m pip install -v . \ --no-build-isolation \ @@ -113,7 +113,7 @@ jobs: - name: Run C++ Tests run: | cd "$GITHUB_WORKSPACE/build" - make unittest -j$NPROC + cmake --build . --target unittest --parallel $NPROC shell: bash - name: Run Python Tests @@ -126,10 +126,10 @@ jobs: run: | cd "$GITHUB_WORKSPACE/examples/c++" mkdir build && cd build - cmake .. -DCMAKE_BUILD_TYPE=Release \ + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - make -j $NPROC + cmake --build . --parallel $NPROC ./db-example ./core-example ./ailego-example @@ -139,10 +139,10 @@ jobs: run: | cd "$GITHUB_WORKSPACE/examples/c" mkdir build && cd build - cmake .. -DCMAKE_BUILD_TYPE=Release \ + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - make -j $NPROC + cmake --build . --parallel $NPROC ./c_api_basic_example ./c_api_collection_schema_example ./c_api_doc_example From 97c23c474883c08ea22bfa98dece47325f76f7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Tue, 21 Apr 2026 15:06:36 +0800 Subject: [PATCH 3/6] ci: enable parallel ctest execution with -j and --timeout - Use CMake ProcessorCount module to detect available CPU cores - Add -j ${NPROC} to ctest command for parallel test execution - Add --timeout 300 to prevent individual tests from hanging CI - Fallback to NPROC=1 when ProcessorCount returns 0 - iOS target unchanged (build-only, no test execution) --- cmake/bazel.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/bazel.cmake b/cmake/bazel.cmake index 262f721b0..b14da80a4 100644 --- a/cmake/bazel.cmake +++ b/cmake/bazel.cmake @@ -312,6 +312,13 @@ endif() # Enable unit testing enable_testing() +# Detect the number of available processors for parallel test execution +include(ProcessorCount) +ProcessorCount(NPROC) +if(NPROC EQUAL 0) + set(NPROC 1) +endif() + # Add unittest target if(NOT TARGET unittest) if(IOS) @@ -320,7 +327,7 @@ if(NOT TARGET unittest) else() add_custom_target( unittest - COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure + COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${NPROC} --timeout 300 --build-config $ ) endif() From 311e8ffac89fa8cbbbf645b2f8462b5cacca6803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Tue, 21 Apr 2026 15:34:19 +0800 Subject: [PATCH 4/6] Revert "ci: enable parallel ctest execution with -j and --timeout" This reverts commit d196dac5f17b1f7cae443360c88bbd8c935dc145. --- cmake/bazel.cmake | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/cmake/bazel.cmake b/cmake/bazel.cmake index b14da80a4..262f721b0 100644 --- a/cmake/bazel.cmake +++ b/cmake/bazel.cmake @@ -312,13 +312,6 @@ endif() # Enable unit testing enable_testing() -# Detect the number of available processors for parallel test execution -include(ProcessorCount) -ProcessorCount(NPROC) -if(NPROC EQUAL 0) - set(NPROC 1) -endif() - # Add unittest target if(NOT TARGET unittest) if(IOS) @@ -327,7 +320,7 @@ if(NOT TARGET unittest) else() add_custom_target( unittest - COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${NPROC} --timeout 300 + COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure --build-config $ ) endif() From 817091792ea2123d88384d3ddd62f81de3dd451c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Tue, 21 Apr 2026 15:56:23 +0800 Subject: [PATCH 5/6] fix(ci): remove sccache from Windows, fix cmake.define quote issues Windows (05-windows-build.yml): - Remove mozilla-actions/sccache-action: sccache incompatible with MSVC /FS flag - Remove SCCACHE_GHA_ENABLED env var - Remove CMAKE_C/CXX_COMPILER_LAUNCHER=sccache from build steps - Remove 'Show sccache statistics' step - MSVC /FS (global PDB concurrency flag) causes fatal C1041 when used with sccache MacOS & Linux (03-macos-linux-build.yml): - Fix cmake.define values: remove extra quotes around 'ccache' and 'ON' - Bare values required: cmake.define.FOO=bar not cmake.define.FOO="bar" --- .github/workflows/03-macos-linux-build.yml | 6 +++--- .github/workflows/05-windows-build.yml | 19 ++----------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index 24e71ff2d..479ba699c 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -104,9 +104,9 @@ jobs: CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \ python -m pip install -v . \ --no-build-isolation \ - --config-settings='cmake.define.BUILD_TOOLS="ON"' \ - --config-settings='cmake.define.CMAKE_C_COMPILER_LAUNCHER="ccache"' \ - --config-settings='cmake.define.CMAKE_CXX_COMPILER_LAUNCHER="ccache"' \ + --config-settings='cmake.define.BUILD_TOOLS=ON' \ + --config-settings='cmake.define.CMAKE_C_COMPILER_LAUNCHER=ccache' \ + --config-settings='cmake.define.CMAKE_CXX_COMPILER_LAUNCHER=ccache' \ ${{ matrix.arch_flag }} shell: bash diff --git a/.github/workflows/05-windows-build.yml b/.github/workflows/05-windows-build.yml index 56ed37474..ca0be0c70 100644 --- a/.github/workflows/05-windows-build.yml +++ b/.github/workflows/05-windows-build.yml @@ -20,9 +20,6 @@ jobs: - platform: windows-2022 - platform: windows-2025 - env: - SCCACHE_GHA_ENABLED: 'true' - steps: - name: Show env info run: | @@ -53,9 +50,6 @@ jobs: with: arch: x64 - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.9 - - name: Set up environment variables run: | $nproc = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors @@ -81,9 +75,7 @@ jobs: $env:CMAKE_BUILD_PARALLEL_LEVEL = "$env:NPROC" python -m pip install -v . ` --no-build-isolation ` - --config-settings='cmake.define.BUILD_TOOLS=ON' ` - --config-settings='cmake.define.CMAKE_C_COMPILER_LAUNCHER=sccache' ` - --config-settings='cmake.define.CMAKE_CXX_COMPILER_LAUNCHER=sccache' + --config-settings='cmake.define.BUILD_TOOLS=ON' shell: powershell - name: Run C++ Tests @@ -103,16 +95,9 @@ jobs: cd "$env:GITHUB_WORKSPACE\examples\c++" mkdir build cd build - cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release ` - -DCMAKE_C_COMPILER_LAUNCHER=sccache ` - -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build . --config Release --parallel $env:NPROC .\db-example.exe .\core-example.exe .\ailego-example.exe - shell: powershell - - - name: Show sccache statistics - if: always() - run: ${env:SCCACHE_PATH} --show-stats shell: powershell \ No newline at end of file From 5fc6ecdff37ed32745223cfc6295ea600e7d1fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E5=BC=8C?= Date: Tue, 21 Apr 2026 21:02:56 +0800 Subject: [PATCH 6/6] feat: cache key with platform and os --- .github/workflows/03-macos-linux-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index 479ba699c..66e814fe0 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -43,7 +43,7 @@ jobs: - name: Setup ccache uses: hendrikmuhs/ccache-action@v1.2 with: - key: ${{ inputs.platform }} + key: ${{ inputs.platform }}-${{ inputs.os }} - name: Set up Python uses: actions/setup-python@v6