Bläddra i källkod

fix(action): streamline ccache setup for Android kernel with improved installation and configuration steps

TheWildJames 4 månader sedan
förälder
incheckning
abb5489ef6
2 ändrade filer med 88 tillägg och 79 borttagningar
  1. 37 24
      .github/actions/build-kernel/action.yml
  2. 51 55
      .github/workflows/build.yml

+ 37 - 24
.github/actions/build-kernel/action.yml

@@ -4,28 +4,41 @@ description: 'Builds kernel using legacy build.sh or Bazel (kleaf)'
 runs:
   using: composite
   steps:
-    - name: 'Build Kernel'
-      shell: bash
-      working-directory: ${{ github.workspace }}/kernel
-      run: |
-        set -euo pipefail
-        if [ -f "build/build.sh" ]; then
-          SKIP_MRPROPER=1 \
-          LTO=thin \
-          #SKIP_VENDOR_BOOT=1 \
-          #SKIP_EXT_MODULES=1 \
-          #SKIP_CP_KERNEL_HDR=1 \
-          GKI_DEFCONFIG_FRAGMENT="$GITHUB_WORKSPACE/wild_gki.fragment" \
-          BUILD_CONFIG=common/build.config.gki.aarch64 \
-          CC="/usr/bin/ccache clang" \
-          #CXX="/usr/bin/ccache clang++" \
-          #HOSTCC="/usr/bin/ccache clang" \
-          #HOSTCXX="/usr/bin/ccache clang++" \
-          #LD="$GITHUB_WORKSPACE/kernel/common/ld-wrapper" \
-          #HOSTLD="$GITHUB_WORKSPACE/kernel/common/ld-wrapper" \
-          build/build.sh -j"$(nproc)"
-        else
-          cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
-          tools/bazel build --config=release --notrim --defconfig_fragment=//common:arch/arm64/configs/wild_gki.fragment --disk_cache=$LDCACHE_DIR --cache_dir=$GITHUB_WORKSPACE/kernel/.cache/bazel //common:kernel_aarch64
-        fi
+  - name: 'Build Kernel'
+    shell: bash
+    working-directory: ${{ github.workspace }}/kernel
+    run: |
+      set -euo pipefail
+
+      # Prepend ccache symlinks directory BEFORE /usr/bin
+      SYMLINK_DIR="/usr/lib/ccache"
+      export PATH="${SYMLINK_DIR}:${PATH}"
+
+      # Use plain clang names, not "/usr/bin/ccache clang"
+      export CC=clang
+      export CXX=clang++
+
+      if [ -f "build/build.sh" ]; then
+        SKIP_MRPROPER=1 \
+        LTO=thin \
+        GKI_DEFCONFIG_FRAGMENT="$GITHUB_WORKSPACE/wild_gki.fragment" \
+        BUILD_CONFIG=common/build.config.gki.aarch64 \
+        CC=clang \
+        CXX=clang++ \
+        CCACHE_DIR="${HOME}/.ccache" \
+        CCACHE_EXEC="${CCACHE_BIN:-/usr/bin/ccache}" \
+        build/build.sh -j"$(nproc)"
+      else
+        cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
+        tools/bazel build \
+          --config=release \
+          --notrim \
+          --defconfig_fragment=//common:arch/arm64/configs/wild_gki.fragment \
+          --disk_cache=$LDCACHE_DIR \
+          --cache_dir=$GITHUB_WORKSPACE/kernel/.cache/bazel \
+          //common:kernel_aarch64
+      fi
+    env:
+      CCACHE_DIR: ${{ env.CCACHE_DIR }}
+      CCACHE_EXEC: /usr/bin/ccache
         

+ 51 - 55
.github/workflows/build.yml

@@ -249,66 +249,62 @@ jobs:
         echo "pre_ld_size=$pre_ld_size" >> $GITHUB_OUTPUT
         echo "pre_ld_files=$pre_ld_files" >> $GITHUB_OUTPUT
 
-    - name: 'Setup ccache and Build Environment'
+    - name: Setup ccache for Android kernel
       shell: bash
       working-directory: ${{ github.workspace }}
       run: |
-        set -euo pipefail
-        
-        # Download and install ccache
-        echo "Installing ccache..."
-        curl -LfsS --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 30 --tcp-fastopen -H "User-Agent: Mozilla/5.0" "https://github.com/WildKernels/kernel_patches/raw/refs/heads/main/ccache/ccache-x86-64" -o ccache || { echo "❌ Failed to download ccache"; exit 1; }
-        sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
-        sudo chmod +x /usr/bin/ccache
-        rm -f ./ccache
-        
-        # Step 1: Verify ccache is installed
-        echo "Verifying ccache installation..."
-        /usr/bin/ccache --version || { echo "❌ ccache not found"; exit 1; }
-        echo "✅ ccache installed at /usr/bin/ccache"
-        
-        # Step 2: Create symlinks directory
-        SYMLINK_DIR="/usr/lib/ccache"
-        echo "Creating symlinks directory: $SYMLINK_DIR"
-        sudo mkdir -p "$SYMLINK_DIR"
-        
-        # Step 3: Create symlinks for compilers (DO USE symlinks, NOT hard links)
-        echo "Creating compiler symlinks..."
-        for compiler in gcc g++ cc c++ clang clang++; do
-          sudo ln -sf /usr/bin/ccache "$SYMLINK_DIR/$compiler" || { echo "❌ Failed to create symlink for $compiler"; exit 1; }
-        done
-        echo "✅ Symlinks created in $SYMLINK_DIR"
-        
-        # Step 4: Prepend symlinks directory to PATH (MUST come before /usr/bin)
-        echo "Prepending $SYMLINK_DIR to PATH..."
-        echo "export PATH=\"$SYMLINK_DIR:\$PATH\"" >> "$GITHUB_ENV"
-        export PATH="$SYMLINK_DIR:$PATH"
-        
-        # Step 5: Verify the setup
-        echo "Verifying compiler masquerading..."
-        which gcc | grep "$SYMLINK_DIR" || { echo "❌ gcc not pointing to ccache symlinks"; exit 1; }
-        which g++ | grep "$SYMLINK_DIR" || { echo "❌ g++ not pointing to ccache symlinks"; exit 1; }
-        echo "✅ gcc and g++ now routed through ccache"
-        
-        # Step 6: Configure ccache (optional - set max size, compression, etc.)
+        set -Eeuo pipefail
+
+        CCACHE_BIN="/usr/bin/ccache"
+        CCACHE_URL="https://github.com/WildKernels/kernel_patches/raw/refs/heads/main/ccache/ccache-x86-64"
+        CCACHE_LINK_DIR="/usr/lib/ccache"
+        CCACHE_DIR="${HOME}/.ccache"
         CCACHE_MAX_SIZE="12G"
-        echo "Setting max cache size to $CCACHE_MAX_SIZE..."
-        sudo ccache -M "$CCACHE_MAX_SIZE" || ccache -M "$CCACHE_MAX_SIZE"
-        
-        # Enable compression (faster cache, slightly slower compilation)
-        ccache --set-config compression=true
-        
-        # Step 7: Show ccache stats setup
-        echo "✅ ccache setup complete!"
-        ccache --show-stats
+
+        echo "== Install ccache =="
+        if ! sudo test -x "${CCACHE_BIN}"; then
+          curl -LfsS \
+            --retry 5 \
+            --retry-delay 5 \
+            --retry-all-errors \
+            --connect-timeout 30 \
+            -H "User-Agent: Mozilla/5.0" \
+            "${CCACHE_URL}" \
+            -o ./ccache
+          sudo install -m 0755 ./ccache "${CCACHE_BIN}"
+          rm -f ./ccache
+        fi
+
+        echo "== Create clang symlinks =="
+        sudo mkdir -p "${CCACHE_LINK_DIR}"
+        for compiler in clang clang++; do
+          sudo ln -sf "${CCACHE_BIN}" "${CCACHE_LINK_DIR}/${compiler}"
+        done
+
+        echo "== Export env =="
+        {
+          echo "CCACHE_DIR=${CCACHE_DIR}"
+          echo "CCACHE_EXEC=${CCACHE_BIN}"
+          echo "CCACHE_BASEDIR=${GITHUB_WORKSPACE}"
+          echo "CCACHE_COMPRESS=true"
+          echo "CCACHE_COMPRESSLEVEL=6"
+          echo "USE_CCACHE=1"
+        } >> "${GITHUB_ENV}"
+
+        mkdir -p "${CCACHE_DIR}"
+
+        echo "== Configure ccache =="
+        "${CCACHE_BIN}" --set-config=cache_dir="${CCACHE_DIR}"
+        "${CCACHE_BIN}" --set-config=base_dir="${GITHUB_WORKSPACE}"
+        "${CCACHE_BIN}" --set-config=compression=true
+        "${CCACHE_BIN}" --set-config=compression_level=6
+        "${CCACHE_BIN}" --max-size="${CCACHE_MAX_SIZE}"
+
+        echo "== Show ccache config =="
+        "${CCACHE_BIN}" --show-config || true
+        "${CCACHE_BIN}" --zero-stats || true
+        "${CCACHE_BIN}" --show-stats || true
         
-        # Step 8: Print what's done for debugging
-        echo "--- ccache setup info ---"
-        echo "ccache binary: $(which ccache)"
-        echo "gcc via ccache: $(which gcc)"
-        echo "g++ via ccache: $(which g++)"
-        echo "symlinks dir: $SYMLINK_DIR"
-        echo "max size: $(ccache --show-stats | grep 'cache size' | awk '{print $3}')"
     - name: 'Setup ccache and Build Environment'
       shell: bash
       if: false