#!/bin/sh
# =============================================================================
# freebsd-setup.sh — runs INSIDE the FreeBSD VM (vmactions/freebsd-vm `prepare`).
# =============================================================================
# Role: install the Rust toolchain (+ this crate's system deps, if any).
# Portability: /bin/sh on FreeBSD (no bashisms). Use [ ], case, parameter
# expansion only.
# =============================================================================
set -eu

# --- Rust toolchain -------------------------------------------------------
# MSRV floor is 1.85 (Cargo.toml `rust-version`). Stable satisfies it.
# A fresh FreeBSD image ships only `fetch`, not curl; rustup-init is fetched
# via curl, so install curl + CA roots first (idempotent, cheap).
# `--profile default` bundles clippy + rustfmt (rustup-init's `--component`
# flag takes one value per flag; `--component clippy rustfmt` is rejected).
if ! command -v cargo >/dev/null 2>&1; then
  echo "installing rustup + stable toolchain..."
  command -v curl >/dev/null 2>&1 || pkg install -y curl ca_root_nss
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
    | sh -s -- -y --profile default
fi

# Source cargo env so this shell (and the subsequent `run` step) see cargo.
if [ -f "$HOME/.cargo/env" ]; then
  # shellcheck disable=SC1091
  . "$HOME/.cargo/env"
fi

echo "rustc: $(rustc --version)"
echo "cargo: $(cargo --version)"

# --- This crate's system dependencies -------------------------------------
# audio-plugin-bsd: capsicum + pdfork are pure-Rust crates that bind FreeBSD
# libc syscalls (pdfork, cap_enter, cap_rights_limit, socketpair).
# They pull in NO FreeBSD ports / system libraries — only libc, which FreeBSD
# ships in base. Therefore 0 system deps are required here.
# If a future version links a FreeBSD system library, add it here, e.g.:
#   pkg install -y alsa-lib   # for an ALSA/OSS backend
#   pkg install -y opus       # for libopus FFI

echo "setup: ok"
