From b87b6981486aba5739648f1ee7a61f04f123a731 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 22 Jun 2026 09:23:58 +0800 Subject: [PATCH] [Fix] (ci): cache native compilation --- .github/workflows/apk.yml | 26 +++++++++++++++++++ .github/workflows/test.yml | 46 +++++++++++++++++++++++++++++++-- android-plugin/app/build.gradle | 12 +++++++++ android-plugin/build.gradle | 9 +++++++ 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/.github/workflows/apk.yml b/.github/workflows/apk.yml index 640610be..cc4d1b95 100644 --- a/.github/workflows/apk.yml +++ b/.github/workflows/apk.yml @@ -11,6 +11,13 @@ on: jobs: build: runs-on: ubuntu-latest + env: + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_COMPRESS: "true" + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 4G + CCACHE_NOHASHDIR: "true" + MOBILEGL_CMAKE_COMPILER_LAUNCHER: ccache steps: - name: Checkout repo @@ -34,6 +41,21 @@ jobs: with: gradle-version: 8.10.2 + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-apk-${{ github.job }}-ccache-${{ github.ref_name }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-apk-${{ github.job }}-ccache-${{ github.ref_name }}- + ${{ runner.os }}-apk-${{ github.job }}-ccache- + + - name: Install ccache + run: | + sudo apt-get update + sudo apt-get install -y ccache + ccache --version + - name: Setup Android SDK uses: android-actions/setup-android@v3 @@ -60,6 +82,10 @@ jobs: SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} + - name: Show ccache stats + if: always() + run: ccache --show-stats + - name: Verify signed APKs run: | APKSIGNER="$(find "$ANDROID_HOME/build-tools" -name apksigner -type f | sort -V | tail -n 1)" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9405f302..a45fe04a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,11 @@ jobs: runs-on: ubuntu-latest env: BUILD_DIR: build-linux + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_COMPRESS: "true" + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 4G + CCACHE_NOHASHDIR: "true" steps: - name: Set Swap Space @@ -28,6 +33,15 @@ jobs: - name: Get CMake uses: lukka/get-cmake@latest + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-test-${{ github.job }}-ccache-${{ github.ref_name }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-test-${{ github.job }}-ccache-${{ github.ref_name }}- + ${{ runner.os }}-test-${{ github.job }}-ccache- + - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@v1.2.1 with: @@ -42,10 +56,11 @@ jobs: - name: Install build dependencies run: | sudo apt-get update - sudo apt-get install -y clang-20 clang++-20 lld-20 libc++-20-dev libc++abi-20-dev libvulkan-dev libegl1-mesa-dev libgles2-mesa-dev libgl1-mesa-dri mesa-vulkan-drivers ninja-build + sudo apt-get install -y ccache clang-20 clang++-20 lld-20 libc++-20-dev libc++abi-20-dev libvulkan-dev libegl1-mesa-dev libgles2-mesa-dev libgl1-mesa-dri mesa-vulkan-drivers ninja-build - name: Show installed toolchain run: | + ccache --version clang-20 --version clang++-20 --version ld.lld-20 --version || ld.lld --version || true @@ -62,6 +77,8 @@ jobs: cmake -S . -B "${BUILD_DIR}" -G Ninja \ -DCMAKE_C_COMPILER=clang-20 \ -DCMAKE_CXX_COMPILER=clang++-20 \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ -DMOBILEGL_LOG_ACTIVE_LEVEL=MOBILEGL_LOG_LEVEL_INFO \ -DMOBILEGL_BUILD_TEST=ON \ @@ -74,6 +91,10 @@ jobs: - name: Build run: cmake --build "${BUILD_DIR}" --parallel "$(nproc)" + - name: Show ccache stats + if: always() + run: ccache --show-stats + - name: Package Linux runtime run: | mkdir -p ci-artifacts @@ -193,6 +214,11 @@ jobs: needs: build-linux env: BUILD_DIR: build-retrace + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_COMPRESS: "true" + CCACHE_DIR: ${{ github.workspace }}/.ccache + CCACHE_MAXSIZE: 4G + CCACHE_NOHASHDIR: "true" MOBILEGL_LIBRARY: ${{ github.workspace }}/build-linux/libMobileGL.so steps: @@ -210,6 +236,15 @@ jobs: - name: Get CMake uses: lukka/get-cmake@latest + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache + key: ${{ runner.os }}-test-${{ github.job }}-ccache-${{ github.ref_name }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-test-${{ github.job }}-ccache-${{ github.ref_name }}- + ${{ runner.os }}-test-${{ github.job }}-ccache- + - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@v1.2.1 with: @@ -224,10 +259,11 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y clang-20 clang++-20 lld-20 libc++-20-dev libc++abi-20-dev libvulkan-dev libegl1-mesa-dev libgles2-mesa-dev libgl1-mesa-dri mesa-vulkan-drivers ninja-build + sudo apt-get install -y ccache clang-20 clang++-20 lld-20 libc++-20-dev libc++abi-20-dev libvulkan-dev libegl1-mesa-dev libgles2-mesa-dev libgl1-mesa-dri mesa-vulkan-drivers ninja-build - name: Show installed toolchain run: | + ccache --version clang-20 --version clang++-20 --version ld.lld-20 --version || ld.lld --version || true @@ -255,6 +291,8 @@ jobs: cmake -S . -B "${BUILD_DIR}" -G Ninja \ -DCMAKE_C_COMPILER=clang-20 \ -DCMAKE_CXX_COMPILER=clang++-20 \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ -DMOBILEGL_LOG_ACTIVE_LEVEL=MOBILEGL_LOG_LEVEL_INFO \ -DMOBILEGL_BUILD_TEST=OFF \ @@ -266,6 +304,10 @@ jobs: - name: Build trace replay run: cmake --build "${BUILD_DIR}" --target mobilegl_trace_replay --parallel "$(nproc)" + - name: Show ccache stats + if: always() + run: ccache --show-stats + - name: Normalize CTest command paths run: | python - <<'PY' diff --git a/android-plugin/app/build.gradle b/android-plugin/app/build.gradle index 36e40a0e..47aad93d 100644 --- a/android-plugin/app/build.gradle +++ b/android-plugin/app/build.gradle @@ -18,6 +18,9 @@ def releaseSigningReady = signingStoreFile.exists() && signingKeyAlias && signingKeyPassword def debuggableRelease = (findProperty('mobilegl.debuggableRelease') ?: 'false').toString().toBoolean() +def mobileGlCmakeCompilerLauncher = { + (findProperty('mobilegl.cmakeCompilerLauncher') ?: System.getenv('MOBILEGL_CMAKE_COMPILER_LAUNCHER') ?: '').toString().trim() +} def mobileGlAbiFilters = { def abiList = (findProperty('mobilegl.abis') ?: System.getenv('MOBILEGL_ABIS') ?: 'arm64-v8a') as String if (abiList.equalsIgnoreCase('all')) { @@ -46,6 +49,15 @@ android { abiFilters(*abiFiltersOverride) } } + externalNativeBuild { + cmake { + def compilerLauncher = mobileGlCmakeCompilerLauncher() + if (!compilerLauncher.isEmpty()) { + arguments "-DCMAKE_C_COMPILER_LAUNCHER=${compilerLauncher}", + "-DCMAKE_CXX_COMPILER_LAUNCHER=${compilerLauncher}" + } + } + } } flavorDimensions 'backend', 'profile' diff --git a/android-plugin/build.gradle b/android-plugin/build.gradle index ccbd920e..7be78098 100644 --- a/android-plugin/build.gradle +++ b/android-plugin/build.gradle @@ -18,6 +18,10 @@ def mobileGlLogActiveLevel = { (rootProject.findProperty('mobilegl.logLevel') ?: System.getenv('MOBILEGL_LOG_ACTIVE_LEVEL') ?: 'MOBILEGL_LOG_LEVEL_INFO') as String } +def mobileGlCmakeCompilerLauncher = { + (rootProject.findProperty('mobilegl.cmakeCompilerLauncher') ?: System.getenv('MOBILEGL_CMAKE_COMPILER_LAUNCHER') ?: '').toString().trim() +} + subprojects { subproject -> subproject.plugins.withId('com.android.library') { subproject.android { @@ -30,6 +34,11 @@ subprojects { subproject -> } externalNativeBuild { cmake { + def compilerLauncher = mobileGlCmakeCompilerLauncher() + if (!compilerLauncher.isEmpty()) { + arguments "-DCMAKE_C_COMPILER_LAUNCHER=${compilerLauncher}", + "-DCMAKE_CXX_COMPILER_LAUNCHER=${compilerLauncher}" + } cppFlags "-DMOBILEGL_LOG_ACTIVE_LEVEL=${mobileGlLogActiveLevel()}" } }