.PHONY: all uv rust deps lint test bench build build-wheel build-sdist

all: deps lint test

UV_EXTRA_ARGS ?=

uv:
	@which uv >/dev/null 2>&1 || { \
		echo "uv is not installed"; \
		exit 1;\
	}

rust:
	@which cargo >/dev/null 2>&1 || { \
		echo "Rust is not installed"; \
		exit 1;\
	}

deps: uv rust
	@uv sync --extra dev
	@uv run maturin develop --release

lint: deps
ifeq ($(MODE), ci)
	@uv run $(UV_EXTRA_ARGS) ruff format python/promrs tests --check
	@uv run $(UV_EXTRA_ARGS) ruff check python/promrs tests
	@uv run $(UV_EXTRA_ARGS) pyright
	@cargo fmt --check
	@cargo clippy
else
	@uv run $(UV_EXTRA_ARGS) ruff format python/promrs tests
	@uv run $(UV_EXTRA_ARGS) ruff check python/promrs tests --fix
	@uv run $(UV_EXTRA_ARGS) pyright
	@cargo fmt
	@cargo clippy
endif

test: deps
	@uv run $(UV_EXTRA_ARGS) pytest -vv $(or $(T),.)

bench: deps
	@uv run python benchmarks/bench.py

build: deps
	@uv run maturin build --release

build-wheel: deps
	@uv run maturin build --release --out dist

build-sdist: deps
	@uv run maturin sdist --out dist
