#!/usr/bin/env bash

# Parse command line arguments.
target=''
getopt=$(getopt --options=wsh --longoptions=windows,strict,help -- "$@") || exit
eval set -- "$getopt"
while true; do
    case "$1" in
        -w|--windows)
            target='--target=x86_64-pc-windows-gnu'
            shift
            ;;
        -s|--strict)
            export RUSTFLAGS='-D warnings'
            shift
            ;;
        -h|--help)
            cat <<EOF
Build Rust debug and release target
Syntax: $(basename "$0") [options]
  -w|--windows ... Build for Windows
  -s|--strict .... Warnings as errors
  -h|--help ...... Show help text
EOF
            exit 1
            ;;
        --)
            shift
            break
            ;;
        *)
            exit 1
            ;;
    esac
done

# Build Rust debug and release target.
if test -z "$target"; then
    cargo build $target || exit
fi
cargo build $target --release || exit
