Skip to content

Instantly share code, notes, and snippets.

@cjlarsen
Created March 24, 2024 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjlarsen/9c23685f72fe7b80825388e7205494a1 to your computer and use it in GitHub Desktop.
Save cjlarsen/9c23685f72fe7b80825388e7205494a1 to your computer and use it in GitHub Desktop.
Rust Makefile Example
SHELL := /bin/bash
PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
clean: ## Clean the project using cargo
cargo clean
build: ## Build the project using cargo
cargo build
run: ## Run the project using cargo
cargo run
lint: ## Run clippy on the project
@rustup component add clippy 2> /dev/null
cargo clippy
format: ## Run rustfmt on the project
@rustup component add rustfmt 2> /dev/null
cargo fmt
test: ## Run the tests using cargo
cargo test
doc: ## Generate the documentation using cargo
cargo doc
bump: ## Bump the version of the project
@echo "Current version is $(shell cargo pkgid | cut -d# -f2)"
@read -p "Enter the new version: " version; \
updated_version=$$(cargo pkgid | cut -d# -f2 | sed -E "s/([0-9]+\.[0-9]+\.[0-9]+)$$/$$version/"); \
sed -i -E "s/version = .*/version = \"$$updated_version\"/" Cargo.toml
@echo "Updated version is $(shell cargo pkgid | cut -d# -f2)"%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment