set -ex

which podman &>/dev/null && docker=podman || docker=docker

mkdir -p empty
$docker build -t nv-rs-build --network=host -f Dockerfile.build empty

case $1 in
  release)
    opts=--release
    bindir=target/release
    ;;
  "")
    bindir=target/debug
    ;;
  *)
    echo >&2 "invalid arg: $1"
    exit 1
    ;;
esac

$docker run --rm -i --net=host --user=$UID \
    nv-rs-build \
    cargo build $opts

mkdir -p dist
cp $bindir/init dist/
