#!/bin/bash
# usage: cache.sh <base|head> <save|cross|restore>
# save: keep the real helper binaries. cross: put each target's cache slot the OTHER architecture's binary. restore: undo.
S=/tmp/scratch
case $1 in base) wt=$HOME/wt/base;; head) wt=$HOME/wt/head;; esac
A=aarch64-unknown-linux-gnu; X=x86_64-unknown-linux-gnu; B=$S/cache-$1
for h in resource-monitor/t3-resource-monitor kde-snap-shot/t3-kde-snap-shot hyprland-snap-shot/t3-hyprland-snap-shot; do
  crate=${h%/*}; bin=${h#*/}; t=$wt/native/$crate/target
  case $2 in
    save) mkdir -p $B/$A $B/$X; cp $t/$A/release/$bin $B/$A/$bin; cp $t/$X/release/$bin $B/$X/$bin;;
    cross) cp $B/$X/$bin $t/$A/release/$bin; cp $B/$A/$bin $t/$X/release/$bin;;
    restore) cp $B/$A/$bin $t/$A/release/$bin; cp $B/$X/$bin $t/$X/release/$bin;;
  esac
  echo "native/$crate/target/$A/release/$bin: $(file -b $t/$A/release/$bin | cut -d, -f1-2)"
  echo "native/$crate/target/$X/release/$bin: $(file -b $t/$X/release/$bin | cut -d, -f1-2)"
done
