Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
ci(spaces): trusted Rust slice producer and a cache key that hits (#5536)
Francesco Bonacci7c465d506101
diff --git a/.github/actions/spaces-rust-slice/action.yml b/.github/actions/spaces-rust-slice/action.ymlnew file mode 100644index 0000000000..81e80ca8c1--- /dev/null+++ b/.github/actions/spaces-rust-slice/action.yml@@ -0,0 +1,97 @@+name: "Cua Spaces SwiftUI Rust slice"+description: >-+ Build the SwiftUI app's Rust slice for one macOS target (the app core+ library cua-spaces-ffi and the cua-spaces-cli binary), or restore it from+ the Actions cache. One definition shared by the trusted main-branch+ producer (ci-cua-spaces-rust-slice.yml) and the release build+ (cd-cua-spaces.yml), so both compute the same key and a release of a commit+ that main already built restores the slice instead of compiling for 33 to+ 60 minutes. The key is the git blob list of the inputs of the build: the+ Rust workspace without documentation and the non-Rust language packages,+ the cua-spacesd pin, the target and the toolchain. A miss builds (with the+ Rust dependency cache) and saves. Signing and verification of the app stay+ in cd-cua-spaces.yml and run on whatever this action leaves in place. Run+ after actions/checkout.++inputs:+ triple:+ description: "Rust target triple (aarch64-apple-darwin or x86_64-apple-darwin)."+ required: true++outputs:+ cache-hit:+ description: "true when the slice came from the cache."+ value: ${{ steps.cache.outputs.cache-hit }}+ key:+ description: "The cache key."+ value: ${{ steps.key.outputs.key }}++runs:+ using: composite+ steps:+ - name: Cache key+ id: key+ shell: bash+ env:+ TRIPLE: ${{ inputs.triple }}+ run: |+ set -euo pipefail+ # Hash the staged blobs (mode, object id, path) of what the build+ # reads. Documentation and the Kotlin, Python and TypeScript packages+ # are not inputs: a changelog or README edit must not cost a rebuild.+ inputs_hash="$( { git ls-files -s -- libs/cua libs/cua-spacesd/VERSION \+ ':(exclude)libs/cua/kotlin' ':(exclude)libs/cua/python' \+ ':(exclude)libs/cua/typescript' ':(exclude)libs/cua/skills' \+ ':(exclude,glob)**/*.md'; } | git hash-object --stdin)"+ repo="${CUA_RELEASE_REPOSITORY//\//-}"+ echo "key=swiftui-rust-v2-${TRIPLE}-rust1.97.1-${repo}-${inputs_hash}" >> "$GITHUB_OUTPUT"+ - name: Restore the compiled slice+ id: cache+ uses: actions/cache@v4+ with:+ path: |+ libs/cua/target/${{ inputs.triple }}/release/libcua_spaces_ffi.dylib+ libs/cua/target/${{ inputs.triple }}/release/cua-spaces-cli+ key: ${{ steps.key.outputs.key }}+ - name: Report the cache+ shell: bash+ env:+ HIT: ${{ steps.cache.outputs.cache-hit || 'false' }}+ KEY: ${{ steps.key.outputs.key }}+ run: echo "::notice::SwiftUI Rust slice cache hit = ${HIT} (${KEY})"+ - if: steps.cache.outputs.cache-hit != 'true'+ uses: dtolnay/[email protected]+ with:+ targets: ${{ inputs.triple }}+ - if: steps.cache.outputs.cache-hit != 'true'+ name: Install protoc+ uses: ./.github/actions/setup-protoc+ - if: steps.cache.outputs.cache-hit != 'true'+ uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2+ with:+ workspaces: libs/cua -> target+ shared-key: swiftui-rust-${{ inputs.triple }}+ # The repository's 10 GB Actions cache evicts oldest-first; a GB-sized+ # dependency cache per job pushed the small compiled-output caches out+ # within the hour. Only the default branch saves it.+ save-if: ${{ github.ref == 'refs/heads/main' }}+ cache-on-failure: true+ - if: steps.cache.outputs.cache-hit != 'true'+ name: Build the slice+ shell: bash+ working-directory: libs/cua+ env:+ CARGO_BUILD_JOBS: 4+ # build-release.sh's stable channel (--channel is not passed).+ CUA_DEFAULT_ENV: ""+ TRIPLE: ${{ inputs.triple }}+ run: cargo build --locked --release -p cua-spaces-ffi -p cua-spaces-cli --target "$TRIPLE"+ - name: Check the slice+ shell: bash+ env:+ TRIPLE: ${{ inputs.triple }}+ run: |+ set -euo pipefail+ for f in libcua_spaces_ffi.dylib cua-spaces-cli; do+ test -s "libs/cua/target/${TRIPLE}/release/$f" || { echo "::error::missing or empty $f"; exit 1; }+ donediff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.ymlindex db91a185dd..3e2161fd8a 100644--- a/.github/workflows/cd-cua-spaces.yml+++ b/.github/workflows/cd-cua-spaces.yml@@ -239,8 +239,10 @@ jobs:# job per architecture so the two build in parallel, as# build-release.sh would build them (same command and environment). The# compiled slices are kept in the Actions cache by the content of their- # inputs: a rerun, or a release of the commit a test build already- # compiled, restores them; a miss builds.+ # inputs (.github/actions/spaces-rust-slice). The main branch builds them+ # on every change to those inputs (ci-cua-spaces-rust-slice.yml), and a tag+ # run reads the default branch's cache, so a release restores them; a miss+ # builds.macos-rust:name: SwiftUI Rust (${{ matrix.arch }})needs: spacesd-published@@ -256,56 +258,13 @@ jobs:include:- { arch: arm64, triple: aarch64-apple-darwin }- { arch: x86_64, triple: x86_64-apple-darwin }- env:- CARGO_BUILD_JOBS: 4- # build-release.sh's stable channel (--channel is not passed).- CUA_DEFAULT_ENV: ""steps:- uses: actions/checkout@v4- - name: Cache key- id: key- env:- TRIPLE: ${{ matrix.triple }}- run: |- set -euo pipefail- inputs_hash="$(git rev-parse HEAD:libs/cua HEAD:libs/cua-spacesd/VERSION | git hash-object --stdin)"- repo="${CUA_RELEASE_REPOSITORY//\//-}"- echo "key=swiftui-rust-v1-${TRIPLE}-rust1.97.1-${repo}-${inputs_hash}" >> "$GITHUB_OUTPUT"- - name: Restore the compiled slice- id: cache- uses: actions/cache@v4+ # One definition with the main-branch producer+ # (ci-cua-spaces-rust-slice.yml): same key, restore or build.+ - uses: ./.github/actions/spaces-rust-slicewith:- path: |- libs/cua/target/${{ matrix.triple }}/release/libcua_spaces_ffi.dylib- libs/cua/target/${{ matrix.triple }}/release/cua-spaces-cli- key: ${{ steps.key.outputs.key }}- - if: steps.cache.outputs.cache-hit != 'true'- uses: dtolnay/[email protected]- with:- targets: ${{ matrix.triple }}- - if: steps.cache.outputs.cache-hit != 'true'- name: Install protoc- uses: ./.github/actions/setup-protoc- - if: steps.cache.outputs.cache-hit != 'true'- uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2- with:- workspaces: libs/cua -> target- shared-key: swiftui-rust-${{ matrix.triple }}- # The repository's 10 GB Actions cache evicts oldest-first; a GB-sized- # dependency cache per job pushed the small compiled-output caches out- # within the hour. Only the default branch saves it.- save-if: ${{ github.ref == 'refs/heads/main' }}- cache-on-failure: true- - if: steps.cache.outputs.cache-hit != 'true'- name: Build the slice- working-directory: libs/cua- run: cargo build --locked --release -p cua-spaces-ffi -p cua-spaces-cli --target "${{ matrix.triple }}"- - name: Check the slice- run: |- set -euo pipefail- for f in libcua_spaces_ffi.dylib cua-spaces-cli; do- test -f "libs/cua/target/${{ matrix.triple }}/release/$f" || { echo "::error::missing $f"; exit 1; }- done+ triple: ${{ matrix.triple }}- uses: actions/upload-artifact@v4with:name: macos-rust-${{ matrix.arch }}diff --git a/.github/workflows/ci-cua-spaces-rust-slice.yml b/.github/workflows/ci-cua-spaces-rust-slice.ymlnew file mode 100644index 0000000000..203b978561--- /dev/null+++ b/.github/workflows/ci-cua-spaces-rust-slice.yml@@ -0,0 +1,56 @@+name: "CI: Cua Spaces SwiftUI Rust slice (producer)"++# The one trusted producer of the SwiftUI app's compiled Rust slice. It builds+# the slice on main for every change to its inputs and saves it in the Actions+# cache under the key the release build (cd-cua-spaces.yml, macos-rust) computes+# from the same action, so a release restores it (seconds) instead of+# compiling (33 to 60 minutes). Tag runs can read the default branch's cache;+# they cannot read another tag's or a pull request's. A manual run of this+# workflow on a branch proves the contract: run it twice and compare the+# cache-hit notice and the job time. The release still signs and verifies the+# app; this only supplies the unsigned compiled slice.++on:+ push:+ branches: [main]+ paths:+ - "libs/cua/**"+ - "libs/cua-spacesd/VERSION"+ - ".github/actions/spaces-rust-slice/**"+ - ".github/workflows/ci-cua-spaces-rust-slice.yml"+ # A change to the producer itself proves its contract: the first run builds,+ # a re-run of the same commit restores (the pull request's own cache scope).+ pull_request:+ paths:+ - ".github/actions/spaces-rust-slice/**"+ - ".github/workflows/ci-cua-spaces-rust-slice.yml"+ workflow_dispatch:++permissions:+ contents: read++# Never cancel a build in progress: its cache is the point.+concurrency:+ group: ci-cua-spaces-rust-slice-${{ github.ref }}+ cancel-in-progress: false++env:+ # Same namespace as cd-cua-spaces.yml, so the keys match.+ CUA_RELEASE_REPOSITORY: ${{ github.repository }}++jobs:+ slice:+ name: SwiftUI Rust (${{ matrix.arch }})+ runs-on: macos-26+ timeout-minutes: 120+ strategy:+ fail-fast: false+ matrix:+ include:+ - { arch: arm64, triple: aarch64-apple-darwin }+ - { arch: x86_64, triple: x86_64-apple-darwin }+ steps:+ - uses: actions/checkout@v4+ - uses: ./.github/actions/spaces-rust-slice+ with:+ triple: ${{ matrix.triple }}