-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
741 lines (630 loc) · 31 KB
/
Copy pathMakefile
File metadata and controls
741 lines (630 loc) · 31 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
.PHONY: build build-all build-local install install-darwin install-windows clean fmt vet run ui ui-dev native-deps setup-lbug lancedb-native build-local \
fetch-ort-linux fetch-ort-darwin fetch-ort-windows lint \
ui-lint ui-test ci ci-fast check test test-full test-race require-heavy-test-isolation \
_ci-isolated _ci-fast-isolated _check-isolated _test-full-isolated _test-race-isolated build-windows-native \
grammars grammars-treesitter grammars-antlr grammars-clean
MODULE := github.com/graphit-labs/graphit-code
CMD := ./cmd/graphit
BIN_DIR := .build
GO_TMP_DIR ?= $(CURDIR)/$(BIN_DIR)/go-tmp
include native-deps.env
UI_DIR := internal/ui
UI_NPM_CONFIG := $(UI_DIR)/.npmrc
UI_NPM_STATE := $(UI_DIR)/node_modules/.package-lock.json
BRAND ?= graphit
BRAND_ENV := $(shell echo $(BRAND) | tr '[:lower:]' '[:upper:]')
DISPLAY_NAME ?= Graphit Code: A Powerful Agent Harness for Enterprise Software Ecosystems
VERSION ?= dev
GITHUB_REPO ?= graphit-labs/graphit-code
DEFAULT_HUB_BUCKET ?=
DEFAULT_HUB_REGION ?=
DEFAULT_HUB_ENDPOINT ?=
SELF_UPDATE_URL ?=
COMPILE_CONFIG ?=
PREFIX ?= /usr/local/bin
PREFIX_WIN ?=
ifeq ($(origin BUILD_ID), undefined)
ifeq ($(OS),Windows_NT)
BUILD_ID := $(shell powershell -Command "[System.Guid]::NewGuid().ToString()")
else
BUILD_ID := $(shell cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)
endif
endif
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/brand.Brand=$(BRAND)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/brand.DisplayName=$(DISPLAY_NAME)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/version.Version=$(VERSION)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/version.BuildID=$(BUILD_ID)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/brand.GitHubRepo=$(GITHUB_REPO)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/brand.DefaultHubBucket=$(DEFAULT_HUB_BUCKET)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/brand.DefaultHubRegion=$(DEFAULT_HUB_REGION)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/brand.DefaultHubEndpoint=$(DEFAULT_HUB_ENDPOINT)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/brand.SelfUpdateURL=$(SELF_UPDATE_URL)'
LDFLAGS += -X 'github.com/graphit-labs/graphit-code/internal/config.CompiledDefaults=$(COMPILE_CONFIG)'
BUILD_TAGS := lancedb
LOCAL_TAGS := $(BUILD_TAGS)
LANCEDB_LIB_DIR := .native
LANCEDB_GOOS := $(shell go env GOOS)
LANCEDB_GOARCH := $(shell go env GOARCH)
ifeq ($(LANCEDB_GOOS),darwin)
LANCEDB_LIB_NAME := liblancedb_go.dylib
else ifeq ($(LANCEDB_GOOS),windows)
LANCEDB_LIB_NAME := lancedb_go.dll
else
LANCEDB_LIB_NAME := liblancedb_go.so
endif
LANCEDB_LIB := $(LANCEDB_LIB_DIR)/$(LANCEDB_LIB_NAME)
GO_PKGS_SKIP := /antlr/|/treesitter/|/node_modules/
GO_PKGS_PARSERS := /antlr/|/treesitter/
GOVULNCHECK_VERSION := v1.7.0
ACTIONLINT_VERSION := v1.7.7
GO_TEST_P ?= 1
GO_TEST_PARALLEL ?= 2
GO_TEST_GOMAXPROCS ?= 2
GO_TEST_TIMEOUT ?= 15m
GO_TEST_UNIT_TIMEOUT ?= 2m
GO_TEST_UNIT_PKGS := \
./internal/brand/... \
./internal/config/... \
./internal/ignorer/... \
./internal/lockfile/... \
./internal/netutil/... \
./internal/output/... \
./internal/pagination/... \
./internal/sessionhook/... \
./internal/slogutil/... \
./internal/sysutil/... \
./internal/textslice/... \
./internal/toon/... \
./internal/version/...
GO_TEST_NATIVE_MAX_WORKERS ?= 2
GO_TEST_NATIVE_DB_THREADS ?= 2
GO_TEST_NATIVE_DB_BUFFER_MB ?= 256
GO_TEST_NATIVE_EMBED_THREADS ?= 1
GO_TEST_NATIVE_ANTLR_HEAP_MB ?= 512
GO_TEST_NATIVE_P ?= 1
GO_TEST_NATIVE_PARALLEL ?= 1
GO_TEST_NATIVE_GOMAXPROCS ?= 2
GO_TEST_CGROUP_CPU_QUOTA ?= 200%
GO_TEST_CGROUP_MEMORY_HIGH ?= 8G
GO_TEST_CGROUP_MEMORY_MAX ?= 9G
GO_TEST_CGROUP_TASKS_MAX ?= 256
GO_TEST_CGROUP_RUNTIME_MAX ?= 30m
GO_TEST_CGROUP_KILL_AFTER ?= 20s
GO_TEST_NATIVE_ENV = \
GRAPHIT_MAX_WORKERS="$(GO_TEST_NATIVE_MAX_WORKERS)" \
GRAPHIT_DB_THREADS="$(GO_TEST_NATIVE_DB_THREADS)" \
GRAPHIT_DB_BUFFER_MB="$(GO_TEST_NATIVE_DB_BUFFER_MB)" \
GRAPHIT_EMBED_THREADS="$(GO_TEST_NATIVE_EMBED_THREADS)" \
GRAPHIT_ANTLR_HEAP_MB="$(GO_TEST_NATIVE_ANTLR_HEAP_MB)"
ORT_CACHE := /tmp/onnxruntime-cache
MODEL_CACHE ?= /tmp/$(BRAND)-model-cache
ORT_HOST_GOOS := $(shell go env GOOS)
ifeq ($(ORT_HOST_GOOS),darwin)
ORT_HOST_FETCH := fetch-ort-darwin
ORT_HOST_LIB := $(ORT_CACHE)/onnxruntime-osx-arm64-$(ORT_VERSION)/lib
else ifeq ($(ORT_HOST_GOOS),windows)
ORT_HOST_FETCH := fetch-ort-windows
ORT_HOST_LIB := $(ORT_CACHE)/onnxruntime-win-x64-$(ORT_VERSION)/lib
else
ORT_HOST_FETCH := fetch-ort-linux
ORT_HOST_LIB := $(ORT_CACHE)/onnxruntime-linux-x64-$(ORT_VERSION)/lib
endif
STRIP_LDFLAGS ?= -s -w
LANCEDB_BUILD_ID := $(LANCEDB_GO_REF) $(LANCEDB_PATCH_GIT_BLOB)
LANCEDB_RUNTIME_ROOT ?= $(if $($(BRAND_ENV)_GLOBAL_DIR),$($(BRAND_ENV)_GLOBAL_DIR),$(HOME)/.$(BRAND))/runtime
LANCEDB_RUNTIME_SOURCE ?= $(LANCEDB_RUNTIME_ROOT)/dev
LBUG_VERSION := $(LBUG_GO_VERSION)
LBUG_EXT_CACHE := /tmp/lbug-extension-cache
LBUG_MOD = $(GOMODCACHE)/github.com/!ladybug!d!b/go-ladybug@$(LBUG_VERSION)
TS_OUTDIR := .build/grammars/treesitter
ANTLR_OUTDIR := .build/grammars/antlr
ifeq ($(OS),Windows_NT)
GOMODCACHE := $(shell cygpath -u "$$(go env GOMODCACHE)")
else
GOMODCACHE := $(shell go env GOMODCACHE)
endif
ifeq ($(OS),Windows_NT)
SHLIB_EXT := .dll
else ifeq ($(shell uname -s),Darwin)
SHLIB_EXT := .dylib
else
SHLIB_EXT := .so
endif
TS_CC := $(CC)
TS_CXX := $(CXX)
TS_CFLAGS := -shared -fPIC -O2 -std=c11 \
-Dts_current_malloc=malloc -Dts_current_free=free \
-Dts_current_realloc=realloc -Dts_current_calloc=calloc
TS_CXXFLAGS := -shared -fPIC -O2 -std=c++14 \
-Dts_current_malloc=malloc -Dts_current_free=free \
-Dts_current_realloc=realloc -Dts_current_calloc=calloc
GRAMMAR_MODULES := \
bash:github.com/tree-sitter/tree-sitter-bash \
c:github.com/tree-sitter/tree-sitter-c \
cpp:github.com/tree-sitter/tree-sitter-cpp \
c-sharp:github.com/tree-sitter/tree-sitter-c-sharp \
css:github.com/tree-sitter/tree-sitter-css \
go:github.com/tree-sitter/tree-sitter-go \
haskell:github.com/tree-sitter/tree-sitter-haskell \
html:github.com/tree-sitter/tree-sitter-html \
java:github.com/tree-sitter/tree-sitter-java \
javascript:github.com/tree-sitter/tree-sitter-javascript \
json:github.com/tree-sitter/tree-sitter-json \
julia:github.com/tree-sitter/tree-sitter-julia \
php:github.com/tree-sitter/tree-sitter-php:php \
python:github.com/tree-sitter/tree-sitter-python \
ruby:github.com/tree-sitter/tree-sitter-ruby \
rust:github.com/tree-sitter/tree-sitter-rust \
scala:github.com/tree-sitter/tree-sitter-scala \
typescript:github.com/tree-sitter/tree-sitter-typescript:typescript \
tsx:github.com/tree-sitter/tree-sitter-typescript:tsx \
hcl:github.com/tree-sitter-grammars/tree-sitter-hcl \
lua:github.com/tree-sitter-grammars/tree-sitter-lua \
toml:github.com/tree-sitter-grammars/tree-sitter-toml \
xml:github.com/tree-sitter-grammars/tree-sitter-xml:xml \
yaml:github.com/tree-sitter-grammars/tree-sitter-yaml \
zig:github.com/tree-sitter-grammars/tree-sitter-zig
GRAMMAR_VENDORED := clojure dockerfile elixir graphql groovy kotlin markdown \
objc proto r sql svelte swift dart vue
TS_ALL := $(foreach spec,$(GRAMMAR_MODULES),$(firstword $(subst :, ,$(spec)))) $(GRAMMAR_VENDORED)
ANTLR_GRAMMARS := plsql postgresql tsql db2 cobol85
define compile_ts_grammar
name="$(1)"; \
src="$(2)"; \
inc="$(3)"; \
alloc="$(4)"; \
cxx="$(5)"; \
output="$(TS_OUTDIR)/tree-sitter-$${name}$(SHLIB_EXT)"; \
parser_c=""; \
if [ -f "$${src}/parser.c" ]; then parser_c="$${src}/parser.c"; \
elif [ -f "$${src}/parser.c.inc" ]; then parser_c="$${src}/parser.c.inc"; \
else echo " ✗ $${name}: parser.c not found in $${src}"; exit 1; fi; \
scanner_c=""; scanner_cc=""; \
if [ -f "$${src}/scanner.c" ]; then scanner_c="$${src}/scanner.c"; \
elif [ -f "$${src}/scanner.c.inc" ]; then scanner_c="$${src}/scanner.c.inc"; fi; \
if [ -f "$${src}/scanner.cc" ]; then scanner_cc="$${src}/scanner.cc"; fi; \
iflags=""; \
for d in $${inc}; do iflags="$${iflags} -I$${d}"; done; \
extra_c=""; \
if [ "$${alloc}" = "1" ] && [ -f "$(SMACKER_DIR)/alloc.c" ]; then \
extra_c="$(SMACKER_DIR)/alloc.c"; \
fi; \
if [ -n "$${scanner_cc}" ] || [ "$${cxx}" = "1" ]; then \
tmpdir=$$(mktemp -d); \
plf=""; case "$${parser_c}" in *.c.inc) plf="-x c" ;; esac; \
$(TS_CC) $(filter-out -shared,$(TS_CFLAGS)) $${iflags} $${plf} -c "$${parser_c}" -o "$${tmpdir}/parser.o" 2>&1 || \
{ echo " ✗ $${name}: parser.c failed"; rm -rf "$${tmpdir}"; exit 1; }; \
$(TS_CXX) $(filter-out -shared,$(TS_CXXFLAGS)) $${iflags} -c "$${scanner_cc}" -o "$${tmpdir}/scanner.o" 2>&1 || \
{ echo " ✗ $${name}: scanner.cc failed"; rm -rf "$${tmpdir}"; exit 1; }; \
obj_files="$${tmpdir}/parser.o $${tmpdir}/scanner.o"; \
if [ -n "$${extra_c}" ]; then \
$(TS_CC) $(filter-out -shared,$(TS_CFLAGS)) $${iflags} -c "$${extra_c}" -o "$${tmpdir}/alloc.o" 2>&1 || \
{ echo " ✗ $${name}: alloc.c failed"; rm -rf "$${tmpdir}"; exit 1; }; \
obj_files="$${obj_files} $${tmpdir}/alloc.o"; \
fi; \
$(TS_CXX) -shared -fPIC -o "$${output}" $${obj_files} 2>&1 || \
{ echo " ✗ $${name}: linking failed"; rm -rf "$${tmpdir}"; exit 1; }; \
rm -rf "$${tmpdir}"; \
else \
cc_args=""; \
for cf in $${parser_c} $${scanner_c} $${extra_c}; do \
case "$${cf}" in *.c.inc) cc_args="$${cc_args} -x c $${cf} -x none" ;; \
*) cc_args="$${cc_args} $${cf}" ;; esac; \
done; \
$(TS_CC) $(TS_CFLAGS) $${iflags} -o "$${output}" $${cc_args} 2>&1 || \
{ echo " ✗ $${name}: compilation failed"; exit 1; }; \
fi; \
size=$$(du -h "$${output}" | cut -f1); \
echo " ✓ $${name} ($${size})"
endef
define fetch_lbug_ext
@mkdir -p $(LBUG_EXT_CACHE)/$(LBUG_EXT_VERSION)/$(1) cmd/launcher/runtime/lbug
@test -s "$(LBUG_EXT_CACHE)/$(LBUG_EXT_VERSION)/$(1)/httpfs.lbug_extension"
cp -L "$(LBUG_EXT_CACHE)/$(LBUG_EXT_VERSION)/$(1)/httpfs.lbug_extension" cmd/launcher/runtime/lbug/httpfs.lbug_extension
endef
grammars: grammars-treesitter grammars-antlr
@echo ""
@echo " ✅ All grammars built."
@echo " Tree-sitter: $(TS_OUTDIR)/"
@echo " ANTLR: $(ANTLR_OUTDIR)/"
@echo ""
.PHONY: ensure-go-modules
ensure-go-modules:
@go mod download
grammars-treesitter: ensure-go-modules
@mkdir -p $(TS_OUTDIR)
@echo ""
@echo "═══════════════════════════════════════════════════════════════════════"
@echo " Building $(words $(TS_ALL)) tree-sitter grammars"
@echo "═══════════════════════════════════════════════════════════════════════"
@echo ""
@echo " Module grammars (bindings/go sources)"
@echo " ──────────────────────────────────────────────────────────────────"
@for spec in $(GRAMMAR_MODULES); do \
key=$$(echo "$$spec" | cut -d: -f1); \
mod=$$(echo "$$spec" | cut -d: -f2); \
sub=$$(echo "$$spec" | cut -d: -f3); \
dir=$$(go list -m -f '{{.Dir}}' "$$mod" 2>/dev/null); \
if [ -z "$$dir" ]; then echo " ✗ $$key: module $$mod not resolved"; continue; fi; \
if [ -n "$$sub" ]; then src="$$dir/$$sub/src"; else src="$$dir/src"; fi; \
$(call compile_ts_grammar,$${key},$${src},$${src},,); \
done
@echo ""
@echo " Vendored grammars (internal/ast/treesitter)"
@echo " ──────────────────────────────────────────────────────────────────"
@for key in $(GRAMMAR_VENDORED); do \
src="internal/ast/treesitter/$${key}"; \
$(call compile_ts_grammar,$${key},$${src},$${src},,); \
done
@echo ""
@total=$$(ls -1 $(TS_OUTDIR)/*$(SHLIB_EXT) 2>/dev/null | wc -l); \
totalsize=$$(du -sh $(TS_OUTDIR) | cut -f1); \
echo " Summary: $${total}/$(words $(TS_ALL)) grammars built ($${totalsize})"
@echo ""
grammars-antlr:
@mkdir -p $(ANTLR_OUTDIR)
@echo ""
@echo "═══════════════════════════════════════════════════════════════════════"
@echo " Building $(words $(ANTLR_GRAMMARS)) ANTLR sidecar binaries"
@echo "═══════════════════════════════════════════════════════════════════════"
@echo ""
@success=0; failed=0; \
for grammar in $(ANTLR_GRAMMARS); do \
if go build -tags "$(BUILD_TAGS),grammar_$${grammar}" \
-ldflags="-s -w" -trimpath \
-o "$(ANTLR_OUTDIR)/antlr-sidecar-$${grammar}" \
./cmd/graphit-antlr-sidecar/ 2>&1; then \
size=$$(du -h "$(ANTLR_OUTDIR)/antlr-sidecar-$${grammar}" | cut -f1); \
echo " ✓ $${grammar} ($${size})"; \
success=$$((success + 1)); \
else \
echo " ✗ $${grammar}: build failed"; \
failed=$$((failed + 1)); \
fi; \
done; \
echo ""; \
totalsize=$$(du -sh $(ANTLR_OUTDIR) 2>/dev/null | cut -f1); \
echo " Summary: $${success}/$(words $(ANTLR_GRAMMARS)) sidecars built ($${totalsize})"; \
echo ""; \
if [ "$$failed" -gt 0 ]; then exit 1; fi
grammars-clean:
rm -rf $(TS_OUTDIR) $(ANTLR_OUTDIR)
define bundle_ast
@mkdir -p cmd/launcher/runtime/ast/queries
cp internal/ast/queries/*.yaml cmd/launcher/runtime/ast/queries/
endef
$(UI_NPM_STATE): $(UI_NPM_CONFIG) $(UI_DIR)/package.json $(UI_DIR)/package-lock.json
cd $(UI_DIR) && npm ci
ui: $(UI_NPM_STATE)
@printf 'module nodemodules\n\ngo 1.26\n' > $(UI_DIR)/node_modules/go.mod
cd $(UI_DIR) && npm run build
ui-dev:
cd internal/ui && npm run dev
ifeq ($(LANCEDB_GOOS)-$(LANCEDB_GOARCH),darwin-arm64)
NATIVE_BUNDLE_PLATFORM := darwin-arm64
else ifeq ($(LANCEDB_GOOS)-$(LANCEDB_GOARCH),windows-amd64)
NATIVE_BUNDLE_PLATFORM := windows-amd64
else ifeq ($(LANCEDB_GOOS)-$(LANCEDB_GOARCH),linux-amd64)
NATIVE_BUNDLE_PLATFORM := linux-amd64
else
NATIVE_BUNDLE_PLATFORM := unsupported-$(LANCEDB_GOOS)-$(LANCEDB_GOARCH)
endif
native-deps:
@go mod download github.com/LadybugDB/go-ladybug
@chmod -R u+w "$(LBUG_MOD)" 2>/dev/null || true
@NATIVE_BUNDLE_CACHE="$(NATIVE_BUNDLE_CACHE)" bash scripts/install-native-deps.sh \
"$(NATIVE_BUNDLE_PLATFORM)" "$(CURDIR)" "$(LBUG_MOD)" "$(ORT_CACHE)" \
"$(LBUG_EXT_CACHE)" "$(LANCEDB_LIB_DIR)"
setup-lbug:
@if [ ! -s "$(LBUG_MOD)/lib/lbug.h" ] || \
[ "$$(cat "$(LBUG_MOD)/lib/lbug_native_version" 2>/dev/null || true)" != "$(LBUG_NATIVE_VERSION)" ]; then \
$(MAKE) --no-print-directory native-deps; \
fi
define curl_fetch
if ! curl -fSL --retry 5 --retry-delay 5 --retry-all-errors \
--connect-timeout 30 --progress-bar "$(1)" -o "$(2).tmp"; then \
rm -f "$(2).tmp"; \
echo ""; \
echo " ✗ download failed: $(1)"; \
echo " the file was not written; nothing downstream will find it."; \
exit 1; \
fi; \
mv "$(2).tmp" "$(2)"
endef
lancedb-native:
@current="$$(cat "$(LANCEDB_LIB_DIR)/lancedb_go_build.sha" 2>/dev/null || true)"; \
if [ -s "$(LANCEDB_LIB)" ] && [ "$$current" = '$(LANCEDB_BUILD_ID)' ]; then exit 0; fi; \
for runtime_dir in "$(LANCEDB_RUNTIME_SOURCE)" "$(LANCEDB_RUNTIME_ROOT)"/*; do \
[ -d "$$runtime_dir" ] || continue; \
runtime_lib="$$runtime_dir/$(LANCEDB_LIB_NAME)"; \
runtime_build_id="$$(cat "$$runtime_dir/lancedb_go_build.sha" 2>/dev/null || true)"; \
[ -s "$$runtime_lib" ] && [ "$$runtime_build_id" = '$(LANCEDB_BUILD_ID)' ] || continue; \
mkdir -p "$(LANCEDB_LIB_DIR)"; \
case "$(LANCEDB_GOOS)" in \
windows) cp -L "$$runtime_lib" "$(LANCEDB_LIB)" ;; \
*) ln -sf "$$runtime_lib" "$(LANCEDB_LIB)" ;; \
esac; \
printf '%s\n' '$(LANCEDB_BUILD_ID)' > "$(LANCEDB_LIB_DIR)/lancedb_go_build.sha"; \
echo " ✓ LanceDB native linked to $$runtime_lib (no cargo needed)"; \
exit 0; \
done; \
echo " → Compatible LanceDB native missing; downloading the verified bundle…"; \
$(MAKE) --no-print-directory native-deps
fetch-ort-linux:
@if [ ! -f $(ORT_CACHE)/onnxruntime-linux-x64-$(ORT_VERSION)/lib/libonnxruntime.so.$(ORT_VERSION) ] || \
[ ! -f $(ORT_CACHE)/onnxruntime-linux-x64-$(ORT_VERSION)/lib/libonnxruntime_providers_shared.so ] || \
[ ! -f $(ORT_CACHE)/onnxruntime-linux-x64-$(ORT_VERSION)/lib/libonnxruntime_providers_cuda.so ]; then \
$(MAKE) --no-print-directory native-deps; \
fi
fetch-ort-darwin:
@if [ ! -f $(ORT_CACHE)/onnxruntime-osx-arm64-$(ORT_VERSION)/lib/libonnxruntime.$(ORT_VERSION).dylib ]; then \
$(MAKE) --no-print-directory native-deps; \
fi
fetch-ort-windows:
@if [ ! -f $(ORT_CACHE)/onnxruntime-win-x64-$(ORT_VERSION)/lib/onnxruntime.dll ] || \
[ ! -f $(ORT_CACHE)/onnxruntime-win-x64-$(ORT_VERSION)/lib/onnxruntime_providers_shared.dll ] || \
[ ! -f $(ORT_CACHE)/onnxruntime-win-x64-$(ORT_VERSION)/lib/onnxruntime_providers_cuda.dll ]; then \
$(MAKE) --no-print-directory native-deps; \
fi
build: build-linux
build-local: setup-lbug lancedb-native
@mkdir -p $(BIN_DIR) $(GO_TMP_DIR)
GOTMPDIR=$(GO_TMP_DIR) CGO_ENABLED=1 go build -tags "$(LOCAL_TAGS)" -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BRAND)-local $(CMD)
@echo " ✓ $(BIN_DIR)/$(BRAND)-local"
install: build
@mkdir -p $(PREFIX)
@if [ -w "$(PREFIX)" ]; then \
cp $(BIN_DIR)/$(BRAND)-linux-amd64 $(PREFIX)/$(BRAND); \
else \
sudo cp $(BIN_DIR)/$(BRAND)-linux-amd64 $(PREFIX)/$(BRAND); \
fi
@echo " ✓ Installed to $(PREFIX)/$(BRAND)"
@case ":$$PATH:" in \
*":$(PREFIX):"*) ;; \
*) echo " ⚠ $(PREFIX) is not in your PATH. Add it: export PATH=\"\$$PATH:$(PREFIX)\"" ;; \
esac
install-darwin: build-darwin
@mkdir -p $(PREFIX)
@if [ -w "$(PREFIX)" ]; then \
cp $(BIN_DIR)/$(BRAND)-darwin-arm64 $(PREFIX)/$(BRAND); \
else \
sudo cp $(BIN_DIR)/$(BRAND)-darwin-arm64 $(PREFIX)/$(BRAND); \
fi
@echo " ✓ Installed to $(PREFIX)/$(BRAND)"
@xattr -d com.apple.quarantine $(PREFIX)/$(BRAND) 2>/dev/null || true
@codesign --sign - --force $(PREFIX)/$(BRAND) 2>/dev/null || true
@case ":$$PATH:" in \
*":$(PREFIX):"*) ;; \
*) echo " ⚠ $(PREFIX) is not in your PATH. Add it: export PATH=\"\$$PATH:$(PREFIX)\"" ;; \
esac
install-windows: build-windows-native
@# Default: %PROGRAMFILES%\graphit (global — equivalent of /usr/local/bin, may need admin)
@# Override: make install-windows PREFIX_WIN='C:\Tools\graphit'
@_dir="$(PREFIX_WIN)"; \
if [ -z "$$_dir" ]; then _dir="$${PROGRAMFILES}/graphit"; fi; \
_dir="$$(echo "$$_dir" | sed 's|\\\\|/|g')"; \
mkdir -p "$$_dir" || { echo " ✗ Cannot create $$_dir. Try running as Administrator."; exit 1; }; \
cp .build/$(BRAND)-windows-amd64.exe "$$_dir/$(BRAND).exe"; \
_windir="$$(echo "$$_dir" | sed 's|/|\\\\|g')"; \
echo " ✓ Installed to $$_windir\\$(BRAND).exe"; \
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \
"\$$d = '$$_windir'; \
\$$syspath = [System.Environment]::GetEnvironmentVariable('PATH', 'Machine'); \
if (\$$syspath -notlike \"*\$$d*\") { \
try { \
[System.Environment]::SetEnvironmentVariable('PATH', \"\$$syspath;\$$d\", 'Machine'); \
Write-Host ' ✓ Added to system PATH (restart terminal to take effect)' -ForegroundColor Green \
} catch { \
\$$up = [System.Environment]::GetEnvironmentVariable('PATH', 'User'); \
[System.Environment]::SetEnvironmentVariable('PATH', \"\$$up;\$$d\", 'User'); \
Write-Host ' ⚠ No admin rights — added to user PATH instead (restart terminal)' -ForegroundColor Yellow \
} \
} else { Write-Host \" ✓ \$$d already in PATH\" -ForegroundColor Green }" 2>/dev/null || \
echo " ⚠ Could not update PATH automatically. Add manually: $$_windir"
build-linux: ui setup-lbug fetch-ort-linux lancedb-native
@mkdir -p cmd/launcher/runtime $(BIN_DIR) $(GO_TMP_DIR)
GOTMPDIR=$(GO_TMP_DIR) GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -tags "$(BUILD_TAGS)" -ldflags "$(LDFLAGS) $(STRIP_LDFLAGS)" -o cmd/launcher/runtime/$(BRAND)-core $(CMD)
GOTMPDIR=$(GO_TMP_DIR) GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS) -s -w" -o cmd/launcher/runtime/$(BRAND)-mcp ./cmd/mcp
find $$(go env GOPATH)/pkg/mod/github.com/!ladybug!d!b/go-ladybug@$(LBUG_VERSION)/lib -maxdepth 1 -name "liblbug.so" -exec cp -L {} cmd/launcher/runtime/ \;
cd cmd/launcher/runtime && cp liblbug.so liblbug.so.0
cp -L $(ORT_CACHE)/onnxruntime-linux-x64-$(ORT_VERSION)/lib/libonnxruntime.so.$(ORT_VERSION) cmd/launcher/runtime/
cp -L $(ORT_CACHE)/onnxruntime-linux-x64-$(ORT_VERSION)/lib/libonnxruntime_providers_shared.so cmd/launcher/runtime/
cp -L $(ORT_CACHE)/onnxruntime-linux-x64-$(ORT_VERSION)/lib/libonnxruntime_providers_cuda.so cmd/launcher/runtime/
@# The search engine. It travels beside the binary, which is what the $ORIGIN rpath in
@# internal/lancestore/cgo_lancedb.go resolves against — see that file for why there are two.
cp -L $(LANCEDB_LIB) cmd/launcher/runtime/
cp $(LANCEDB_LIB_DIR)/lancedb_go_build.sha cmd/launcher/runtime/
$(call fetch_lbug_ext,linux_amd64)
$(call bundle_ast)
GOTMPDIR=$(GO_TMP_DIR) GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BRAND)-linux-amd64 ./cmd/launcher
rm -rf cmd/launcher/runtime/*
build-darwin: ui setup-lbug fetch-ort-darwin lancedb-native
@mkdir -p cmd/launcher/runtime $(BIN_DIR) $(GO_TMP_DIR)
GOTMPDIR=$(GO_TMP_DIR) GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -tags "$(BUILD_TAGS)" -ldflags "$(LDFLAGS) $(STRIP_LDFLAGS)" -o cmd/launcher/runtime/$(BRAND)-core $(CMD)
GOTMPDIR=$(GO_TMP_DIR) GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS) -s -w" -o cmd/launcher/runtime/$(BRAND)-mcp ./cmd/mcp
find $$(go env GOPATH)/pkg/mod/github.com/!ladybug!d!b/go-ladybug@$(LBUG_VERSION)/lib -maxdepth 1 -name "liblbug.dylib" -exec cp -L {} cmd/launcher/runtime/ \;
cd cmd/launcher/runtime && cp liblbug.dylib liblbug.0.dylib
cp -L $(ORT_CACHE)/onnxruntime-osx-arm64-$(ORT_VERSION)/lib/libonnxruntime.$(ORT_VERSION).dylib cmd/launcher/runtime/
cp -L $(LANCEDB_LIB) cmd/launcher/runtime/
cp $(LANCEDB_LIB_DIR)/lancedb_go_build.sha cmd/launcher/runtime/
$(call fetch_lbug_ext,osx_arm64)
$(call bundle_ast)
GOTMPDIR=$(GO_TMP_DIR) GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BRAND)-darwin-arm64 ./cmd/launcher
rm -rf cmd/launcher/runtime/*
build-windows-native: ui setup-lbug fetch-ort-windows lancedb-native
@mkdir -p cmd/launcher/runtime $(BIN_DIR) $(GO_TMP_DIR)
GOTMPDIR=$(GO_TMP_DIR) CGO_ENABLED=1 CGO_CFLAGS="-I/mingw64/include" CGO_CXXFLAGS="-I/mingw64/include" CGO_LDFLAGS="-lstdc++" go build -tags "$(BUILD_TAGS)" -ldflags "$(LDFLAGS) $(STRIP_LDFLAGS)" -o cmd/launcher/runtime/$(BRAND)-core.exe $(CMD)
GOTMPDIR=$(GO_TMP_DIR) CGO_ENABLED=0 go build -ldflags "$(LDFLAGS) -s -w" -o cmd/launcher/runtime/$(BRAND)-mcp.exe ./cmd/mcp
cp -L $(LANCEDB_LIB) cmd/launcher/runtime/
cp $(LANCEDB_LIB_DIR)/lancedb_go_build.sha cmd/launcher/runtime/
GOPATH_UNIX=$$(cygpath -u "$$(go env GOPATH)") && find $$GOPATH_UNIX/pkg/mod/github.com/!ladybug!d!b/go-ladybug@$(LBUG_VERSION)/lib -maxdepth 1 -name "lbug_shared.dll" -exec cp -L {} cmd/launcher/runtime/ \;
cp /mingw64/bin/libgcc_s_seh-1.dll cmd/launcher/runtime/ 2>/dev/null || true
cp /mingw64/bin/libstdc++-6.dll cmd/launcher/runtime/ 2>/dev/null || true
cp /mingw64/bin/libwinpthread-1.dll cmd/launcher/runtime/ 2>/dev/null || true
cp -L $(ORT_CACHE)/onnxruntime-win-x64-$(ORT_VERSION)/lib/onnxruntime.dll cmd/launcher/runtime/
cp -L $(ORT_CACHE)/onnxruntime-win-x64-$(ORT_VERSION)/lib/onnxruntime_providers_shared.dll cmd/launcher/runtime/
cp -L $(ORT_CACHE)/onnxruntime-win-x64-$(ORT_VERSION)/lib/onnxruntime_providers_cuda.dll cmd/launcher/runtime/
$(call fetch_lbug_ext,win_amd64)
$(call bundle_ast)
GOTMPDIR=$(GO_TMP_DIR) CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BRAND)-windows-amd64.exe ./cmd/launcher
rm -rf cmd/launcher/runtime/*
build-all:
@echo " ✗ build-all no longer exists as one machine's job."
@echo ""
@echo " Native dependencies are published as verified, platform-specific bundles, so a"
@echo " binary for another platform must be produced on that platform's release runner."
@echo ""
@echo " Release runs three jobs, one per runner: .github/workflows/release.yml"
@echo " For this machine: make build-local"
@exit 1
test:
@TEST_HOME_ROOT="$${TMPDIR:-/tmp}/$(BRAND)-unit-test-homes"; \
rm -rf "$$TEST_HOME_ROOT"; \
trap 'rm -rf "$$TEST_HOME_ROOT"' EXIT; \
echo " → Running the lightweight cached unit tier…"; \
GRAPHIT_TEST_HOME_ROOT="$$TEST_HOME_ROOT" GOMAXPROCS="$(GO_TEST_GOMAXPROCS)" \
go test -p $(GO_TEST_P) -parallel $(GO_TEST_PARALLEL) \
-timeout $(GO_TEST_UNIT_TIMEOUT) $(GO_TEST_UNIT_PKGS)
require-heavy-test-isolation:
@if [ "$${GRAPHIT_HEAVY_TEST_ISOLATED:-}" = "1" ]; then exit 0; fi; \
echo "✗ Refusing native/full validation on an unisolated local machine."; \
echo " Run it in CI or inside hard CPU, memory, process-count, concurrency and wall-time limits."; \
echo " Set GRAPHIT_HEAVY_TEST_ISOLATED=1 only after that isolation and explicit authorization exist."; \
exit 2
test-full:
@if [ "$${GRAPHIT_HEAVY_TEST_ISOLATED:-}" = "1" ]; then \
$(MAKE) -j1 --no-print-directory _test-full-isolated GRAPHIT_HEAVY_TEST_GATE_PASSED=1; \
exit $$?; \
fi; \
for command in systemd-run timeout ionice nice; do \
if ! command -v "$$command" >/dev/null 2>&1; then \
echo "✗ Cannot safely run the full suite: $$command is unavailable."; \
echo " Use an isolated CI runner or install the required local isolation tools."; \
exit 2; \
fi; \
done; \
echo " → Entering a transient cgroup: $(GO_TEST_CGROUP_CPU_QUOTA) CPU, $(GO_TEST_CGROUP_MEMORY_MAX) memory, no swap, $(GO_TEST_CGROUP_TASKS_MAX) tasks, $(GO_TEST_CGROUP_RUNTIME_MAX) maximum…"; \
systemd-run --user --scope --collect --quiet \
--property=CPUQuota=$(GO_TEST_CGROUP_CPU_QUOTA) \
--property=MemoryHigh=$(GO_TEST_CGROUP_MEMORY_HIGH) \
--property=MemoryMax=$(GO_TEST_CGROUP_MEMORY_MAX) \
--property=MemorySwapMax=0 \
--property=OOMPolicy=stop \
--property=TasksMax=$(GO_TEST_CGROUP_TASKS_MAX) \
timeout --signal=TERM --kill-after=$(GO_TEST_CGROUP_KILL_AFTER) $(GO_TEST_CGROUP_RUNTIME_MAX) \
ionice -c 3 nice -n 10 \
$(MAKE) -j1 --no-print-directory _test-full-isolated \
GRAPHIT_HEAVY_TEST_ISOLATED=1 GRAPHIT_HEAVY_TEST_GATE_PASSED=1
_test-full-isolated:
@test "$(GRAPHIT_HEAVY_TEST_GATE_PASSED)" = "1"
@$(MAKE) --no-print-directory setup-lbug lancedb-native $(ORT_HOST_FETCH)
@LBUG_LIB="$(LBUG_MOD)/lib"; \
TEST_HOME_ROOT="$${TMPDIR:-/tmp}/$(BRAND)-test-homes"; \
if [ -f "$$LBUG_LIB/liblbug.so" ] && [ ! -f "$$LBUG_LIB/liblbug.so.0" ]; then \
cp -L "$$LBUG_LIB/liblbug.so" "$$LBUG_LIB/liblbug.so.0"; \
fi; \
rm -rf "$$TEST_HOME_ROOT"; \
status=0; \
echo " → Running the full native suite inside the established isolation boundary…"; \
LD_LIBRARY_PATH="$$LBUG_LIB:$(ORT_HOST_LIB):$$LD_LIBRARY_PATH" \
DYLD_LIBRARY_PATH="$(ORT_HOST_LIB):$$DYLD_LIBRARY_PATH" \
$(GO_TEST_NATIVE_ENV) $(BRAND_ENV)_MODEL_CACHE="$(MODEL_CACHE)" \
GRAPHIT_TEST_HOME_ROOT="$$TEST_HOME_ROOT" GOMAXPROCS="$(GO_TEST_NATIVE_GOMAXPROCS)" \
go test -count=1 -tags "$(LOCAL_TAGS)" -coverprofile=coverage.out -covermode=atomic \
-p $(GO_TEST_NATIVE_P) -parallel $(GO_TEST_NATIVE_PARALLEL) -timeout $(GO_TEST_TIMEOUT) \
$$(go list ./... | grep -Ev "$(GO_PKGS_SKIP)") || status=1; \
echo " → Running generated parser tests…"; \
LD_LIBRARY_PATH="$$LBUG_LIB:$(ORT_HOST_LIB):$$LD_LIBRARY_PATH" \
DYLD_LIBRARY_PATH="$(ORT_HOST_LIB):$$DYLD_LIBRARY_PATH" \
$(GO_TEST_NATIVE_ENV) $(BRAND_ENV)_MODEL_CACHE="$(MODEL_CACHE)" \
GRAPHIT_TEST_HOME_ROOT="$$TEST_HOME_ROOT" GOMAXPROCS="$(GO_TEST_NATIVE_GOMAXPROCS)" \
go test -count=1 -tags "$(LOCAL_TAGS)" \
-p $(GO_TEST_NATIVE_P) -parallel $(GO_TEST_NATIVE_PARALLEL) -timeout $(GO_TEST_TIMEOUT) \
$$(go list -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./internal/ast/antlr/... | sed '/^$$/d') || status=1; \
rm -rf "$$TEST_HOME_ROOT"; \
exit $$status
test-race: require-heavy-test-isolation
@$(MAKE) --no-print-directory _test-race-isolated GRAPHIT_HEAVY_TEST_GATE_PASSED=1
_test-race-isolated:
@test "$(GRAPHIT_HEAVY_TEST_GATE_PASSED)" = "1"
@$(MAKE) --no-print-directory setup-lbug lancedb-native $(ORT_HOST_FETCH)
@LBUG_LIB="$(LBUG_MOD)/lib"; \
TEST_HOME_ROOT="$${TMPDIR:-/tmp}/$(BRAND)-test-homes"; \
rm -rf "$$TEST_HOME_ROOT"; \
echo " → Running focused native race tests; guardrails below are not hard isolation…"; \
LD_LIBRARY_PATH="$$LBUG_LIB:$(ORT_HOST_LIB):$$LD_LIBRARY_PATH" \
DYLD_LIBRARY_PATH="$(ORT_HOST_LIB):$$DYLD_LIBRARY_PATH" \
$(GO_TEST_NATIVE_ENV) $(BRAND_ENV)_MODEL_CACHE="$(MODEL_CACHE)" \
GRAPHIT_TEST_HOME_ROOT="$$TEST_HOME_ROOT" GOMAXPROCS="$(GO_TEST_NATIVE_GOMAXPROCS)" \
go test -race -count=1 -tags "$(LOCAL_TAGS)" -p $(GO_TEST_NATIVE_P) -parallel $(GO_TEST_NATIVE_PARALLEL) \
-timeout $(GO_TEST_TIMEOUT) \
./internal/fswatch/... ./internal/livesearch/... ./internal/mcpproxy/... \
./internal/projectlock/... ./internal/sessionhook/... ./internal/sysutil/... ./internal/task/...; \
status=$$?; \
rm -rf "$$TEST_HOME_ROOT"; \
exit $$status
lint: setup-lbug lancedb-native
golangci-lint run ./...
vulncheck: setup-lbug lancedb-native
go run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION) -tags "$(LOCAL_TAGS)" ./...
actionlint:
@go run github.com/rhysd/actionlint/cmd/actionlint@$(ACTIONLINT_VERSION) -no-color .github/workflows/*.yml
ui-lint: $(UI_NPM_STATE)
cd internal/ui && npm run lint
ui-test: $(UI_NPM_STATE)
cd internal/ui && npm test
fmt:
gofmt -w .
vet: setup-lbug lancedb-native
go vet -tags "$(LOCAL_TAGS)" -unreachable=false $$(go list -tags "$(LOCAL_TAGS)" ./... | grep -Ev "$(GO_PKGS_SKIP)")
ci-fast: require-heavy-test-isolation
@$(MAKE) --no-print-directory _ci-fast-isolated GRAPHIT_HEAVY_TEST_GATE_PASSED=1
_ci-fast-isolated:
@test "$(GRAPHIT_HEAVY_TEST_GATE_PASSED)" = "1"
@$(MAKE) --no-print-directory lancedb-native
@echo " → Running bounded static checks, then the lightweight unit tier…"
@$(MAKE) actionlint
@$(MAKE) vet
@$(MAKE) lint
@$(MAKE) ui-lint
@$(MAKE) ui-test
@$(MAKE) test
ci: require-heavy-test-isolation
@$(MAKE) --no-print-directory _ci-isolated GRAPHIT_HEAVY_TEST_GATE_PASSED=1
_ci-isolated:
@test "$(GRAPHIT_HEAVY_TEST_GATE_PASSED)" = "1"
@$(MAKE) --no-print-directory lancedb-native
@echo " → Building UI, then static checks, the bounded full suite, and focused race checks…"
@$(MAKE) ui
@$(MAKE) actionlint
@$(MAKE) vet
@$(MAKE) lint
@$(MAKE) vulncheck
@$(MAKE) ui-lint
@$(MAKE) ui-test
@$(MAKE) test-full
@$(MAKE) test-race
@echo ""
@echo " ✅ All CI checks passed."
@echo ""
check: require-heavy-test-isolation
@$(MAKE) --no-print-directory _check-isolated GRAPHIT_HEAVY_TEST_GATE_PASSED=1
_check-isolated:
@test "$(GRAPHIT_HEAVY_TEST_GATE_PASSED)" = "1"
@$(MAKE) actionlint
@$(MAKE) vet
@$(MAKE) lint
@$(MAKE) vulncheck
@$(MAKE) test-full
@$(MAKE) test-race
@echo ""
@echo " ✅ Go checks passed (vet + lint + vulncheck + test-full + test-race)."
@echo ""
clean:
rm -rf $(BIN_DIR)
rm -rf internal/ui/dist
run:
go run $(CMD) $(ARGS)
update-deps:
go get -u ./...
go mod tidy