#!/bin/sh
# Run a run_rustc make target inside the Alpine devfs sandbox (musl, 256-TLS loader, gcc).
# Usage: run-runrustc.sh <make-target> [extra make args...]
set -eu
ROOT=/home/sergio/hammer
DEVFS=$ROOT/.dev-fs/alpine
MRUSTC=$ROOT/.scratch/mrustc
TARGET=${1:?make target required}
shift || true

exec bwrap \
  --bind "$DEVFS" / \
  --bind "$MRUSTC" /mrustc \
  --dev /dev --proc /proc \
  --tmpfs /tmp --tmpfs /run \
  --setenv PATH /usr/bin:/bin:/usr/sbin:/sbin \
  --setenv HOME /root \
  --setenv TMPDIR /tmp \
  --setenv MRUSTC_TARGET_VER 1.90 \
  --setenv CC gcc --setenv CXX g++ \
  --chdir /mrustc/run_rustc \
  make RUSTC_VERSION=1.90.0 OUTDIR_SUF=-1.90.0-x86_64-unknown-linux-musl \
       RUSTC_TARGET=x86_64-unknown-linux-musl PARLEVEL=8 \
       "$TARGET" "$@"
