Visual Studio Code, rebuilt in Rust
Rust
build(studio): run cargo in two shared build slots with sccache
rokarture3daa66bcbfb
diff --git a/port/tools/build-slot b/port/tools/build-slotnew file mode 100755index 00000000000..6b44a55de26--- /dev/null+++ b/port/tools/build-slot@@ -0,0 +1,33 @@+#!/bin/bash+# Runs a command (a cargo run, from port/tools/studio) once one of the Studio's build slots is free.+# Parallel sessions' builds and test runs take turns: six at once swapped 32 GB and got SIGKILLed.+# PORT_BUILD_SLOTS sets the count; a command started inside a held slot runs at once (no deadlock on nested cargo).+set -uo pipefail+[[ -z ${PORT_BUILD_SLOT_HELD:-} ]] || exec "$@"+slots=${PORT_BUILD_SLOTS:-2}+slot=+trap '[[ -z $slot ]] || rm -rf "$slot"' EXIT+trap 'exit 1' INT TERM HUP++take() {+ mkdir "$1" 2>/dev/null && echo $$ > "$1/pid" && return+ local owner+ owner=$(cat "$1/pid" 2>/dev/null || true)+ [[ -n $owner ]] && ! kill -0 "$owner" 2>/dev/null && rm -rf "$1" && take "$1"+}++waiting=+until [[ -n $slot ]]; do+ for i in $(seq "$slots"); do+ if take "/tmp/port-build-slot-$i.lock"; then+ slot=/tmp/port-build-slot-$i.lock+ break+ fi+ done+ if [[ -z $slot ]]; then+ [[ -n $waiting ]] || echo "build-slot: all $slots slots are busy, waiting" >&2+ waiting=1+ sleep 2+ fi+done+PORT_BUILD_SLOT_HELD=1 "$@"diff --git a/port/tools/studio b/port/tools/studioindex dc4435d694e..0451a1cd95b 100755--- a/port/tools/studio+++ b/port/tools/studio@@ -40,5 +40,6 @@ sync_lock=cmd=$1# --lane '<cmd>': run a GUI tool in the first free GUI lane (port/tools/gui-lane).[[ $1 != --lane ]] || cmd="port/tools/gui-lane $(printf '%q' "$2")"-# Builds of parallel sessions run niced: the apps under test in a ui-pair run get the CPU first.-ssh studio "cd ~/$work/$name && bash -lc $(printf '%q' "cargo() { nice -n 15 cargo \"\$@\"; }; export -f cargo; $cmd")"+# Builds of parallel sessions run niced (the apps under test in a ui-pair run get the CPU first), in a build slot+# (port/tools/build-slot), and share one sccache: every mirror's dependencies compile once.+ssh studio "cd ~/$work/$name && bash -lc $(printf '%q' "export RUSTC_WRAPPER=sccache SCCACHE_CACHE_SIZE=40G; cargo() { ~/$work/$name/port/tools/build-slot nice -n 15 cargo \"\$@\"; }; export -f cargo; $cmd")"