#!/bin/sh
# Thin launch glue. Cache ownership, validation, policy and bootstrap selection
# are Rust responsibilities. This private temporary executable is not a cache.
set -eu
original_umask=$(umask)
umask 077
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P)
bootstrap_dir=$(mktemp -d "${TMPDIR:-/tmp}/rts-cache-launch.XXXXXXXX")
trap 'rm -f -- "$bootstrap_dir/launcher"; rmdir -- "$bootstrap_dir"' EXIT
(cd "$repo" && rustc --edition=2024 -C debuginfo=0 scripts/cache-bootstrap.rs -o "$bootstrap_dir/launcher")
umask "$original_umask"
# The Rust launcher removes its own private transient file before doing work.
# exec preserves the PID tracked by Studio, including its forced-stop fallback.
exec "$bootstrap_dir/launcher" "$repo" "$@"
