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.

cua-spaces-macos: faster install-local.sh (sccache, parallel web build) (#6320)

Francesco Bonaccib72833f10706
diff --git a/apps/cua-spaces-macos/scripts/install-local.sh b/apps/cua-spaces-macos/scripts/install-local.sh
index 72e6ef8564..4cfd6dbc38 100755
--- a/apps/cua-spaces-macos/scripts/install-local.sh
+++ b/apps/cua-spaces-macos/scripts/install-local.sh
@@ -189,7 +189,18 @@ case "${CARGO_TARGET_DIR:-/}" in
/*) ;;
*) die "CARGO_TARGET_DIR must be an absolute path (got: $CARGO_TARGET_DIR)." ;;
esac
-SPACESD_BIN="${CARGO_TARGET_DIR:-$SPACESD_DIR/target}/release/cua-spacesd"
+# libs/cua and libs/cua-spacesd are separate Cargo workspaces (libs/cua pins its
+# toolchain in rust-toolchain.toml), so they must not share a target directory:
+# artifacts from one toolchain break the other (E0463 "can't find crate for
+# zeroize_derive"). A set CARGO_TARGET_DIR is used as a parent, one subdirectory
+# per workspace.
+if [ -n "${CARGO_TARGET_DIR:-}" ]; then
+ SPACESD_TARGET_DIR="$CARGO_TARGET_DIR/cua-spacesd"
+ export CARGO_TARGET_DIR="$CARGO_TARGET_DIR/cua"
+else
+ SPACESD_TARGET_DIR="$SPACESD_DIR/target"
+fi
+SPACESD_BIN="$SPACESD_TARGET_DIR/release/cua-spacesd"
[ -x "$BUILD_SCRIPT" ] || die "missing $BUILD_SCRIPT"
[ -f "$SIGNING_LIB" ] || die "missing $SIGNING_LIB (the stable local signing shared with Cua Driver)"
@@ -306,21 +317,38 @@ echo ""
# --- Build -----------------------------------------------------------------------
-# The web UI first (as the release build does: pnpm install --frozen-lockfile,
-# pnpm build, which builds the app core's WebAssembly and then the pages): it
-# is the quick one to fail. CI=true keeps pnpm from asking questions.
+# The web UI (as the release build does: pnpm install --frozen-lockfile,
+# pnpm build, which builds the app core's WebAssembly and then the pages).
+# CI=true keeps pnpm from asking questions. Its build shares no target directory with the Rust build below, so
+# the two run side by side (a cold wasm build is minutes). Its output goes to a
+# log that is shown when it fails.
+WEB_PID=""
+WEB_BUILD_LOG=""
if [ "$BUILD_WEB" = 1 ]; then
- log "building the web UI (apps/cua-spaces-web: pnpm install, pnpm build)"
- if ! (cd "$WEBUI_APP" && CI=true pnpm install --ignore-workspace --frozen-lockfile && pnpm build); then
+ log "building the web UI (apps/cua-spaces-web: pnpm install, pnpm build) in the background"
+ WEB_BUILD_LOG="$(mktemp -t cua-local-webui)"
+ (cd "$WEBUI_APP" && CI=true pnpm install --ignore-workspace --frozen-lockfile && pnpm build) >"$WEB_BUILD_LOG" 2>&1 &
+ WEB_PID=$!
+fi
+wait_for_web_ui() {
+ [ -n "$WEB_PID" ] || return 0
+ if wait "$WEB_PID"; then
+ ok "the web UI is built"
+ rm -f "$WEB_BUILD_LOG"
+ else
+ cat "$WEB_BUILD_LOG" >&2
+ rm -f "$WEB_BUILD_LOG"
die "the web UI build failed (see above). Nothing was installed."
fi
-fi
-if [ ! -f "$WEBUI_DIST/index.html" ]; then
- web_ui_missing
- exit 1
-fi
-
+ WEB_PID=""
+}
if [ "$SKIP_RUST_BUILD" = 0 ]; then
+ # sccache, when installed, shares compiled crates between checkouts and
+ # survives a cargo clean. A set $RUSTC_WRAPPER (even empty) overrides this.
+ if [ -z "${RUSTC_WRAPPER+x}" ] && command -v sccache >/dev/null 2>&1; then
+ export RUSTC_WRAPPER=sccache
+ log "using sccache for the Rust builds"
+ fi
if ! command -v cargo >/dev/null 2>&1 && [ -f "$HOME/.cargo/env" ]; then
# shellcheck disable=SC1091
. "$HOME/.cargo/env"
@@ -332,7 +360,12 @@ if [ "$SKIP_RUST_BUILD" = 0 ]; then
(cd "$REPO_ROOT/libs/cua" && cargo build --locked --release -p cua-spaces-ffi -p cua-spaces-cli)
"$REPO_ROOT/libs/spaces-app-swift/scripts/stage-library.sh"
log "building cua-spacesd from this checkout (cargo, release)"
- (cd "$SPACESD_DIR" && cargo build --locked --release -p cua-spacesd --bin cua-spacesd)
+ (cd "$SPACESD_DIR" && CARGO_TARGET_DIR="$SPACESD_TARGET_DIR" cargo build --locked --release -p cua-spacesd --bin cua-spacesd)
+fi
+wait_for_web_ui
+if [ ! -f "$WEBUI_DIST/index.html" ]; then
+ web_ui_missing
+ exit 1
fi
[ -x "$SPACESD_BIN" ] || die "cargo did not produce $SPACESD_BIN"
diff --git a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
index 7e27de2901..16e0f7f14b 100755
--- a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
+++ b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
@@ -827,7 +827,7 @@ WEB_DIST="$FAKE_REPO/apps/cua-spaces-web/dist"
check "the web UI is built as the release build does: pnpm install --ignore-workspace --frozen-lockfile, then pnpm build, in apps/cua-spaces-web" \
'[ "$(cat "$WEB_LOG")" = "pnpm install --ignore-workspace --frozen-lockfile [in cua-spaces-web] CI=true
pnpm build [in cua-spaces-web] CI=" ]'
-check "it is built before the Rust build (the quick one fails first)" '[ -s "$WEB_LOG" ] && [ -s "$CARGO_LOG" ]'
+check "it is built alongside the Rust build" '[ -s "$WEB_LOG" ] && [ -s "$CARGO_LOG" ]'
check "the build is told where the web UI is, and the installed app has it" \
'grep >/dev/null "^webui=$WEB_DIST\$" "$BUILD_LOG" && [ -f "$LOCAL_APP/Contents/Resources/WebUI/index.html" ]'
check "the signature covers the web UI (it verifies, deep and strict)" '/usr/bin/codesign --verify --deep --strict "$LOCAL_APP" 2>/dev/null'
@@ -856,8 +856,8 @@ check "a CUA_WEBUI_DIST without an index.html stops with the same message" \
reset_fixture
ALL_BEFORE="$(snap_all)"
run env SHIM_PNPM_BUILD_FAILS=1 "$FAKE_SCRIPTS/install-local.sh" --no-launch
-check "a failing web UI build stops the install, and nothing is built after it or installed" \
- '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "the web UI build failed" && [ ! -s "$BUILD_LOG" ] && [ ! -s "$CARGO_LOG" ] && [ ! -e "$LOCAL_APP" ] && [ "$(snap_all)" = "$ALL_BEFORE" ]'
+check "a failing web UI build stops the install: the app is not built or installed (cargo runs alongside it)" \
+ '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "the web UI build failed" && [ ! -s "$BUILD_LOG" ] && [ ! -e "$LOCAL_APP" ] && [ "$(snap_all)" = "$ALL_BEFORE" ]'
reset_fixture
install