Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

ci(e2e-cua-sdk): per-job compiler caches, warmed nightly; sccache inside the image builder (CUA-3134) (#6387)

cua-agents[bot]6ac84a572b55
diff --git a/.github/scripts/e2e_cua_sdk_scope.py b/.github/scripts/e2e_cua_sdk_scope.py
index 16cff5896f..7b7814c1f6 100644
--- a/.github/scripts/e2e_cua_sdk_scope.py
+++ b/.github/scripts/e2e_cua_sdk_scope.py
@@ -85,6 +85,7 @@ PATHS = (
"docs/code-block-policy.json",
# What the job runs around the suite: gVisor, the toolchain, the cache, the scope script.
"scripts/images/install-gvisor.sh",
+ "scripts/ci/lib/docker-sccache.sh",
".github/actions/linux-rust-prep/**",
".github/actions/setup-protoc/**",
".github/actions/rust-cache/**",
diff --git a/.github/workflows/e2e-cua-sdk.yml b/.github/workflows/e2e-cua-sdk.yml
index 2615be5c49..b76b647b32 100644
--- a/.github/workflows/e2e-cua-sdk.yml
+++ b/.github/workflows/e2e-cua-sdk.yml
@@ -11,6 +11,9 @@ name: "E2E: cua SDK"
# .github/scripts/e2e_cua_sdk_scope.py).
# nightly cua-sandbox and local QEMU (KVM) on the reference disk.
# Cua Cloud has ended, so there is no live Fleet lane.
+# The five PR build jobs run too (no test shards): on main
+# they save their compiler caches, which every pull request
+# restores (see "Compiler caches" below).
# dispatch any lane set.
#
# Lume needs a macOS host with nested virtualization, which hosted runners
@@ -53,6 +56,7 @@ on:
- "docs/code-block-policy.json"
# gVisor, the toolchain and cache steps, and the scope script the job runs.
- "scripts/images/install-gvisor.sh"
+ - "scripts/ci/lib/docker-sccache.sh"
- ".github/actions/linux-rust-prep/**"
- ".github/actions/setup-protoc/**"
- ".github/actions/rust-cache/**"
@@ -106,7 +110,7 @@ jobs:
# skipped, the run still exists and succeeds, so `ci-gate` counts it as passed.
changes:
name: "E2E: cua SDK / changes"
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && (github.event_name != 'schedule')) }}
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--')) }}
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
@@ -141,10 +145,19 @@ jobs:
#
# Before this, one job built everything in series (about 46 minutes of
# builds) and then ran the three language halves in series (about 15).
+ #
+ # Compiler caches: each build job has its own sccache family (shared-key),
+ # because they compile different unit kinds (release SDK, debug CLI and
+ # wasm, static musl daemon plus fixtures, test binaries, the daemon inside
+ # the image builder's container). They used to share `libs-cua` with
+ # ci-cua-sdk.yml, whose entry held none of these units: 0 to 4% hits on
+ # three of the four jobs. This workflow does not run on main pushes, so the
+ # nightly runs the build jobs on main and saves the families; pull requests
+ # restore them (and never save).
build-sdk:
name: build / release SDK
needs: changes
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && (github.event_name != 'schedule') && needs.changes.outputs.run != 'false') }}
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && needs.changes.outputs.run != 'false') }}
runs-on: ubuntu-latest
timeout-minutes: 150
env:
@@ -166,7 +179,7 @@ jobs:
libs/cua
tests/e2e/cua-sdk/rust
libs/cua-spacesd
- key: cua-e2e
+ shared-key: cua-e2e-sdk
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "22"
@@ -186,7 +199,7 @@ jobs:
build-cli:
name: build / debug CLI, TypeScript, wasm
needs: changes
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && (github.event_name != 'schedule') && needs.changes.outputs.run != 'false') }}
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && needs.changes.outputs.run != 'false') }}
runs-on: ubuntu-latest
timeout-minutes: 150
env:
@@ -212,7 +225,7 @@ jobs:
libs/cua
tests/e2e/cua-sdk/rust
libs/cua-spacesd
- key: cua-e2e
+ shared-key: cua-e2e-cli
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "22"
@@ -234,7 +247,7 @@ jobs:
build-fixtures:
name: build / fixtures, static cua-spacesd
needs: changes
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && (github.event_name != 'schedule') && needs.changes.outputs.run != 'false') }}
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && needs.changes.outputs.run != 'false') }}
runs-on: ubuntu-latest
timeout-minutes: 150
env:
@@ -258,7 +271,8 @@ jobs:
libs/cua
tests/e2e/cua-sdk/rust
libs/cua-spacesd
- key: cua-e2e
+ shared-key: cua-e2e-fixtures
+ size: 6G
# An image without cua-spacesd gets the static musl build injected, so
# the suite tests this tree's daemon (same build as ci-cua-oci-spacesd).
# The shards point CUA_SPACESD_STATIC at this file in their checkout.
@@ -286,7 +300,7 @@ jobs:
build-rust-tests:
name: build / Rust test binaries
needs: changes
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && (github.event_name != 'schedule') && needs.changes.outputs.run != 'false') }}
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && needs.changes.outputs.run != 'false') }}
runs-on: ubuntu-latest
timeout-minutes: 150
env:
@@ -308,7 +322,7 @@ jobs:
libs/cua
tests/e2e/cua-sdk/rust
libs/cua-spacesd
- key: cua-e2e
+ shared-key: cua-e2e-rust-tests
# The Rust half's own build (its own target directory), done once here
# instead of inside `cargo test` on every shard.
- name: Build the Rust half's test binaries
@@ -327,7 +341,7 @@ jobs:
build-images:
name: build / reference images
needs: changes
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && (github.event_name != 'schedule') && needs.changes.outputs.run != 'false') }}
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && (!startsWith(github.head_ref, 'release-please--branches--') && needs.changes.outputs.run != 'false') }}
runs-on: ubuntu-latest
timeout-minutes: 120
env:
@@ -343,7 +357,12 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# cua-spacesd builds in a rust container and the three images on top,
- # all in the runner's docker.
+ # all in the runner's docker. The container compiles through this
+ # job's sccache (scripts/ci/lib/docker-sccache.sh).
+ - uses: ./.github/actions/rust-cache
+ with:
+ workspaces: "libs/cua-spacesd -> target"
+ shared-key: cua-e2e-images
- name: Build the reference images
run: tests/e2e/cua-sdk/ci-setup.sh --images --only images
- name: Pack
@@ -358,7 +377,8 @@ jobs:
if-no-files-found: error
shard:
- if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) }}
+ # The nightly runs the build jobs only to save their caches; its suite is `live`.
+ if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.draft) && github.event_name != 'schedule' }}
name: tests (shard ${{ matrix.shard }})
needs: [build-sdk, build-cli, build-fixtures, build-rust-tests, build-images]
runs-on: ubuntu-24.04
@@ -498,7 +518,10 @@ jobs:
libs/cua
tests/e2e/cua-sdk/rust
libs/cua-spacesd
- key: cua-e2e
+ # Restores the CLI build family; never saves, so it cannot replace
+ # the entry the PR build job needs with its own mix.
+ shared-key: cua-e2e-cli
+ save-if: "false"
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "22"
diff --git a/libs/images/linux/build-spacesd-linux.sh b/libs/images/linux/build-spacesd-linux.sh
index bbeb1b8739..60f94b6934 100755
--- a/libs/images/linux/build-spacesd-linux.sh
+++ b/libs/images/linux/build-spacesd-linux.sh
@@ -42,6 +42,11 @@ host_arch() { case "$(uname -m)" in arm64|aarch64) echo arm64 ;; *) echo amd64 ;
DEV_LIBS="libx11-dev libxi-dev libxtst-dev libxext-dev libxkbcommon-dev libdbus-1-dev libwayland-dev libxcb1-dev"
TOOLS="clang pkg-config cmake nasm protobuf-compiler libprotobuf-dev perl make"
+# The job's sccache, when the rust-cache action restored one (CI).
+# shellcheck source=/dev/null
+. "$REPO_ROOT/scripts/ci/lib/docker-sccache.sh"
+docker_sccache_args
+
for arch in "$@"; do
case "$arch" in
arm64) triple=aarch64-unknown-linux-gnu; gnu=aarch64-linux-gnu ;;
@@ -75,7 +80,11 @@ for arch in "$@"; do
git_sha="${CUA_SPACESD_GIT_SHA:-${CUA_GUESTD_GIT_SHA:-$(git -C "$REPO_ROOT" rev-parse HEAD 2>/dev/null || true)}}"
vol_suffix="$(echo "$platform" | tr / -)"
t0=$SECONDS
+ # Emulated foreign-arch builds cannot run the host's sccache binary.
+ sccache_args=()
+ [ "$mode" = emulate ] || sccache_args=("${DOCKER_SCCACHE[@]}")
docker run --rm --platform "$platform" --memory=6g --memory-swap=6g \
+ ${sccache_args[@]+"${sccache_args[@]}"} \
-v "$REPO_ROOT:/src:ro" \
-v "cua-e2e-spacesd-cargo-registry-$vol_suffix:/usr/local/cargo/registry" \
-v "${CUA_SPACESD_TARGET_VOLUME:-${CUA_GUESTD_TARGET_VOLUME:-${CUA_ENV_DRIVER_TARGET_VOLUME:-cua-e2e-spacesd-target}}}-$vol_suffix-$arch:/target" \
@@ -83,6 +92,8 @@ for arch in "$@"; do
-e CUA_SPACESD_GIT_SHA="$git_sha" \
-e CARGO_TARGET_DIR=/target -e CARGO_TERM_COLOR=never -e CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-4}" \
"$RUST_IMAGE" bash -euo pipefail -c "
+ $(declare -f docker_sccache_stop)
+ trap docker_sccache_stop EXIT
{ $setup; } || { echo 'toolchain setup failed' >&2; exit 1; }
$cargo_env
cd /src/libs/cua-spacesd
diff --git a/scripts/ci/lib/docker-sccache.sh b/scripts/ci/lib/docker-sccache.sh
new file mode 100644
index 0000000000..6f8b0414ae
--- /dev/null
+++ b/scripts/ci/lib/docker-sccache.sh
@@ -0,0 +1,57 @@
+# shellcheck shell=bash
+# Share the job's sccache with a cargo build that runs inside `docker run`.
+#
+# source scripts/ci/lib/docker-sccache.sh
+# docker_sccache_args # fills the DOCKER_SCCACHE array
+# docker run "${DOCKER_SCCACHE[@]}" ... bash -c '...; docker_sccache_stop'
+#
+# The rust-cache action (.github/actions/rust-cache) restores an sccache
+# directory and exports SCCACHE_DIR, SCCACHE_CACHE_SIZE and RUSTC_WRAPPER for
+# the host. A build inside a container saw none of it and compiled cold on
+# every run (the e2e reference images and the spacesd Docker lanes: 7 to 15
+# minutes each). This mounts the host's sccache binary (the static musl build
+# the action installs) and the restored directory into the container, so the
+# container's rustc goes through the same cache and the action saves what it
+# wrote. Paths inside the container are the same on every run, so its entries
+# hit on the next one.
+#
+# Off (empty array) when there is no restored directory or the binary is not
+# static: the build then compiles exactly as before. Set DOCKER_SCCACHE_OFF=1 to
+# force that.
+# shellcheck disable=SC2034 # read by the scripts that source this file
+DOCKER_SCCACHE=()
+docker_sccache_args() {
+ DOCKER_SCCACHE=()
+ [ "${DOCKER_SCCACHE_OFF:-}" = 1 ] && return 0
+ [ -n "${SCCACHE_DIR:-}" ] && [ -d "$SCCACHE_DIR" ] || return 0
+ local bin
+ bin="$(command -v sccache 2>/dev/null)" || return 0
+ bin="$(readlink -f "$bin")"
+ # A dynamically linked binary would not run in another distribution's image.
+ if ! file -L "$bin" 2>/dev/null | grep -q 'statically linked\|static-pie linked'; then
+ echo "docker-sccache: $bin is not static; the container compiles without sccache" >&2
+ return 0
+ fi
+ # shellcheck disable=SC2034
+ DOCKER_SCCACHE=(
+ -v "$bin:/usr/local/bin/sccache:ro"
+ -v "$SCCACHE_DIR:/sccache"
+ -e SCCACHE_DIR=/sccache
+ -e "SCCACHE_CACHE_SIZE=${SCCACHE_CACHE_SIZE:-4G}"
+ -e SCCACHE_IDLE_TIMEOUT=0
+ -e RUSTC_WRAPPER=/usr/local/bin/sccache
+ -e CARGO_INCREMENTAL=0
+ )
+ echo "docker-sccache: the container compiles through $SCCACHE_DIR"
+}
+
+# Inside the container, at the end of the build: flush the server's pending
+# writes before the container exits, and print its hit rate. A no-op without
+# sccache. Pass the body of this function into `bash -c` via
+# "$(declare -f docker_sccache_stop)".
+docker_sccache_stop() {
+ if [ -n "${RUSTC_WRAPPER:-}" ] && command -v sccache >/dev/null 2>&1; then
+ sccache --show-stats 2>/dev/null | grep -E 'Compile requests|Cache hits|Cache misses|Cache size' || true
+ sccache --stop-server >/dev/null 2>&1 || true
+ fi
+}