PROJ_REPO := github.com/habedi/spart
BINARY_NAME := $(or $(PROJ_BINARY), $(notdir $(PROJ_REPO)))
BINARY = :target/release/$(BINARY_NAME)
PATH := /snap/bin:$(PATH)
RUST_BACKTRACE := 0
DEBUG_SPART := 0
RUST_LOG := info
WHEEL_DIR := dist
PYSPART_DIR := pyspart
PY_DEP_MNGR := uv
WHEEL_FILE := $(shell ls $(PYSPART_DIR)/$(WHEEL_DIR)/pyspart-*.whl 2>/dev/null | head -n 1)
.DEFAULT_GOAL := help
.PHONY: help
help:
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@grep -E '^[a-zA-Z_-]+:.*## .*$$' Makefile | \
awk 'BEGIN {FS = ":.*## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
.PHONY: format
format:
@echo "Formatting Rust files..."
@cargo fmt
.PHONY: test
test: format
@echo "Running tests..."
@DEBUG_SPART=$(DEBUG_SPART) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo test -- --nocapture
.PHONY: coverage
coverage: format
@echo "Generating test coverage report..."
@DEBUG_SPART=$(DEBUG_SPART) cargo tarpaulin --out Xml --out Html
.PHONY: build
build: format
@echo "Building the project..."
@DEBUG_SPART=$(DEBUG_SPART) cargo build --release
.PHONY: run
run: build
@echo "Running the $(BINARY) binary..."
@DEBUG_SPART=$(DEBUG_SPART) ./$(BINARY)
.PHONY: run-examples
run-examples: build
@echo "Running Rust examples..."
@cargo run --example quadtree
@cargo run --example octree
@cargo run --example kdtree
@cargo run --example rtree
.PHONY: run-py-examples
run-py-examples: develop-py
@echo "Running Python examples..."
@bash -c "source .venv/bin/activate && python pyspart/examples/quadtree.py"
@bash -c "source .venv/bin/activate && python pyspart/examples/octree.py"
@bash -c "source .venv/bin/activate && python pyspart/examples/kdtree.py"
@bash -c "source .venv/bin/activate && python pyspart/examples/rtree.py"
@bash -c "source .venv/bin/activate && python pyspart/examples/rstar_tree.py"
.PHONY: clean
clean:
@echo "Cleaning up..."
@cargo clean
@rm -rf $(WHEEL_DIR) dist/ $(PYSPART_DIR)/$(WHEEL_DIR) $(PYSPART_DIR)/*.so $(PYSPART_DIR)/target
.PHONY: install-snap
install-snap:
@echo "Installing the snap package..."
@sudo apt-get update
@sudo apt-get install -y snapd
@sudo snap refresh
@sudo snap install rustup --classic
.PHONY: install-deps
install-deps: install-snap
@echo "Installing dependencies..."
@rustup component add rustfmt clippy
@cargo install cargo-tarpaulin
@cargo install --locked cargo-nextest --version 0.9.97-b.2
@sudo apt-get install -y python3-pip
@pip install $(PY_DEP_MNGR)
.PHONY: lint
lint: format
@echo "Linting Rust files..."
@DEBUG_SPART=$(DEBUG_SPART) cargo clippy -- -D warnings
.PHONY: publish
publish:
@echo "Publishing the package to Cargo registry..."
@cargo publish --token $(CARGO_REGISTRY_TOKEN)
.PHONY: bench
bench:
@echo "Running benchmarks..."
@DEBUG_SPART=$(DEBUG_SPART) cargo bench
.PHONY: audit
audit:
@echo "Running security audit..."
@cargo audit
.PHONY: nextest
nextest:
@echo "Running tests using nextest..."
@DEBUG_SPART=$(DEBUG_SPART) RUST_BACKTRACE=$(RUST_BACKTRACE) cargo nextest run
.PHONY: docs
docs: format
@echo "Generating documentation..."
@cargo doc --no-deps --document-private-items
.PHONY: fix-lint
fix-lint:
@echo "Fixing linter warnings..."
@cargo clippy --fix --allow-dirty --allow-staged --all-targets --workspace --all-features -- -D warnings
.PHONY: develop-py
develop-py:
@echo "Building and installing PySpart..."
@bash -c "source .venv/bin/activate && cd $(PYSPART_DIR) && unset CONDA_PREFIX && maturin develop"
.PHONY: wheel
wheel:
@echo "Building the PySpart wheel..."
@(cd $(PYSPART_DIR) && maturin build --release --out $(WHEEL_DIR) --auditwheel check)
.PHONY: wheel-manylinux
wheel-manylinux:
@echo "Building the manylinux PySpart wheel..."
@(cd $(PYSPART_DIR) && maturin build --release --out $(WHEEL_DIR) --auditwheel check --zig)
.PHONY: test-py
test-py: develop-py
@echo "Running Python tests..."
@bash -c "source .venv/bin/activate && pytest"
.PHONY: publish-py
publish-py: wheel-manylinux
@echo "Publishing PySpart to PyPI..."
@if [ -z "$(WHEEL_FILE)" ]; then \
echo "Error: No wheel file found. Please run 'make wheel' first."; \
exit 1; \
fi
@echo "Found wheel file: $(WHEEL_FILE)"
@twine upload -u __token__ -p $(PYPI_TOKEN) $(WHEEL_FILE)
.PHONY: generate-ci
generate-ci:
@echo "Generating CI configuration files..."
@(cd $(PYSPART_DIR) && maturin generate-ci --zig --pytest --platform all -o ../.github/workflows/ci.yml github)
.PHONY: setup-hooks
setup-hooks:
@echo "Installing Git hooks..."
@pre-commit install --hook-type pre-commit
@pre-commit install --hook-type pre-push
@pre-commit install-hooks
.PHONY: test-hooks
test-hooks:
@echo "Testing Git hooks..."
@pre-commit run --all-files