#!/usr/bin/env bash
# Workaround for https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
# Invoke this like: ./bin/benchmark-criterion -p foo -- --save-baseline my_baseline
# Any arguments after the "--" will _only_ be passed to criterion binaries.
set -euo pipefail
SCRIPT_DIR=$(dirname "$0")
cd "${SCRIPT_DIR}"/..
declare -a CARGO_ARGS
while [[ "${1:-}" != "--" ]] && (! [[ -z "${1:-}" ]]); do
    CARGO_ARGS+=("$1")
    shift 1
done
if [[ "${1:-}" == "--" ]]; then
    shift 1
fi
export LIBSIGNAL_BENCHMARK_ARGS="$@"
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="$PWD/bin/benchmark-criterion-helper.sh"
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="$PWD/bin/benchmark-criterion-helper.sh"
export CARGO_TARGET_AARCH64_APPLE_DARWIN_RUNNER="$PWD/bin/benchmark-criterion-helper.sh"
exec cargo bench "${CARGO_ARGS[@]}"
