From b637962da0ca08764c3855796428f6377294e4f6 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Sat, 20 Jun 2026 12:15:34 +0800 Subject: [PATCH] [Chore] (ci): cache native builds --- .github/workflows/apk.yml | 45 +++++++++++++++++++++++++++++++-- .github/workflows/test.yml | 44 +++++++++++++++++++++++++++++--- android-plugin/app/build.gradle | 8 ++++++ android-plugin/build.gradle | 8 ++++++ 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/.github/workflows/apk.yml b/.github/workflows/apk.yml index 14106c9e..153127c1 100644 --- a/.github/workflows/apk.yml +++ b/.github/workflows/apk.yml @@ -11,6 +11,12 @@ on: jobs: build: runs-on: ubuntu-latest + env: + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_COMPILERCHECK: content + CCACHE_DIR: ${{ github.workspace }}/.ccache/android + CCACHE_MAXSIZE: 4G + CCACHE_NOHASHDIR: true steps: - name: Checkout repo @@ -37,6 +43,27 @@ jobs: - name: Setup Android SDK uses: android-actions/setup-android@v3 + - name: Restore Android native SDK packages + uses: actions/cache@v4 + with: + path: | + /usr/local/lib/android/sdk/ndk/27.3.13750724 + /usr/local/lib/android/sdk/cmake/3.22.1 + key: ${{ runner.os }}-android-native-sdk-ndk-27.3.13750724-cmake-3.22.1 + + - name: Install ccache + run: | + sudo apt-get update + sudo apt-get install -y ccache + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache/android + key: ${{ runner.os }}-apk-ccache-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-apk-ccache- + - name: Install Android NDK run: | sdkmanager "ndk;27.3.13750724" @@ -47,14 +74,20 @@ jobs: run: python update_glslang_sources.py - name: Build plugin APKs - run: gradle --no-daemon -p android-plugin :app:assembleEsprytPluginRelease :app:assembleMagmaPluginRelease -Pmobilegl.logLevel=MOBILEGL_LOG_LEVEL_INFO --parallel --max-workers "$(nproc)" + run: | + ccache --zero-stats + gradle --no-daemon -p android-plugin :app:assembleEsprytPluginRelease :app:assembleMagmaPluginRelease -Pmobilegl.cmakeCompilerLauncher=ccache -Pmobilegl.logLevel=MOBILEGL_LOG_LEVEL_INFO --parallel --max-workers "$(nproc)" + ccache --show-stats env: SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} - name: Build retrace APKs - run: gradle --no-daemon -p android-plugin :app:assembleEsprytTraceRelease :app:assembleMagmaTraceRelease -Pmobilegl.abis=all -Pmobilegl.debuggableRelease=true -Pmobilegl.logLevel=MOBILEGL_LOG_LEVEL_INFO --parallel --max-workers "$(nproc)" + run: | + ccache --zero-stats + gradle --no-daemon -p android-plugin :app:assembleEsprytTraceRelease :app:assembleMagmaTraceRelease -Pmobilegl.cmakeCompilerLauncher=ccache -Pmobilegl.abis=all -Pmobilegl.debuggableRelease=true -Pmobilegl.logLevel=MOBILEGL_LOG_LEVEL_INFO --parallel --max-workers "$(nproc)" + ccache --show-stats env: SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} @@ -380,6 +413,14 @@ jobs: - name: Setup Android SDK uses: android-actions/setup-android@v3 + - name: Restore Android emulator SDK packages + uses: actions/cache@v4 + with: + path: | + /usr/local/lib/android/sdk/platforms/android-35 + /usr/local/lib/android/sdk/system-images/android-35/google_apis/x86_64 + key: ${{ runner.os }}-android-emulator-sdk-api35-google-apis-x86-64 + - name: Download retrace APKs uses: actions/download-artifact@v4 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e794997..e8cd4f95 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_COMPILERCHECK: content + CCACHE_DIR: ${{ github.workspace }}/.ccache/build-linux + CCACHE_MAXSIZE: 2G + CCACHE_NOHASHDIR: true steps: - name: Set Swap Space @@ -42,7 +47,15 @@ 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 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 ccache + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache/build-linux + key: ${{ runner.os }}-test-build-linux-ccache-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-test-build-linux-ccache- - name: Show installed toolchain run: | @@ -62,6 +75,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 \ @@ -72,7 +87,10 @@ jobs: -DCMAKE_POLICY_VERSION_MINIMUM=3.5 - name: Build - run: cmake --build "${BUILD_DIR}" --parallel "$(nproc)" + run: | + ccache --zero-stats + cmake --build "${BUILD_DIR}" --parallel "$(nproc)" + ccache --show-stats - name: Package Linux runtime run: | @@ -194,6 +212,11 @@ jobs: env: BUILD_DIR: build-retrace MOBILEGL_LIBRARY: ${{ github.workspace }}/build-linux/libMobileGL.so + CCACHE_BASEDIR: ${{ github.workspace }} + CCACHE_COMPILERCHECK: content + CCACHE_DIR: ${{ github.workspace }}/.ccache/build-retrace + CCACHE_MAXSIZE: 2G + CCACHE_NOHASHDIR: true steps: - name: Set Swap Space @@ -224,7 +247,15 @@ 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 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 ccache + + - name: Restore ccache + uses: actions/cache@v4 + with: + path: .ccache/build-retrace + key: ${{ runner.os }}-test-build-retrace-ccache-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-test-build-retrace-ccache- - name: Show installed toolchain run: | @@ -255,6 +286,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 \ @@ -264,7 +297,10 @@ jobs: -DCMAKE_POLICY_VERSION_MINIMUM=3.5 - name: Build trace replay - run: cmake --build "${BUILD_DIR}" --target mobilegl_trace_replay --parallel "$(nproc)" + run: | + ccache --zero-stats + cmake --build "${BUILD_DIR}" --target mobilegl_trace_replay --parallel "$(nproc)" + ccache --show-stats - name: Normalize CTest command paths run: | diff --git a/android-plugin/app/build.gradle b/android-plugin/app/build.gradle index 36e40a0e..1e743016 100644 --- a/android-plugin/app/build.gradle +++ b/android-plugin/app/build.gradle @@ -28,6 +28,9 @@ def mobileGlAbiFilters = { .collect { it.trim() } .findAll { !it.isEmpty() } } +def mobileGlCmakeCompilerLauncher = { + (findProperty('mobilegl.cmakeCompilerLauncher') ?: System.getenv('MOBILEGL_CMAKE_COMPILER_LAUNCHER') ?: '') as String +} android { namespace 'top.mobilegl.plugin' @@ -112,6 +115,11 @@ android { cmake { path file('src/trace/cpp/CMakeLists.txt') version '3.22.1' + def compilerLauncher = mobileGlCmakeCompilerLauncher() + if (!compilerLauncher.isEmpty()) { + arguments "-DCMAKE_C_COMPILER_LAUNCHER=${compilerLauncher}", + "-DCMAKE_CXX_COMPILER_LAUNCHER=${compilerLauncher}" + } } } diff --git a/android-plugin/build.gradle b/android-plugin/build.gradle index ccbd920e..78220eef 100644 --- a/android-plugin/build.gradle +++ b/android-plugin/build.gradle @@ -17,6 +17,9 @@ def mobileGlAbiFilters = { 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') ?: '') as String +} subprojects { subproject -> subproject.plugins.withId('com.android.library') { @@ -30,6 +33,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()}" } }