#!/usr/bin/env bash # Run a command inside the DarkRoom Android build container. # # ./docker/android/build.sh cargo ndk -t arm64-v8a build --release # ./docker/android/build.sh cargo check --target aarch64-linux-android # ./docker/android/build.sh # interactive shell # # Builds the image on first use. Rebuild after editing the Dockerfile with: # ./docker/android/build.sh --rebuild set -euo pipefail IMAGE="darkroom-android:latest" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO="$(cd "${HERE}/../.." && pwd)" # Prefer podman (rootless by default); fall back to docker. if command -v podman >/dev/null 2>&1; then ENGINE=podman elif command -v docker >/dev/null 2>&1; then ENGINE=docker else echo "error: neither podman nor docker found" >&2 exit 1 fi if [[ "${1:-}" == "--rebuild" ]]; then shift "${ENGINE}" build -t "${IMAGE}" "${HERE}" elif ! "${ENGINE}" image exists "${IMAGE}" 2>/dev/null && \ ! "${ENGINE}" image inspect "${IMAGE}" >/dev/null 2>&1; then echo "==> building ${IMAGE} (first run; several minutes)" "${ENGINE}" build -t "${IMAGE}" "${HERE}" fi # Persist the cargo registry and target dir across runs, or every build # re-downloads the crate index. CACHE="${XDG_CACHE_HOME:-${HOME}/.cache}/darkroom-android" mkdir -p "${CACHE}/registry" "${CACHE}/target" ARGS=( --rm -v "${REPO}:/work:z" -v "${CACHE}/registry:/opt/cargo/registry:z" -v "${CACHE}/target:/work/target-android:z" -e CARGO_TARGET_DIR=/work/target-android -w /work ) # Rootless podman already maps the host user; docker needs it stated. if [[ "${ENGINE}" == "docker" ]]; then ARGS+=(--user "$(id -u):$(id -g)") fi if [[ $# -eq 0 ]]; then ARGS+=(-it) set -- /bin/bash fi exec "${ENGINE}" run "${ARGS[@]}" "${IMAGE}" "$@"