
# Which build. The default is exactly what this script has always done, and
# has to stay that way: deploy.sh calls it with no argument every twenty
# minutes, and ship.sh calls deploy.sh. `--release` (or SS_ANDROID_RELEASE=1)
# is the other path, and as of this round nobody has run it — see ANDROID.md
# → "The release build (nobody has made one yet)".
REL=0
case "${1:-}" in
    --release) REL=1 ;;
    "") ;;
    *) echo "usage: build.sh [--release]"; exit 2 ;;
esac
if [ "${SS_ANDROID_RELEASE:-0}" = "1" ]; then REL=1; fi
if [ "$REL" = "1" ]; then
    PROFILE=release
    VARIANT=Arm64Release
    # --features is repeatable and cargo unions them, so custom-protocol on
    # the cargo line below is kept. devtools is not a nicety: wry compiles the
    # setWebContentsDebuggingEnabled call only under
    # cfg(any(debug_assertions, feature = "devtools")), so a plain release APK
    # opens no webview_devtools_remote socket and `smoke.mjs --phone` cannot
    # attach to the one build that most needs walking. R8 never sees it.
    CARGO_EXTRA="--release --features tauri/devtools"
    test -d src-tauri/gen/android/app || { echo "no generated Android project — run the CLI's android init first"; exit 1; }
    # The app-wide keep rules, into a project that cannot hold them itself:
    # gen/ is regenerated and gitignored. The release build type globs
    # **/*.pro out of this directory; the debug type reads none of them.
    cp src-tauri/android/proguard-soulstream.pro src-tauri/gen/android/app/proguard-soulstream.pro
    echo "== RELEASE: R8 on, rules from src-tauri/android/proguard-soulstream.pro + each plugin's consumer-rules.pro"
else
    PROFILE=debug
    VARIANT=Arm64Debug
    CARGO_EXTRA=""
fi
