From ff312e8e11912780edcdce968bd1aa8ddd1de73c Mon Sep 17 00:00:00 2001 From: mattt Date: Tue, 17 Nov 2026 20:17:43 -0800 Subject: [PATCH 1/3] Download the Metal toolchain instead of caching it --- .github/workflows/ci.yml | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5aaedd8d..7dcb3583 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,36 +59,14 @@ jobs: # Swift 6.4's default build system compiles MLX's Metal shaders, # and the Xcode 27 runner image doesn't include the Metal toolchain. - - name: Identify Xcode build - if: matrix.swift == '6.4' - id: xcode - run: echo "build=$(xcodebuild -version | awk '/Build version/ { print $3 }')" >> "$GITHUB_OUTPUT" - - - name: Restore Metal toolchain download - if: matrix.swift == '6.4' - id: metal-cache - uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ~/.cache/metal-toolchain - key: ${{ runner.os }}-${{ runner.arch }}-metal-${{ steps.xcode.outputs.build }} - - - name: Download Metal toolchain - if: matrix.swift == '6.4' && steps.metal-cache.outputs.cache-hit != 'true' - run: xcodebuild -downloadComponent MetalToolchain -exportPath "$HOME/.cache/metal-toolchain" - - - name: Save Metal toolchain download - if: matrix.swift == '6.4' && steps.metal-cache.outputs.cache-hit != 'true' && github.event_name == 'push' - uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ~/.cache/metal-toolchain - key: ${{ steps.metal-cache.outputs.cache-primary-key }} - + # Downloading it takes seconds, less than restoring it from an 835 MB cache. - name: Install Metal toolchain if: matrix.swift == '6.4' run: | xcrun --kill-cache if ! xcrun metal --version >/dev/null 2>&1; then - for bundle in "$HOME/.cache/metal-toolchain/"*.exportedBundle; do + xcodebuild -downloadComponent MetalToolchain -exportPath "$RUNNER_TEMP/metal-toolchain" + for bundle in "$RUNNER_TEMP/metal-toolchain/"*.exportedBundle; do xcodebuild -importComponent MetalToolchain -importPath "$bundle" done xcrun --kill-cache From ce290b15d8cc93fda1b0d62c5179d64ea3239b4b Mon Sep 17 00:00:00 2001 From: mattt Date: Tue, 17 Nov 2026 20:18:11 -0800 Subject: [PATCH 2/3] Cache only the build directory --- .github/workflows/ci.yml | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dcb3583..14d47414 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,12 +80,10 @@ jobs: id: spm-cache uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: | - ~/.cache/org.swift.swiftpm - .build - key: ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-spm-${{ hashFiles('Package.swift', 'Package.resolved') }} + path: .build + key: ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-build-${{ hashFiles('Package.swift', 'Package.resolved') }} restore-keys: | - ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-spm- + ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-build- - name: Lint run: swift format lint --strict --recursive . @@ -104,9 +102,7 @@ jobs: if: steps.spm-cache.outputs.cache-hit != 'true' && github.event_name == 'push' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: | - ~/.cache/org.swift.swiftpm - .build + path: .build key: ${{ steps.spm-cache.outputs.cache-primary-key }} - name: Test @@ -178,16 +174,16 @@ jobs: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + # Cache only .build. SwiftPM's shared cache, ~/.cache/org.swift.swiftpm, + # repeats the Git repositories in .build/repositories. - name: Restore Swift Package Manager cache id: spm-cache uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: | - ~/.cache/org.swift.swiftpm - .build - key: ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-spm-${{ hashFiles('Package.swift', 'Package.resolved') }} + path: .build + key: ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-build-${{ hashFiles('Package.swift', 'Package.resolved') }} restore-keys: | - ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-spm- + ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-build- - name: Lint run: swift format lint --strict --recursive . @@ -199,9 +195,7 @@ jobs: if: steps.spm-cache.outputs.cache-hit != 'true' && github.event_name == 'push' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: | - ~/.cache/org.swift.swiftpm - .build + path: .build key: ${{ steps.spm-cache.outputs.cache-primary-key }} - name: Test @@ -224,16 +218,16 @@ jobs: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + # Cache only .build. SwiftPM's shared cache, ~/.cache/org.swift.swiftpm, + # repeats the Git repositories in .build/repositories. - name: Restore Swift Package Manager cache id: spm-cache uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: | - ~/.cache/org.swift.swiftpm - .build - key: ${{ runner.os }}-swift-${{ matrix.swift }}-wasi-spm-${{ hashFiles('Package.swift', 'Package.resolved') }} + path: .build + key: ${{ runner.os }}-swift-${{ matrix.swift }}-wasi-build-${{ hashFiles('Package.swift', 'Package.resolved') }} restore-keys: | - ${{ runner.os }}-swift-${{ matrix.swift }}-wasi-spm- + ${{ runner.os }}-swift-${{ matrix.swift }}-wasi-build- - name: Install Swift SDK for WASI run: | @@ -251,7 +245,5 @@ jobs: if: steps.spm-cache.outputs.cache-hit != 'true' && github.event_name == 'push' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: | - ~/.cache/org.swift.swiftpm - .build + path: .build key: ${{ steps.spm-cache.outputs.cache-primary-key }} From 44cf60f7b0bdeede488b6e731b4e2aab21bbaaaa Mon Sep 17 00:00:00 2001 From: mattt Date: Tue, 17 Nov 2026 20:41:35 -0800 Subject: [PATCH 3/3] Leave Git repositories and the index store out of macOS caches --- .github/workflows/ci.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14d47414..dac6421b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,11 +76,17 @@ jobs: # Only pushes to main save caches. # A pull request's run can read main's caches but not another pull request's, # and its saved caches would evict main's from the 10 GB repository limit. + # The cache leaves out .build/repositories, about 30 percent of its size. + # SwiftPM doesn't read those Git repositories while the checkouts match Package.resolved, + # and it fetches the ones it needs when a pin changes. + # On macOS, SwiftPM keeps its shared cache in ~/Library/Caches, which isn't cached. - name: Restore Swift Package Manager cache id: spm-cache uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: .build + path: | + .build/* + !.build/repositories key: ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-build-${{ hashFiles('Package.swift', 'Package.resolved') }} restore-keys: | ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'ahc-off' || 'ahc-on' }}-build- @@ -95,18 +101,22 @@ jobs: if: matrix.swift == '6.4' run: rm -rf .build/out/Intermediates.noindex/XCBuildData/*.xcbuilddata + # Nothing in these jobs reads the index store. + # The Linux jobs keep it because test discovery on Linux reads it. - name: Build - run: swift build --build-tests --traits MLX,Llama,CoreML${{ matrix.traits != '' && format(',{0}', matrix.traits) || '' }} + run: swift build --build-tests --disable-index-store --traits MLX,Llama,CoreML${{ matrix.traits != '' && format(',{0}', matrix.traits) || '' }} - name: Save Swift Package Manager cache if: steps.spm-cache.outputs.cache-hit != 'true' && github.event_name == 'push' uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: .build + path: | + .build/* + !.build/repositories key: ${{ steps.spm-cache.outputs.cache-primary-key }} - name: Test - run: swift test --skip-build --traits MLX,Llama,CoreML${{ matrix.traits != '' && format(',{0}', matrix.traits) || '' }} + run: swift test --skip-build --disable-index-store --traits MLX,Llama,CoreML${{ matrix.traits != '' && format(',{0}', matrix.traits) || '' }} build-watchos: permissions: