#!/bin/bash
set -e

run=false

TEMP=$(getopt --long -o "g" "$@")
eval set -- "$TEMP"
while true; do
  case "$1" in
  -g)
    run=true
    shift 2
    ;;
  *)
    break
    ;;
  esac
done

echo "ANDROID_HOME: $ANDROID_HOME"
echo "ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT"
echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"

cargo install cargo-apk

if [ "$run" = true ] ; then
  # -Zbuild-std is required for latest NDK: https://github.com/rust-windowing/android-ndk-rs/pull/189
  cargo +nightly-2022-04-04 apk run --lib -Zbuild-std
else
  cargo +nightly-2022-04-04 apk build --lib -Zbuild-std
fi
