Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Reduce Desktop SDK cache downloads and warm Linux ARM64 (#644)

Deec93eebe5af1a
diff --git a/.github/actions/desktop-flutter-arm64/action.yml b/.github/actions/desktop-flutter-arm64/action.yml
new file mode 100644
index 000000000..f9e78bda3
--- /dev/null
+++ b/.github/actions/desktop-flutter-arm64/action.yml
@@ -0,0 +1,88 @@
+name: Prepare Linux ARM64 Flutter
+description: Cache the pinned Git-installed SDK where Flutter publishes no SDK archive
+inputs:
+ version:
+ description: Exact Flutter version from release-desktop.yml
+ required: true
+ save-cache:
+ description: Save missing caches during cache preparation
+ default: 'false'
+runs:
+ using: composite
+ steps:
+ - name: Resolve the pinned SDK and cache identity
+ id: paths
+ shell: bash
+ env:
+ SDK_VERSION: ${{ inputs.version }}
+ run: |
+ set -euo pipefail
+ test "$RUNNER_OS/$RUNNER_ARCH" = Linux/ARM64
+ [[ "$SDK_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
+ revision="$(git ls-remote https://github.com/flutter/flutter.git \
+ "refs/tags/$SDK_VERSION" "refs/tags/$SDK_VERSION^{}" \
+ | awk 'NF == 2 { if ($2 ~ /\^\{\}$/) peeled=$1; else direct=$1 } END { print peeled ? peeled : direct }')"
+ [[ "$revision" =~ ^[0-9a-f]{40}$ ]]
+ {
+ echo "revision=$revision"
+ echo "sdk-path=$RUNNER_TOOL_CACHE/flutter/stable-$SDK_VERSION-arm64"
+ echo "sdk-key=flutter-linux-stable-$SDK_VERSION-arm64-$revision-desktop-v1"
+ echo "pub-path=$HOME/.pub-cache"
+ echo "pub-key=flutter-pub-linux-stable-$SDK_VERSION-arm64-$revision"
+ } >> "$GITHUB_OUTPUT"
+ - id: sdk
+ uses: actions/cache/restore@v4
+ with:
+ path: ${{ steps.paths.outputs.sdk-path }}
+ key: ${{ steps.paths.outputs.sdk-key }}
+ - id: pub
+ uses: actions/cache/restore@v4
+ with:
+ path: ${{ steps.paths.outputs.pub-path }}
+ key: ${{ steps.paths.outputs.pub-key }}-${{ hashFiles('**/pubspec.lock') }}
+ - name: Install the exact SDK from Git when absent
+ shell: bash
+ env:
+ SDK_ROOT: ${{ steps.paths.outputs.sdk-path }}/flutter
+ SDK_VERSION: ${{ inputs.version }}
+ SDK_REVISION: ${{ steps.paths.outputs.revision }}
+ SDK_PUB_CACHE: ${{ steps.paths.outputs.pub-path }}
+ run: |
+ set -euo pipefail
+ if [[ ! -x "$SDK_ROOT/bin/flutter" ]]; then
+ git clone --depth 1 --branch "$SDK_VERSION" https://github.com/flutter/flutter.git "$SDK_ROOT"
+ fi
+ test "$(git -C "$SDK_ROOT" rev-parse HEAD)" = "$SDK_REVISION"
+ {
+ echo "FLUTTER_ROOT=$SDK_ROOT"
+ echo "PUB_CACHE=$SDK_PUB_CACHE"
+ } >> "$GITHUB_ENV"
+ {
+ echo "$SDK_ROOT/bin"
+ echo "$SDK_ROOT/bin/cache/dart-sdk/bin"
+ echo "$SDK_PUB_CACHE/bin"
+ } >> "$GITHUB_PATH"
+ - name: Verify the toolchain and prepare Linux dependencies
+ shell: bash
+ working-directory: desktop
+ env:
+ SDK_VERSION: ${{ inputs.version }}
+ SDK_REVISION: ${{ steps.paths.outputs.revision }}
+ run: |
+ set -euo pipefail
+ # Bootstrap the native Dart SDK before reading machine-formatted output.
+ flutter --version
+ flutter --version --machine | jq -e --arg version "$SDK_VERSION" --arg revision "$SDK_REVISION" \
+ '.frameworkVersion == $version and .frameworkRevision == $revision'
+ flutter precache --linux
+ flutter pub get
+ - uses: actions/cache/save@v4
+ if: inputs.save-cache == 'true' && steps.sdk.outputs.cache-hit != 'true'
+ with:
+ path: ${{ steps.paths.outputs.sdk-path }}
+ key: ${{ steps.paths.outputs.sdk-key }}
+ - uses: actions/cache/save@v4
+ if: inputs.save-cache == 'true' && steps.pub.outputs.cache-hit != 'true'
+ with:
+ path: ${{ steps.paths.outputs.pub-path }}
+ key: ${{ steps.paths.outputs.pub-key }}-${{ hashFiles('**/pubspec.lock') }}
diff --git a/.github/actions/desktop-flutter/action.yml b/.github/actions/desktop-flutter/action.yml
index 7339f8f6b..c698bdc22 100644
--- a/.github/actions/desktop-flutter/action.yml
+++ b/.github/actions/desktop-flutter/action.yml
@@ -10,7 +10,8 @@ inputs:
runs:
using: composite
steps:
- # Keep upstream keys/paths so logging, internal and web builds can reuse main's caches too.
+ # Keep the upstream installation path and exact SDK identity. Desktop's
+ # smaller archive has its own key; the full SDK remains a compatible fallback.
- id: paths
uses: subosito/flutter-action@v2
with:
@@ -23,7 +24,8 @@ runs:
uses: actions/cache/restore@v4
with:
path: ${{ steps.paths.outputs.CACHE-PATH }}
- key: ${{ steps.paths.outputs.CACHE-KEY }}
+ key: ${{ steps.paths.outputs.CACHE-KEY }}-desktop-v1
+ restore-keys: ${{ steps.paths.outputs.CACHE-KEY }}
- id: pub
uses: actions/cache/restore@v4
with:
@@ -51,11 +53,17 @@ runs:
flutter precache --linux
fi
flutter pub get
+ - name: Trim mobile artifacts before saving the Desktop SDK cache
+ if: inputs.save-cache == 'true' && steps.sdk.outputs.cache-hit != 'true'
+ shell: bash
+ env:
+ ACTION_PATH: ${{ github.action_path }}
+ run: python3 "$ACTION_PATH/trim-cache.py" "$FLUTTER_ROOT"
- uses: actions/cache/save@v4
if: inputs.save-cache == 'true' && steps.sdk.outputs.cache-hit != 'true'
with:
path: ${{ steps.paths.outputs.CACHE-PATH }}
- key: ${{ steps.paths.outputs.CACHE-KEY }}
+ key: ${{ steps.paths.outputs.CACHE-KEY }}-desktop-v1
- uses: actions/cache/save@v4
if: inputs.save-cache == 'true' && steps.pub.outputs.cache-hit != 'true'
with:
diff --git a/.github/actions/desktop-flutter/trim-cache.py b/.github/actions/desktop-flutter/trim-cache.py
new file mode 100644
index 000000000..45b3398be
--- /dev/null
+++ b/.github/actions/desktop-flutter/trim-cache.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+"""Remove mobile engine artifacts from a CI-owned Desktop SDK cache."""
+import argparse
+from pathlib import Path
+import shutil
+
+MOBILE_ARTIFACTS = {"ios", "ios-profile", "ios-release"} | {
+ f"android-{arch}{mode}"
+ for arch in ("arm", "arm64", "x86", "x64")
+ for mode in ("", "-profile", "-release")
+}
+
+
+def trim_cache(root):
+ root = root.resolve(strict=True)
+ engine = root / "bin/cache/artifacts/engine"
+ if not (root / "bin/flutter").is_file() or not engine.is_dir() or engine.resolve() != engine:
+ raise ValueError("expected a Flutter SDK with an in-place engine cache")
+ selected = [engine / name for name in sorted(MOBILE_ARTIFACTS) if (engine / name).exists() or (engine / name).is_symlink()]
+ # Validate the complete selection before deleting anything. Frameworks may
+ # contain internal symlinks; rmtree removes those links without following them.
+ if any(path.is_symlink() or not path.is_dir() for path in selected):
+ raise ValueError("mobile engine artifacts must be ordinary SDK directories")
+ for path in selected:
+ shutil.rmtree(path)
+ return [path.name for path in selected]
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("sdk", type=Path)
+ args = parser.parse_args()
+ removed = trim_cache(args.sdk)
+ print(f"Desktop SDK cache: removed {len(removed)} mobile engine directories: " + ", ".join(removed))
+
+
+if __name__ == "__main__":
+ main()
diff --git a/.github/workflows/desktop-cache.yml b/.github/workflows/desktop-cache.yml
index a410995ff..62c59e0b4 100644
--- a/.github/workflows/desktop-cache.yml
+++ b/.github/workflows/desktop-cache.yml
@@ -9,6 +9,7 @@ on:
- 'desktop/pubspec.yaml'
- '**/pubspec.lock'
- '.github/actions/desktop-flutter/**'
+ - '.github/actions/desktop-flutter-arm64/**'
- '.github/workflows/desktop-cache.yml'
- '.github/workflows/release-desktop.yml'
pull_request:
@@ -16,6 +17,7 @@ on:
- 'desktop/pubspec.yaml'
- '**/pubspec.lock'
- '.github/actions/desktop-flutter/**'
+ - '.github/actions/desktop-flutter-arm64/**'
- '.github/workflows/desktop-cache.yml'
- '.github/workflows/release-desktop.yml'
workflow_dispatch:
@@ -32,7 +34,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- os: [macos-15, ubuntu-22.04]
+ os: [macos-15, ubuntu-22.04, ubuntu-22.04-arm]
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
@@ -43,6 +45,12 @@ jobs:
test -n "$version"
echo "version=$version" >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/desktop-flutter
+ if: runner.os != 'Linux' || runner.arch != 'ARM64'
+ with:
+ version: ${{ steps.toolchain.outputs.version }}
+ save-cache: 'true'
+ - uses: ./.github/actions/desktop-flutter-arm64
+ if: runner.os == 'Linux' && runner.arch == 'ARM64'
with:
version: ${{ steps.toolchain.outputs.version }}
save-cache: 'true'
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index d2a532e27..a47fc18dc 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -256,34 +256,17 @@ jobs:
sudo apt-get install -y --no-install-recommends \
clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
- # Flutter publishes NO linux-arm64 SDK archive — releases_linux.json carries `x64` and
- # nothing else — so flutter-action has nothing to download on ubuntu-22.04-arm and fails
- # outright. Everything it would have unpacked does exist for arm64 (both
- # linux-arm64/artifacts.zip and dart-sdk-linux-arm64.zip are served for this engine), so the
- # SAME toolchain is reached by the other route: clone the SDK at the same tag and let
- # precache pull the artifacts. x64 keeps the action for its cache.
+ # Flutter has no Linux ARM64 SDK archive. Its action installs the same
+ # pinned SDK from Git, verifies the revision, and reuses main's native cache.
- uses: ./.github/actions/desktop-flutter
if: matrix.arch != 'arm64'
with:
version: ${{ env.FLUTTER_VERSION }}
- - name: Install Flutter from git (arm64 has no published archive)
+ - uses: ./.github/actions/desktop-flutter-arm64
if: matrix.arch == 'arm64'
- run: |
- set -euo pipefail
- git clone --depth 1 --branch "$FLUTTER_VERSION" \
- https://github.com/flutter/flutter.git "$RUNNER_TEMP/flutter"
- echo "$RUNNER_TEMP/flutter/bin" >> "$GITHUB_PATH"
-
- # x64 is prepared by the shared action. arm64 has no SDK archive/cache.
- - name: Verify the toolchain and precache Linux artifacts
- if: matrix.arch == 'arm64'
- run: |
- flutter --version
- flutter precache --linux
-
- - if: matrix.arch == 'arm64'
- run: flutter pub get
+ with:
+ version: ${{ env.FLUTTER_VERSION }}
# appimagetool packages the Linux bundle into the single-file .AppImage the release publishes
# (see RELEASE.md). --appimage-extract-and-run in upload-desktop-linux.sh means the runner
diff --git a/docs/validation-and-release.md b/docs/validation-and-release.md
index 7a5396a5e..25f9732ce 100644
--- a/docs/validation-and-release.md
+++ b/docs/validation-and-release.md
@@ -63,7 +63,10 @@ needed; it does not publish anything. Release tags restore those caches without
saving another tag-specific copy. Cache misses still install the pinned SDK and
resolve dependencies normally. macOS enables Swift Package Manager before pub get.
The shared keys include SDK version/commit, OS/architecture, and the dependency
-lockfiles for pub. Signing, notarization and artifact checks remain required.
+lockfiles for pub. Desktop SDK caches omit Android/iOS engine artifacts and use
+their own key, with the full SDK for the exact same version as a fallback. Cache
+preparation covers macOS and both Linux architectures. Signing, notarization and
+artifact checks remain required.
Native TUI CI tests and builds the shipped musl target in the same Cargo output
directory. Dependency caches are keyed by target, Rust toolchain, and Cargo inputs;
diff --git a/scripts/tests/test_desktop_sdk_cache.py b/scripts/tests/test_desktop_sdk_cache.py
new file mode 100644
index 000000000..2cb5ccaf7
--- /dev/null
+++ b/scripts/tests/test_desktop_sdk_cache.py
@@ -0,0 +1,81 @@
+"""Cache trimming must preserve every desktop tool and stay inside its SDK."""
+import importlib.util
+from pathlib import Path
+import tempfile
+import unittest
+
+ROOT = Path(__file__).resolve().parents[2]
+spec = importlib.util.spec_from_file_location("desktop_sdk_cache", ROOT / ".github/actions/desktop-flutter/trim-cache.py")
+cache = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(cache)
+
+
+class DesktopSdkCacheTests(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.temp.cleanup)
+ self.root = Path(self.temp.name) / "SDK with spaces"
+ self.engine = self.root / "bin/cache/artifacts/engine"
+ self.engine.mkdir(parents=True)
+ (self.root / "bin/flutter").write_text("launcher")
+
+ def artifact(self, name):
+ path = self.engine / name
+ path.mkdir()
+ (path / "payload").write_text(name)
+ return path
+
+ def test_removes_only_mobile_engine_artifacts_and_is_repeatable(self):
+ mobile = ["android-arm", "android-arm64-release", "android-x86", "ios", "ios-profile", "ios-release"]
+ kept = ["darwin-x64", "darwin-x64-release", "darwin-x64-profile", "linux-arm64", "linux-x64-release", "common", "future-engine"]
+ for name in mobile + kept:
+ self.artifact(name)
+ other = self.root / "packages/android-arm"
+ other.mkdir(parents=True)
+ (other / "source.dart").write_text("keep SDK source")
+ self.assertEqual(cache.trim_cache(self.root), sorted(mobile))
+ self.assertTrue(all(not (self.engine / name).exists() for name in mobile))
+ for name in kept:
+ self.assertEqual((self.engine / name / "payload").read_text(), name)
+ self.assertEqual((other / "source.dart").read_text(), "keep SDK source")
+ self.assertEqual((self.root / "bin/flutter").read_text(), "launcher")
+ self.assertEqual(cache.trim_cache(self.root), [])
+
+ def test_rejects_a_directory_that_is_not_an_sdk(self):
+ mobile = self.artifact("ios")
+ (self.root / "bin/flutter").unlink()
+ with self.assertRaises(ValueError):
+ cache.trim_cache(self.root)
+ self.assertTrue(mobile.exists())
+
+ def test_rejects_an_engine_cache_redirected_outside_the_sdk(self):
+ outside = Path(self.temp.name) / "outside"
+ self.engine.rename(outside)
+ self.engine.symlink_to(outside, target_is_directory=True)
+ (outside / "ios").mkdir()
+ with self.assertRaises(ValueError):
+ cache.trim_cache(self.root)
+ self.assertTrue((outside / "ios").exists())
+
+ def test_checks_all_top_level_artifacts_before_removing_any(self):
+ mobile = self.artifact("android-arm")
+ outside = Path(self.temp.name) / "outside"
+ outside.mkdir()
+ (outside / "payload").write_text("keep outside data")
+ (self.engine / "ios").symlink_to(outside, target_is_directory=True)
+ with self.assertRaises(ValueError):
+ cache.trim_cache(self.root)
+ self.assertTrue(mobile.exists())
+ self.assertEqual((outside / "payload").read_text(), "keep outside data")
+
+ def test_internal_framework_links_do_not_remove_their_targets(self):
+ mobile = self.artifact("ios")
+ outside = Path(self.temp.name) / "outside"
+ outside.write_text("keep outside data")
+ (mobile / "linked-framework").symlink_to(outside)
+ self.assertEqual(cache.trim_cache(self.root), ["ios"])
+ self.assertEqual(outside.read_text(), "keep outside data")
+
+
+if __name__ == "__main__":
+ unittest.main()