.PHONY: dev test pub clean

BUMP ?= patch
PYVER := $(shell uv run python -c "import sys; print(f'python3.{sys.version_info.minor}')")

dev:
	uv run maturin develop --release

test:
	cargo test
	uv run pytest

# Publish. Bumps patch by default.
#   make pub              # 0.1.0 -> 0.1.1
#   make pub BUMP=minor   # 0.1.0 -> 0.2.0
#   make pub V=0.2.0      # explicit version
pub:
	@test -f .pypirc || (echo "Missing .pypirc" && exit 1)
	@test -f .cargo-credentials || (echo "Missing .cargo-credentials" && exit 1)
	git add .
	git commit -m "new version"
	$(if $(V),uv run bump-my-version bump --new-version $(V) patch,uv run bump-my-version bump $(BUMP))
	rm -rf dist/
	uv run maturin build --release --zig --target x86_64-unknown-linux-gnu  --manylinux 2_17 --out dist/
	uv run maturin build --release --zig --target aarch64-unknown-linux-gnu --manylinux 2_17 --out dist/ -i $(PYVER)
	uv run maturin sdist --out dist/
	uv add --dev twine
	uv run twine upload -r coren --config .pypirc dist/*
	cargo publish --token "$$(grep '^token' .cargo-credentials | sed 's/.*= *"\(.*\)"/\1/')"
	git push origin main --tags

clean:
	cargo clean
	rm -rf dist/ .venv/ *.egg-info/
