Skip to content

Commit 1007394

Browse files
committed
Refactor Makefile tool defaults and helper targets
1 parent 290202f commit 1007394

File tree

1 file changed

+108
-59
lines changed

1 file changed

+108
-59
lines changed

Makefile

Lines changed: 108 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,139 @@
11
# Define the shell
22
SHELL := /bin/bash
3-
4-
# --- Variables ---
5-
UV := uv
6-
SCARB := scarb
7-
CARGO := cargo
3+
.SHELLFLAGS := -e -o pipefail -c
4+
MAKEFLAGS += --no-builtin-rules --no-builtin-variables
5+
.DEFAULT_GOAL := all
6+
7+
# --- Tools (override via env) ---
8+
UV ?= uv
9+
SCARB ?= scarb
10+
CARGO ?= cargo
11+
MDBOOK ?= mdbook
12+
DOCKER ?= docker
13+
14+
# --- Paths ---
15+
VENV_BIN := .venv/bin
16+
CAIRO_FORMAT := $(VENV_BIN)/cairo-format
17+
18+
# Docker
19+
DOCKER_TAG ?= hdp-cairo
20+
DOCKER_TTY := $(shell if [ -t 1 ]; then echo "-t"; fi)
21+
DOCKER_RUN_FLAGS ?= --rm -i $(DOCKER_TTY)
822

923
# Directories to remove on 'clean'
1024
CLEAN_DIRS := .venv db
1125

1226
# --- Targets ---
27+
.PHONY: all help setup venv versions rust-check \
28+
fmt fmt-check rust-fmt rust-fmt-check scarb-fmt scarb-fmt-check cairo-fmt cairo-fmt-check \
29+
clippy lint check dev ci future-incompat \
30+
build build-release scarb-build scarb-build-tests \
31+
test test-stable test-all-features test-nextest test-cargo \
32+
docs-build docs-serve \
33+
docker-build docker-run \
34+
clean
35+
36+
all: clean setup build test ## Clean, setup, build, test
37+
38+
help: ## Show this help
39+
@awk 'BEGIN {FS = ":.*##"; printf "\nAvailable commands:\n"} \
40+
/^[a-zA-Z0-9][a-zA-Z0-9_-]*:.*##/ { printf " %-24s %s\n", $$1, $$2 } \
41+
END { printf "\n" }' $(MAKEFILE_LIST)
42+
43+
versions: ## Show toolchain versions
44+
@rustc --version
45+
@$(CARGO) --version
46+
@$(SCARB) --version
47+
@$(UV) --version
48+
49+
setup: ## Sync Python deps and check Rust
50+
@echo "--- Setting up environment: uv sync + cargo check ---"
51+
$(UV) sync
52+
$(CARGO) check --workspace --all-targets
53+
54+
venv: $(CAIRO_FORMAT) ## Ensure Cairo0 tooling installed
55+
56+
rust-check: ## Cargo check workspace
57+
$(CARGO) check --workspace --all-targets
1358

14-
# Ensure these targets are always run, even if files with these names exist
15-
.PHONY: all setup build test clean help
59+
build: scarb-build build-release ## Build Scarb + Rust (release)
1660

17-
# Default target: running 'make' will default to 'make all'
18-
all: clean setup build test
61+
build-release: ## Cargo build release
62+
$(CARGO) build --release
63+
64+
scarb-build: ## Scarb build
65+
$(SCARB) build
1966

20-
# --- Quality gates (stable default + optional nightly/STWO lane) ---
67+
scarb-build-tests: ## Scarb build tests package
68+
$(SCARB) build -p tests
2169

22-
.PHONY: fmt fmt-check clippy test-stable test-all-features future-incompat check dev lint
70+
fmt: rust-fmt scarb-fmt cairo-fmt ## Format Rust, Cairo1, Cairo0
71+
fmt-check: rust-fmt-check scarb-fmt-check cairo-fmt-check ## Check formatting
2372

24-
fmt:
73+
rust-fmt: ## Format Rust
2574
$(CARGO) fmt --all
2675

27-
fmt-check:
76+
rust-fmt-check: ## Check Rust formatting
2877
$(CARGO) fmt --all -- --check
2978

79+
scarb-fmt: ## Format Cairo1 with Scarb
80+
$(SCARB) fmt
81+
82+
scarb-fmt-check: ## Check Cairo1 formatting with Scarb
83+
$(SCARB) fmt --check
84+
85+
$(CAIRO_FORMAT): pyproject.toml uv.lock
86+
$(UV) sync
87+
88+
cairo-fmt: $(CAIRO_FORMAT) ## Format Cairo0 in src/
89+
$(CAIRO_FORMAT) -i src/*.cairo
90+
91+
cairo-fmt-check: $(CAIRO_FORMAT) ## Check Cairo0 formatting in src/
92+
$(CAIRO_FORMAT) -c src/*.cairo
93+
3094
# Stable-by-default clippy: do NOT use --all-features because `stwo` pulls nightly-only deps.
31-
clippy:
95+
clippy: ## Run clippy (workspace, all targets)
3296
$(CARGO) clippy --workspace --all-targets -- -D warnings
3397

34-
# Default tests (stable-compatible). Integration tests are ignored by default.
35-
test-stable:
98+
lint: fmt-check clippy ## Run format checks + clippy
99+
100+
check: fmt-check clippy test-stable ## Run format checks, clippy, tests
101+
102+
dev: fmt clippy test-stable ## Format, clippy, and run tests
103+
104+
ci: fmt-check clippy test-stable ## CI-friendly checks
105+
106+
test: scarb-build-tests test-nextest ## Build Scarb tests + run nextest
107+
108+
test-nextest: ## Run cargo nextest
109+
$(CARGO) nextest run --no-fail-fast
110+
111+
test-cargo: ## Run cargo tests (workspace)
36112
$(CARGO) test --workspace --all-targets
37113

38-
# All-features tests run through the unified nightly toolchain.
39-
test-all-features:
40-
$(CARGO) test --workspace --all-targets --all-features
114+
test-stable: test-cargo ## Run stable-compatible tests
41115

42-
# One-shot check: stable lane only (fast + deterministic).
43-
check: fmt-check clippy test-stable
116+
test-all-features: ## Run tests with all features
117+
$(CARGO) test --workspace --all-targets --all-features
44118

45-
# Track future-incompatibility warnings reported by Rust (non-fatal today, fatal in future toolchains).
46-
future-incompat:
119+
future-incompat: ## Show Rust future-incompat report
47120
$(CARGO) report future-incompatibilities
48121

49-
# Development workflow
50-
dev: fmt clippy test-stable
51-
@echo "--- Development checks passed ---"
122+
docs-build: ## Build mdBook docs
123+
$(MDBOOK) build docs
52124

53-
# Full lint
54-
lint: fmt-check clippy
55-
@echo "--- All lint checks passed ---"
125+
docs-serve: ## Serve mdBook docs
126+
$(MDBOOK) serve docs
56127

57-
# Setup the environment: sync Python deps and check Rust code
58-
setup:
59-
@echo "--- 🚀 Setting up environment: Syncing Python dependencies and checking Rust code ---"
60-
$(UV) sync
61-
$(CARGO) check
128+
docker-build: ## Build Docker image (DOCKER_TAG=hdp-cairo)
129+
$(DOCKER) build -t $(DOCKER_TAG) .
62130

63-
# Build the projects in release mode
64-
build:
65-
@echo "--- 🏗️ Building projects (Release): Scarb and Cargo ---"
66-
$(SCARB) build
67-
$(CARGO) build --release
68-
69-
# Run tests
70-
test:
71-
@echo "--- 🧪 Running tests: Building Scarb tests and running Cargo nextest ---"
72-
$(SCARB) build -p tests
73-
$(CARGO) nextest run --no-fail-fast
131+
docker-run: ## Run Docker image (DOCKER_TAG=hdp-cairo)
132+
$(DOCKER) run $(DOCKER_RUN_FLAGS) $(DOCKER_TAG) --help
74133

75-
# Clean up artifacts, virtual environments, and caches
76-
clean:
77-
@echo "--- 🧹 Cleaning up: Removing build artifacts, venv, db, and caches ---"
134+
clean: ## Remove build artifacts and caches
135+
@echo "--- Cleaning: build artifacts, venv, db, and caches ---"
78136
rm -rf $(CLEAN_DIRS)
79137
$(UV) cache clean
80-
$(CARGO) clean
81-
82-
# Self-documenting help target
83-
help:
84-
@echo "Available commands:"
85-
@echo " make setup - Sync Python 'uv' environment and check Rust code."
86-
@echo " make build - Build the Scarb and Rust projects (release mode). (Default)"
87-
@echo " make test - Run 'setup' then build Scarb tests and run Rust tests."
88-
@echo " make future-incompat - Show Rust future-incompatibility report (helps address warnings like 'size-of')."
89-
@echo " make clean - Remove build artifacts, .venv, db, and clean caches."
90-
@echo " make all - Alias for 'make build'."
138+
$(SCARB) clean
139+
$(CARGO) clean

0 commit comments

Comments
 (0)