PKG = github.com/habedi/template-rust-project
BINARY_NAME = $(or $(PROJ_BINARY), $(notdir $(PKG)))
BINARY = target/release/$(BINARY_NAME)
PATH := /snap/bin:$(PATH)
.DEFAULT_GOAL := help
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: format
format:
@echo "Formatting Rust files..."
cargo fmt
.PHONY: test
test: format
@echo "Running tests..."
cargo test -- --nocapture
.PHONY: coverage
coverage: format
@echo "Generating test coverage report..."
cargo tarpaulin --out Xml --out Html
.PHONY: build
build: format
@echo "Building the project..."
cargo build --release
.PHONY: run
run: build
@echo "Running the $(BINARY) binary..."
./$(BINARY)
.PHONY: clean
clean:
@echo "Cleaning up..."
cargo clean
.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
.PHONY: lint
lint: format
@echo "Linting Rust files..."
cargo clippy -- -D warnings
.PHONY: publish
publish:
@echo "Publishing the package to Cargo registry..."
cargo publish --token $(CARGO_REGISTRY_TOKEN)