#!/usr/bin/env bash
# Build and run the exporter against the disc.
#
#   build-export              build only
#   build-export --run        build, then export to ./export
#
# Jobs are capped: this box runs two agent containers and a desktop, and an
# unbounded parallel build has crashed it. Do not raise this to "use all cores".
set -euo pipefail
cd "${PROJECT_DIR:-/work}"
export CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-3}"
cargo build --release -p sylpheed-export
if [ "${1:-}" = "--run" ]; then
  shift
  disc="${SYLPHEED_DISC:?set SYLPHEED_DISC to the extracted disc root}"
  exec "$CARGO_TARGET_DIR/release/sylpheed-export" --disc "$disc" --out export "$@"
fi
