-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
347 lines (306 loc) · 13.9 KB
/
Makefile
File metadata and controls
347 lines (306 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# Poly-Bench Development Makefile
# ================================
# Quick commands for local development and CI
.PHONY: help check check-compile build build-debug watch release release-minor release-major _release-run release-build release-both clean install-tools reload cli run \
cli-release init add install pb-build pb-run fmt fmt-check lint test test-cover oncommit install-hooks \
grammar grammar-wasm vscode-publish
# Default target
help:
@echo "Poly-Bench Development Commands"
@echo "================================"
@echo ""
@echo "CI / quality:"
@echo " make fmt - Format code"
@echo " make fmt-check - Check formatting (CI)"
@echo " make lint - Clippy (CI)"
@echo " make test - Run tests"
@echo " make test-cover - Run tests with coverage"
@echo " make check - fmt-check + lint + test"
@echo " make build - Release build of poly-bench (single binary)"
@echo ""
@echo "Development:"
@echo " make check-compile - Fast compile check (no binary)"
@echo " make cli - Debug build of poly-bench"
@echo " make cb - Check + debug build"
@echo " make watch - Auto-rebuild on changes"
@echo ""
@echo "CLI (Debug):"
@echo " make cli - Build the poly-bench CLI (debug)"
@echo " make run - Run poly-bench CLI (use ARGS for arguments)"
@echo " Example: make run ARGS='run examples/simple'"
@echo ""
@echo "CLI (Release - Production):"
@echo " make cli-release - Build optimized poly-bench CLI"
@echo " make init - poly-bench init (NAME=<name> [DIR=<parent>])"
@echo " make add - poly-bench add (requires PROJECT=<dir>)"
@echo " make install - poly-bench install (requires PROJECT=<dir>)"
@echo " make pb-build - poly-bench build (requires PROJECT=<dir>)"
@echo " make pb-run - poly-bench run (requires PROJECT=<dir>)"
@echo ""
@echo " Example workflow:"
@echo " make init NAME=my-bench"
@echo " make init NAME=demo DIR=examples"
@echo " make pb-build PROJECT=examples/demo"
@echo " make pb-run PROJECT=examples/demo"
@echo ""
@echo "Release:"
@echo " make release - Default release (minor bump from Cargo.toml)"
@echo " make release-minor - Minor bump + tag + prerelease + PR to production"
@echo " make release-major - Major bump + tag + prerelease + PR to production"
@echo " make release VERSION=vX.Y.Z - Legacy explicit release version override"
@echo " make release-build - Build single release binary (poly-bench)"
@echo " make release-both - Build poly-bench (compatibility alias)"
@echo " make vscode-publish - Publish VSCode extension to marketplace (requires VSCE_PAT)"
@echo ""
@echo "Utilities:"
@echo " make clean - Clean build artifacts"
@echo " make install-tools - Install cargo-watch"
@echo " make install-hooks - Install git pre-push hook"
@echo ""
@echo "After building, reload VS Code for LSP: Cmd+Shift+P → 'Developer: Reload Window'"
# ============================================================================
# CI / quality targets
# ============================================================================
# Format all workspace Rust (examples/ has no crates, so not formatted)
fmt:
@cargo +nightly fmt --all
fmt-check:
@cargo +nightly fmt --all -- --check
lint:
@cargo clippy --all-targets -- -D warnings
test:
@cargo test --all
test-cover:
@cargo test --all --no-run 2>/dev/null || true
@cargo test --all
# Full check: formatting + lint + test (CI)
check: fmt-check lint test
@echo "==> All checks passed!"
# Install git hooks for pre-push checks
install-hooks:
@echo "Installing git hooks..."
@cp .github/hooks/pre-push .git/hooks/pre-push
@chmod +x .git/hooks/pre-push
@echo "==> Git hooks installed!"
# Release build: single binary (poly-bench includes LSP via 'poly-bench lsp')
build: cli-release
# Fast compile check (no binary output)
check-compile:
@echo "🔍 Checking for compile errors..."
@cargo check --bin poly-bench
@echo "✅ No errors!"
# Debug build (fast, unoptimized)
build-debug:
@echo "🔨 Building poly-bench (debug)..."
@cargo build --bin poly-bench
@echo "✅ Done! Binary at: target/debug/poly-bench"
# Check then build (common workflow)
cb: check-compile build-debug
# Build the poly-bench CLI (debug)
cli:
@echo "🔨 Building poly-bench CLI (debug)..."
@cargo build --bin poly-bench
@echo "✅ Done! Binary at: target/debug/poly-bench"
# Run the poly-bench CLI with arguments (debug)
# Usage: make run ARGS='run examples/simple'
run: cli
@./target/debug/poly-bench $(ARGS)
# ============================================================================
# Production CLI Commands (Release Build)
# ============================================================================
# These use the optimized release binary for actual benchmarking work.
# The release build is much faster and produces accurate timing results.
#
# Use PROJECT=<dir> to specify which project to operate on:
# make pb-build PROJECT=my-project
# make pb-run PROJECT=my-project
# ============================================================================
# Build the poly-bench CLI (release/production)
cli-release:
@printf "\033[36m[±]\033[0m Building poly-bench (release)...\r" && \
cargo build --release --bin poly-bench && \
printf "\033[32m[✓]\033[0m Built poly-bench (release) \n"
# poly-bench init
# Usage: make init NAME=my-project
# Usage: make init NAME=my-project DIR=examples
# Usage: make init NAME=. DIR=examples/demo ARGS='-l go'
init: cli-release
ifndef NAME
$(error Usage: make init NAME=<project-name> [DIR=<parent-dir>] [ARGS='...'])
endif
ifdef DIR
@cd $(DIR) && $(CURDIR)/target/release/poly-bench init $(NAME) $(ARGS)
else
@./target/release/poly-bench init $(NAME) $(ARGS)
endif
# poly-bench add
# Usage: make add PROJECT=my-project ARGS='--go github.com/pkg/errors@v0.9.1'
# Usage: make add PROJECT=my-project ARGS='--ts viem@^2.0.0'
add: cli-release
ifndef PROJECT
$(error Usage: make add PROJECT=<project-dir> ARGS='--go pkg@version')
endif
@cd $(PROJECT) && $(CURDIR)/target/release/poly-bench add $(ARGS)
# poly-bench install
# Usage: make install PROJECT=my-project
install: cli-release
ifndef PROJECT
$(error Usage: make install PROJECT=<project-dir>)
endif
@cd $(PROJECT) && $(CURDIR)/target/release/poly-bench install
# poly-bench build
# Usage: make pb-build PROJECT=my-project
pb-build: cli-release
ifndef PROJECT
$(error Usage: make pb-build PROJECT=<project-dir>)
endif
@cd $(PROJECT) && $(CURDIR)/target/release/poly-bench build $(ARGS)
# poly-bench run
# Usage: make pb-run PROJECT=my-project
# Usage: make pb-run PROJECT=my-project ARGS='--lang go'
pb-run: cli-release
ifndef PROJECT
$(error Usage: make pb-run PROJECT=<project-dir>)
endif
@cd $(PROJECT) && $(CURDIR)/target/release/poly-bench run $(ARGS)
# Watch for changes and auto-rebuild
watch:
@echo "👀 Watching for changes..."
@cargo watch -x "build --bin poly-bench"
# Optimized release build: single binary (poly-bench; use 'poly-bench lsp' for LSP)
release-build: cli-release
@echo "✅ Release binary: target/release/poly-bench"
# Build binary (compatibility alias retained)
release-both:
@echo "🔨 Building poly-bench (release)..."
@cargo build --release --bin poly-bench
@echo "✅ Done!"
@echo " CLI: target/release/poly-bench"
@echo " LSP command: target/release/poly-bench lsp"
# Release automation entrypoint:
# - make release-minor / make release-major (recommended)
# - make release VERSION=vX.Y.Z (legacy manual override)
release:
ifeq ($(strip $(VERSION)),)
@$(MAKE) release-minor VSCODE_VERSION="$(VSCODE_VERSION)"
else
@$(MAKE) _release-run VERSION="$(VERSION)" VSCODE_VERSION="$(VSCODE_VERSION)"
endif
# Bump Cargo semver minor and run release flow
release-minor:
@CURRENT=$$(node -e "const fs=require('fs');const m=fs.readFileSync('Cargo.toml','utf8').match(/^version = \"([0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?)\"/m);if(!m){console.error('Could not parse Cargo.toml version');process.exit(1)};process.stdout.write(m[1]);"); \
NEXT=$$(node -e "const v='$$CURRENT';const m=v.match(/^(\\d+)\\.(\\d+)\\.(\\d+)(?:-.+)?$$/);if(!m){console.error('Invalid semver: '+v);process.exit(1)};process.stdout.write('v'+m[1]+'.'+(Number(m[2])+1)+'.0');"); \
echo "==> Releasing minor version $$CURRENT -> $$NEXT"; \
$(MAKE) _release-run VERSION="$$NEXT" VSCODE_VERSION="$(VSCODE_VERSION)"
# Bump Cargo semver major and run release flow
release-major:
@CURRENT=$$(node -e "const fs=require('fs');const m=fs.readFileSync('Cargo.toml','utf8').match(/^version = \"([0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?)\"/m);if(!m){console.error('Could not parse Cargo.toml version');process.exit(1)};process.stdout.write(m[1]);"); \
NEXT=$$(node -e "const v='$$CURRENT';const m=v.match(/^(\\d+)\\.(\\d+)\\.(\\d+)(?:-.+)?$$/);if(!m){console.error('Invalid semver: '+v);process.exit(1)};process.stdout.write('v'+(Number(m[1])+1)+'.0.0');"); \
echo "==> Releasing major version $$CURRENT -> $$NEXT"; \
$(MAKE) _release-run VERSION="$$NEXT" VSCODE_VERSION="$(VSCODE_VERSION)"
# Shared release implementation: bump versions (Rust + VSCode extension), tag, prerelease, open PR to production
# Requires: gh CLI authenticated, on main branch
_release-run:
ifndef VERSION
$(error VERSION is required. Usage: make release VERSION=v0.0.1)
endif
@echo "==> Checking gh CLI authentication..."
@gh auth status || (echo "Error: Please run 'gh auth login' first" && exit 1)
@echo "==> Ensuring we're on main branch..."
@git checkout main
@git pull origin main
@echo "==> Bumping Cargo.toml to $(VERSION) and VSCode extension version independently..."
@VER=$$(echo $(VERSION) | sed 's/^v//'); \
EXT_VER_INPUT="$(VSCODE_VERSION)"; \
if [ -n "$$EXT_VER_INPUT" ]; then \
EXT_VER="$$EXT_VER_INPUT"; \
else \
EXT_VER=$$(node -e "const fs=require('fs');const j=JSON.parse(fs.readFileSync('extensions/vscode/package.json','utf8'));const m=j.version.match(/^(\\d+)\\.(\\d+)\\.(\\d+)(-.+)?$$/);if(!m){process.exit(1)};const major=Number(m[1]);const minor=Number(m[2]);const patch=Number(m[3])+1;const pre=m[4]??'';process.stdout.write(major+'.'+minor+'.'+patch+pre);"); \
fi; \
sed -i.bak "s/^version = \".*\"/version = \"$$VER\"/" Cargo.toml && rm -f Cargo.toml.bak; \
node -e "const fs=require('fs');const p='extensions/vscode/package.json';const j=JSON.parse(fs.readFileSync(p,'utf8'));j.version='$$EXT_VER';fs.writeFileSync(p,JSON.stringify(j,null,2)+'\n');console.log('VSCode extension version -> '+j.version);" && \
git add Cargo.toml extensions/vscode/package.json && \
git diff --staged --quiet && echo "==> No version changes (already at $(VERSION)?)" || (git commit -m "chore: release $(VERSION)" && git push origin main)
@echo "==> Creating tag $(VERSION)..."
@git tag -a $(VERSION) -m "Release $(VERSION)"
@git push origin $(VERSION)
@echo "==> Creating prerelease on GitHub..."
@gh release create $(VERSION) \
--title "$(VERSION)" \
--generate-notes \
--prerelease
@echo "==> Creating PR from main to production..."
@gh pr create \
--base production \
--head main \
--title "Release $(VERSION)" \
--body "## Release $(VERSION)$$( echo )$$( echo )This PR releases $(VERSION) to production.$$( echo )$$( echo )When merged, comment \`/release\` on this PR to promote the prerelease to the latest release."
@echo "==> Done! Review and merge the PR to publish the release."
# Publish the VSCode extension to the marketplace
# Requires VSCE_PAT env var (your Azure DevOps personal access token)
# Usage: VSCE_PAT=<token> make vscode-publish
vscode-publish:
ifndef VSCE_PAT
$(error VSCE_PAT is required. Usage: VSCE_PAT=<token> make vscode-publish)
endif
@echo "==> Publishing VSCode extension..."
@cd extensions/vscode && npm run publish:ci
@echo "==> VSCode extension published!"
# Clean build artifacts
clean:
@echo "🧹 Cleaning..."
@cargo clean
@echo "✅ Clean!"
# Install development tools
install-tools:
@echo "📦 Installing cargo-watch..."
@cargo install cargo-watch
@echo "✅ Done!"
# Build and show size comparison
size: build-debug release-build
@echo ""
@echo "📊 Binary sizes:"
@ls -lh target/debug/poly-bench 2>/dev/null | awk '{print " Debug: " $$5}' || true
@ls -lh target/release/poly-bench 2>/dev/null | awk '{print " Release: " $$5}' || true
# ============================================================================
# Quick PR Workflow
# ============================================================================
# Creates a PR from staged files, squash-merges it, and pulls changes.
# Your editor stays on main the entire time.
#
# Usage: make pr TITLE="your-pr-title"
#
# Requirements:
# - Must be on main branch
# - Must have staged files (git add <files> first)
# - gh CLI must be installed and authenticated
# ============================================================================
.PHONY: pr
pr:
ifndef TITLE
$(error Usage: make pr TITLE="your-pr-title")
endif
@./scripts/quick-pr.sh "$(TITLE)"
# ============================================================================
# Tree-sitter Grammar
# ============================================================================
# Build the Tree-sitter grammar for poly-bench DSL
# ============================================================================
# Generate Tree-sitter parser from grammar.js
grammar:
@echo "🔨 Generating Tree-sitter grammar..."
@cd poly-bench-grammar && npm install && npm run generate
@echo "✅ Grammar generated!"
# Build Tree-sitter WASM for VSCode extension
grammar-wasm: grammar
@echo "🔨 Building Tree-sitter WASM..."
@cd poly-bench-grammar && npm run build-wasm
@mkdir -p extensions/vscode/tree-sitter extensions/vscode/tree-sitter/queries
@cp poly-bench-grammar/tree-sitter-polybench.wasm extensions/vscode/tree-sitter/
@cp poly-bench-grammar/queries/highlights.scm extensions/vscode/tree-sitter/queries/
@echo "✅ WASM and queries built and copied to extensions/vscode/tree-sitter/"
# Test Tree-sitter grammar
grammar-test: grammar
@echo "🧪 Testing Tree-sitter grammar..."
@cd poly-bench-grammar && npm test
@echo "✅ Grammar tests passed!"