#!/usr/bin/env bash

set -eou pipefail

# export PYTHON=python3.11
# export PYTHON_PACKAGE=python3.11
# export RUST_TOOLCHAIN=nightly-2024-09-25
# export TARGET=x86_64-unknown-linux-gnu
# export VENV=.venv
# export CARGO_TARGET_DIR=/tmp/orjson

export VENV="${VENV:-.venv}"
export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-target}"

rm /etc/yum.repos.d/fedora-cisco-openh264.repo || true

dnf install --setopt=install_weak_deps=false -y rustup clang lld "${PYTHON_PACKAGE}"

rustup-init --default-toolchain "${RUST_TOOLCHAIN}-${TARGET}" --profile minimal --component rust-src -y
source "${HOME}/.cargo/env"

mkdir -p .cargo
cp ci/config.toml .cargo/config.toml

cargo fetch --target="${TARGET}" &

curl -LsSf https://astral.sh/uv/install.sh | sh
rm -rf "${VENV}"
uv venv --python "${PYTHON}" "${VENV}"
source "${VENV}/bin/activate"

uv pip install --upgrade "maturin>=1,<2" -r test/requirements.txt -r integration/requirements.txt
