Skip to content

Instantly share code, notes, and snippets.

@arnauorriols
Created July 29, 2021 23:34
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 arnauorriols/dc60e089cd3a1da1355726cd1d019753 to your computer and use it in GitHub Desktop.
Save arnauorriols/dc60e089cd3a1da1355726cd1d019753 to your computer and use it in GitHub Desktop.
Rust one-stop Makefile
SHELL := /bin/bash -O globstar
# built-in targets
.PHONY: help run build build-dev test profile profile-build profiles-dir docs bench setup-bench open-bench save-bench format lint megalint typecheck check pre-commit all fix-vscode fix-perm todo
.DEFAULT_GOAL := help
# targets
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
run: ## Run CLI
cargo run --release
build: ## Build for production
cargo build --locked --release
build-dev: ## Build in dev-mode (faster to build, slower to run)
cargo build
test: ## Run tests (and doc examples as tests!)
cargo test -- $(FILTER) $(ARGS)
profile: build profiles-dir ## Build and run in release mode with profiling activated
ifdef SHIELD
cset shield --exec -- perf record -F 999 --call-graph "dwarf,16384" target/release/cli fixtures/example-1000000.txt
else
perf record -F 999 --call-graph "dwarf,16384" target/release/cli fixtures/example-1000000.txt
endif
$(eval filename=$(shell git rev-parse --short HEAD).$(shell date +%Y%m%d%H%M%S).perf.text)
perf script > profiles/${filename}
rm -f perf.data*
xdg-open https://profiler.firefox.com
@echo -------
@echo profile generated: profiles/${filename}
profile-build: profiles-dir ## Profile the compilation time
cargo +nightly build -Ztimings
$(eval filename=$(shell git rev-parse --short HEAD).$(shell date +%Y%m%d%H%M%S).cargo-timing.html)
mv cargo-timing.html profiles/${filename}
rm -f cargo-timing*.html
xdg-open profiles/${filename}
profiles-dir: ## Create profiles dir if missing
mkdir -p profiles
docs: ## Build the docs
cargo doc --no-deps --open
bench: ## Run benchmarks and generate HTML report
ifdef SHIELD
cset shield --exec -- cargo bench $(FILTER) -- $(ARGS)
else
cargo bench $(FILTER) -- $(ARGS)
endif
setup-bench: ## Prepare the machine for running benchmarks
echo 0 > /proc/sys/kernel/randomize_va_space
# TODO: iterate over actual CPUs
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo
cset shield -c 2,3 -k on
open-bench: ## Open benchmark's HTML report in browser
ifdef NAME
xdg-open benchmarks/${NAME}/report/index.html
else
xdg-open target/criterion/report/index.html
endif
save-bench: ## Save benchmark outside of target
ifndef NAME
$(error NAME variable is required)
endif
mkdir -p benchmarks/${NAME}
mv target/criterion/* benchmarks/${NAME}/
format: ## Format source code
cargo fmt
lint: ## Run the linter(s)
touch **/*.rs && cargo clippy --all-features
megalint: ## Run the linter with the maximum strictness possible
touch **/*.rs && cargo rustc --all-features --lib -- -Dunused -Dfuture-incompatible -Drust-2018-idioms -Dwarnings -Dnonstandard-style && cargo clippy --all-features -- -D clippy::all -D clippy::pedantic
typecheck: ## Run type checker
cargo check
check: typecheck ## Alias of typecheck
pre-commit: format typecheck lint ## Run this command before every commit
all: pre-commit ## I'm feeling lucky
fix-vscode: ## Reset RLS to fix VScode going wild from time to time
pkill rls -e
fix-perm: ## Set permissions of all files to USER
chown -R ${USER}: .
todo: ## find all TODO flags in source code
grep -nR TODO src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment