#!/usr/bin/env bash # Run a command inside the DarkRoom macOS link-check container. # # ./docker/macos/build.sh cargo zigbuild --target aarch64-apple-darwin -p dr-inference-engine --all-targets # ./docker/macos/build.sh # interactive shell # # Builds the image on first use; `--rebuild` after editing the Dockerfile. set -euo pipefail IMAGE="darkroom-macos:latest" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO="$(cd "${HERE}/../.." && pwd)" 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 inspect "${IMAGE}" >/dev/null 2>&1; then echo "==> building ${IMAGE} (first run; a few minutes)" "${ENGINE}" build -t "${IMAGE}" "${HERE}" fi # Registry, target and zig's own cache persist across runs. CACHE="${XDG_CACHE_HOME:-${HOME}/.cache}/darkroom-macos" mkdir -p "${CACHE}/registry" "${CACHE}/target" "${CACHE}/home" ARGS=( --rm -v "${REPO}:/work:z" -v "${CACHE}/registry:/opt/cargo/registry:z" -v "${CACHE}/target:/work/target-macos:z" -v "${CACHE}/home:/tmp/home:z" -e HOME=/tmp/home -e CARGO_TARGET_DIR=/work/target-macos -w /work ) # Capped for the same reason as the Windows image: a cross build otherwise # takes every thread on the host. JOBS="${DARKROOM_BUILD_JOBS:-8}" if [[ "${JOBS}" != "0" ]]; then ARGS+=(--cpus "${JOBS}" -e "CARGO_BUILD_JOBS=${JOBS}") fi 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}" "$@"