-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
979 lines (829 loc) · 35.4 KB
/
Copy pathMakefile
File metadata and controls
979 lines (829 loc) · 35.4 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
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
# SQLite WASM Component Makefile
# Builds SQLite as a WebAssembly component targeting WASI Preview 2
.PHONY: all clean deps sqlite wasi-sdk bindings build test test-cli help cli extensions \
wasmmachine-build wasmmachine-seal wasmmachine-run \
verify-sqlite-version
# Directories
PROJECT_ROOT := $(shell pwd)
DEPS_DIR := $(PROJECT_ROOT)/deps
BUILD_DIR := $(PROJECT_ROOT)/build
SRC_DIR := $(PROJECT_ROOT)/src
WIT_DIR := $(PROJECT_ROOT)/wit
BINDINGS_DIR := $(SRC_DIR)/bindings
# wasi-sdk configuration
WASI_SDK := $(DEPS_DIR)/wasi-sdk
WASI_SYSROOT := $(WASI_SDK)/share/wasi-sysroot
CC := $(WASI_SDK)/bin/clang
AR := $(WASI_SDK)/bin/llvm-ar
# Target triple
TARGET := wasm32-wasip2
# WASM feature flags for better performance
# SIMD provides 128-bit vector operations for faster data processing
# Can be disabled with WASM_SIMD=0 for maximum compatibility
WASM_SIMD ?= 1
WASM_FEATURES :=
ifeq ($(WASM_SIMD),1)
WASM_FEATURES += -msimd128
endif
# SQLite configuration flags
# Note: FTS5, RTREE, GEOPOLY, JSON1 are built as separate WASM extensions
SQLITE_CFLAGS := \
-DSQLITE_THREADSAFE=1 \
-DSQLITE_ENABLE_MATH_FUNCTIONS \
-DSQLITE_ENABLE_COLUMN_METADATA \
-DSQLITE_ENABLE_STAT4 \
-DSQLITE_OMIT_LOCALTIME \
-DSQLITE_TEMP_STORE=2 \
-DSQLITE_OS_OTHER=1 \
-DSQLITE_MUTEX_NOOP \
-DSQLITE_DEFAULT_MEMSTATUS=0 \
-DSQLITE_MAX_EXPR_DEPTH=0 \
-DSQLITE_USE_ALLOCA
# Note: SESSION + PREUPDATE_HOOK enabled for the cli's sqlite3 via
# core/Cargo.toml's `libsqlite3-sys = { features = [..., "session"] }`.
# The Makefile compile is for FTS5/RTREE/etc. .o variants only;
# the cli's main sqlite3 comes from cargo.
# Compiler flags
CFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-O2 \
-g \
-Wall \
-Wextra \
-Wno-unused-parameter \
-I$(DEPS_DIR)/sqlite \
-I$(SRC_DIR) \
-I$(BINDINGS_DIR) \
$(WASM_FEATURES) \
$(SQLITE_CFLAGS)
# Linker flags for reactor (library) mode
LDFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-mexec-model=reactor \
-Wl,--export-dynamic \
-Wl,--no-entry
# Source files
SQLITE_SRC := $(DEPS_DIR)/sqlite/sqlite3.c
VFS_SRCS := \
$(SRC_DIR)/vfs/vfs_memory.c \
$(SRC_DIR)/vfs/vfs_wasi.c
EXPORT_SRCS := \
$(SRC_DIR)/exports/low_level.c \
$(SRC_DIR)/exports/high_level.c
MAIN_SRC := $(SRC_DIR)/sqlite_wasm.c
# Object files
OBJS := \
$(BUILD_DIR)/sqlite3.o \
$(BUILD_DIR)/vfs_memory.o \
$(BUILD_DIR)/vfs_wasi.o \
$(BUILD_DIR)/low_level.o \
$(BUILD_DIR)/high_level.o \
$(BUILD_DIR)/sqlite_wasm.o \
$(BUILD_DIR)/sqlite_world.o \
$(BINDINGS_DIR)/sqlite_world_component_type.o
# Output files
CORE_WASM := $(BUILD_DIR)/sqlite-core.wasm
COMPONENT_WASM := $(BUILD_DIR)/sqlite.wasm
# Default target
all: $(COMPONENT_WASM)
# Help
help:
@echo "SQLite WASM Component Build System"
@echo ""
@echo "Targets:"
@echo " all Build the SQLite WASM component (default)"
@echo " deps Download all dependencies (wasi-sdk, sqlite)"
@echo " sqlite Download SQLite amalgamation"
@echo " wasi-sdk Download wasi-sdk toolchain"
@echo " bindings Generate C bindings from WIT"
@echo " bindings-unified Generate bindings for the unified-WIT world (task #12)"
@echo " build Build the core WASM module"
@echo " component Convert core module to component"
@echo " cli Build the SQLite CLI (sqlite-cli.wasm)"
@echo " cli-zip Build CLI composed with zip-wasm (.archive support)"
@echo " cli-common Build CLI composed with FTS5 + JSON1"
@echo " cli-full Build CLI with all extensions + ZIP support"
@echo " cli-wac Same as cli-full but composed via wac (requires unified-WIT migration)"
@echo " extensions Build all WASM extensions (FTS5, R-Tree, JSON1, GeoPoly)"
@echo " test Run tests"
@echo " clean Remove build artifacts"
@echo ""
@echo "Environment variables:"
@echo " SQLITE_VERSION SQLite version (default: 3530100)"
@echo " WASI_SDK_VERSION wasi-sdk version (default: 33)"
@echo " ZIP_WASM Path to zip-wasm component (for cli-zip/cli-full)"
@echo " WASM_SIMD Enable SIMD instructions (default: 1, set to 0 to disable)"
# Download dependencies
deps: wasi-sdk sqlite
sqlite:
@echo "Downloading SQLite..."
./scripts/download-sqlite.sh
wasi-sdk:
@echo "Downloading wasi-sdk..."
./scripts/download-wasi-sdk.sh
# Generate bindings from WIT
bindings: $(BINDINGS_DIR)/sqlite_world.h
$(BINDINGS_DIR)/sqlite_world.h: $(WIT_DIR)/world.wit $(WIT_DIR)/sqlite-low-level.wit $(WIT_DIR)/sqlite-high-level.wit
@echo "Generating C bindings from WIT..."
@mkdir -p $(BINDINGS_DIR)
wit-bindgen c $(WIT_DIR) --world sqlite-world --out-dir $(BINDINGS_DIR)
# Generate bindings for extensible world (includes extension API)
BINDINGS_EXT_DIR := $(SRC_DIR)/bindings-ext
bindings-ext: $(BINDINGS_EXT_DIR)/sqlite_extensible.h
$(BINDINGS_EXT_DIR)/sqlite_extensible.h: $(WIT_DIR)/world.wit $(WIT_DIR)/sqlite-low-level.wit $(WIT_DIR)/sqlite-high-level.wit $(WIT_DIR)/sqlite-extension.wit
@echo "Generating C bindings for extensible world..."
@mkdir -p $(BINDINGS_EXT_DIR)
wit-bindgen c $(WIT_DIR) --world sqlite-extensible --out-dir $(BINDINGS_EXT_DIR)
# Generate bindings for the unified-WIT world (task #12 target shape).
#
# Uses the canonical sqlite:extension contract via the sqlite-wit
# submodule, exposed to wit-bindgen via wit/deps/sqlite-extension as a
# symlink. The C glue that consumes these bindings (a successor to
# src/exports/extension.c) hasn't landed yet; this target exists so the
# binding shape can be inspected and iterated on without disturbing the
# legacy sqlite-extensible build path.
BINDINGS_UNIFIED_DIR := $(SRC_DIR)/bindings-unified
WIT_UNIFIED_DEPS := $(WIT_DIR)/deps/sqlite-extension/types.wit \
$(WIT_DIR)/deps/sqlite-extension/host-spi.wit \
$(WIT_DIR)/deps/sqlite-extension/guest.wit \
$(WIT_DIR)/deps/sqlite-extension/policy.wit
bindings-unified: $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h
$(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h: $(WIT_DIR)/unified-world.wit $(WIT_DIR)/wasm-slots.wit $(WIT_DIR)/sqlite-low-level.wit $(WIT_DIR)/sqlite-high-level.wit $(WIT_DIR)/extension-loader.wit $(WIT_DIR)/zip-operations.wit $(WIT_UNIFIED_DEPS)
@echo "Generating C bindings for sqlite-cli-unified world..."
@mkdir -p $(BINDINGS_UNIFIED_DIR)
wit-bindgen c $(WIT_DIR) --world sqlite-cli-unified --out-dir $(BINDINGS_UNIFIED_DIR)
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Compile SQLite
$(BUILD_DIR)/sqlite3.o: $(SQLITE_SRC) | $(BUILD_DIR)
@echo "Compiling SQLite..."
$(CC) $(CFLAGS) -c $< -o $@
# Compile VFS implementations
$(BUILD_DIR)/vfs_memory.o: $(SRC_DIR)/vfs/vfs_memory.c | $(BUILD_DIR)
@echo "Compiling memory VFS..."
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/vfs_wasi.o: $(SRC_DIR)/vfs/vfs_wasi.c | $(BUILD_DIR)
@echo "Compiling WASI VFS..."
$(CC) $(CFLAGS) -c $< -o $@
# Compile export implementations
$(BUILD_DIR)/low_level.o: $(SRC_DIR)/exports/low_level.c $(BINDINGS_DIR)/sqlite_world.h | $(BUILD_DIR)
@echo "Compiling low-level exports..."
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/high_level.o: $(SRC_DIR)/exports/high_level.c $(BINDINGS_DIR)/sqlite_world.h | $(BUILD_DIR)
@echo "Compiling high-level exports..."
$(CC) $(CFLAGS) -c $< -o $@
# Compile main wrapper
$(BUILD_DIR)/sqlite_wasm.o: $(MAIN_SRC) $(BINDINGS_DIR)/sqlite_world.h | $(BUILD_DIR)
@echo "Compiling main wrapper..."
$(CC) $(CFLAGS) -c $< -o $@
# Compile generated bindings
$(BUILD_DIR)/sqlite_world.o: $(BINDINGS_DIR)/sqlite_world.c $(BINDINGS_DIR)/sqlite_world.h | $(BUILD_DIR)
@echo "Compiling generated bindings..."
$(CC) $(CFLAGS) -c $< -o $@
# Link core WASM module
$(CORE_WASM): $(OBJS)
@echo "Linking core WASM module..."
$(CC) $(LDFLAGS) $(OBJS) -o $@
# wasm32-wasip2 target already produces a component, just rename/copy
$(COMPONENT_WASM): $(CORE_WASM)
@echo "Finalizing WASM component..."
cp $(CORE_WASM) $@
@echo "Built: $@"
@wasm-tools component wit $@ 2>/dev/null | head -50 || true
@ls -lh $@
build: $(CORE_WASM)
component: $(COMPONENT_WASM)
# Run tests
test: $(COMPONENT_WASM)
@echo "Running tests..."
@if command -v wasmtime >/dev/null 2>&1; then \
echo "Testing with wasmtime..."; \
wasmtime wast tests/unit/*.wast 2>/dev/null || echo "No .wast tests found"; \
else \
echo "wasmtime not found, skipping runtime tests"; \
fi
test-unit: test
test-integration: $(COMPONENT_WASM)
@echo "Running integration tests..."
@if command -v jco >/dev/null 2>&1; then \
echo "Testing with jco..."; \
jco transpile $(COMPONENT_WASM) -o $(BUILD_DIR)/js --minify 2>/dev/null && \
node tests/integration/jco/test.js 2>/dev/null || echo "jco tests not configured"; \
else \
echo "jco not found, skipping JavaScript integration tests"; \
fi
test-cli: $(CLI_WASM)
@echo "Running CLI tests..."
@./tests/cli/test_load.sh
@./tests/cli/test_commands.sh
# CLI build
CLI_SRC := $(SRC_DIR)/cli/sqlite_cli.c
CLI_WASM := $(BUILD_DIR)/sqlite-cli.wasm
# CLI compiler flags (command mode, not reactor)
CLI_CFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-O2 \
-g \
-Wall \
-I$(DEPS_DIR)/sqlite \
-I$(SRC_DIR) \
-D_WASI_EMULATED_PROCESS_CLOCKS \
$(WASM_FEATURES) \
$(SQLITE_CFLAGS)
CLI_LDFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-lwasi-emulated-process-clocks \
-Wl,-z,stack-size=131072
# CLI object files
CLI_OBJS := \
$(BUILD_DIR)/sqlite3.o \
$(BUILD_DIR)/vfs_memory.o \
$(BUILD_DIR)/vfs_wasi.o \
$(BUILD_DIR)/sqlite_wasm.o \
$(BUILD_DIR)/sqlite_cli.o
# Compile CLI main
$(BUILD_DIR)/sqlite_cli.o: $(CLI_SRC) | $(BUILD_DIR)
@echo "Compiling CLI..."
$(CC) $(CLI_CFLAGS) -c $< -o $@
# Link CLI
$(CLI_WASM): $(CLI_OBJS)
@echo "Linking CLI..."
$(CC) $(CLI_LDFLAGS) $(CLI_OBJS) -o $@
@echo "Built: $@"
@ls -lh $@
cli: $(CLI_WASM)
# Extensible build (with extension API)
EXTENSIBLE_WASM := $(BUILD_DIR)/sqlite-extensible.wasm
# Compiler flags for extensible build (bindings-ext first for compatibility wrapper)
CFLAGS_EXT := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-O2 \
-g \
-Wall \
-Wextra \
-Wno-unused-parameter \
-I$(DEPS_DIR)/sqlite \
-I$(SRC_DIR) \
-I$(BINDINGS_EXT_DIR) \
$(WASM_FEATURES) \
$(SQLITE_CFLAGS)
# Object files for extensible build
OBJS_EXT := \
$(BUILD_DIR)/sqlite3.o \
$(BUILD_DIR)/vfs_memory.o \
$(BUILD_DIR)/vfs_wasi.o \
$(BUILD_DIR)/low_level_ext.o \
$(BUILD_DIR)/high_level_ext.o \
$(BUILD_DIR)/extension.o \
$(BUILD_DIR)/sqlite_wasm_ext.o \
$(BUILD_DIR)/sqlite_extensible.o \
$(BINDINGS_EXT_DIR)/sqlite_extensible_component_type.o
# Compile exports for extensible build (uses sqlite_world.h wrapper in bindings-ext)
$(BUILD_DIR)/low_level_ext.o: $(SRC_DIR)/exports/low_level.c $(BINDINGS_EXT_DIR)/sqlite_extensible.h | $(BUILD_DIR)
@echo "Compiling low-level exports (extensible)..."
$(CC) $(CFLAGS_EXT) -c $< -o $@
$(BUILD_DIR)/high_level_ext.o: $(SRC_DIR)/exports/high_level.c $(BINDINGS_EXT_DIR)/sqlite_extensible.h | $(BUILD_DIR)
@echo "Compiling high-level exports (extensible)..."
$(CC) $(CFLAGS_EXT) -c $< -o $@
$(BUILD_DIR)/extension.o: $(SRC_DIR)/exports/extension.c $(BINDINGS_EXT_DIR)/sqlite_extensible.h | $(BUILD_DIR)
@echo "Compiling extension exports..."
$(CC) $(CFLAGS_EXT) -c $< -o $@
$(BUILD_DIR)/sqlite_wasm_ext.o: $(MAIN_SRC) $(BINDINGS_EXT_DIR)/sqlite_extensible.h | $(BUILD_DIR)
@echo "Compiling main wrapper (extensible)..."
$(CC) $(CFLAGS_EXT) -c $< -o $@
$(BUILD_DIR)/sqlite_extensible.o: $(BINDINGS_EXT_DIR)/sqlite_extensible.c $(BINDINGS_EXT_DIR)/sqlite_extensible.h | $(BUILD_DIR)
@echo "Compiling generated extensible bindings..."
$(CC) $(CFLAGS_EXT) -c $< -o $@
$(EXTENSIBLE_WASM): $(OBJS_EXT)
@echo "Linking extensible WASM module..."
$(CC) $(LDFLAGS) $(OBJS_EXT) -o $@
@echo "Built: $@"
@wasm-tools component wit $@ 2>/dev/null | head -50 || true
@ls -lh $@
extensible: bindings-ext $(EXTENSIBLE_WASM)
.PHONY: extensible
# =============================================================================
# Unified build (sqlite-cli-unified world from task #12)
# =============================================================================
# Reactor build matching the sqlite-extensible target but using the
# unified sqlite:extension contract. The new C glue
# (src/exports/extension-unified.c) is the unified-WIT successor to
# extension.c; spi/logging/config exports are present, scalar dispatch
# from composed extension slots is the next iteration.
UNIFIED_WASM := $(BUILD_DIR)/sqlite-unified.wasm
CFLAGS_UNIFIED := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-O2 \
-g \
-Wall \
-Wextra \
-Wno-unused-parameter \
-I$(DEPS_DIR)/sqlite \
-I$(SRC_DIR) \
-I$(BINDINGS_UNIFIED_DIR) \
$(WASM_FEATURES) \
$(SQLITE_CFLAGS)
OBJS_UNIFIED := \
$(BUILD_DIR)/sqlite3.o \
$(BUILD_DIR)/vfs_memory.o \
$(BUILD_DIR)/vfs_wasi.o \
$(BUILD_DIR)/low_level_unified.o \
$(BUILD_DIR)/high_level_unified.o \
$(BUILD_DIR)/extension_unified.o \
$(BUILD_DIR)/sqlite_wasm_unified.o \
$(BUILD_DIR)/sqlite_cli_unified.o \
$(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified_component_type.o
$(BUILD_DIR)/low_level_unified.o: $(SRC_DIR)/exports/low_level.c $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h | $(BUILD_DIR)
@echo "Compiling low-level exports (unified)..."
$(CC) $(CFLAGS_UNIFIED) -c $< -o $@
$(BUILD_DIR)/high_level_unified.o: $(SRC_DIR)/exports/high_level.c $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h | $(BUILD_DIR)
@echo "Compiling high-level exports (unified)..."
$(CC) $(CFLAGS_UNIFIED) -c $< -o $@
$(BUILD_DIR)/extension_unified.o: $(SRC_DIR)/exports/extension-unified.c $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h | $(BUILD_DIR)
@echo "Compiling extension exports (unified)..."
$(CC) $(CFLAGS_UNIFIED) -c $< -o $@
$(BUILD_DIR)/sqlite_wasm_unified.o: $(MAIN_SRC) $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h | $(BUILD_DIR)
@echo "Compiling main wrapper (unified)..."
$(CC) $(CFLAGS_UNIFIED) -c $< -o $@
$(BUILD_DIR)/sqlite_cli_unified.o: $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.c $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h | $(BUILD_DIR)
@echo "Compiling generated unified bindings..."
$(CC) $(CFLAGS_UNIFIED) -c $< -o $@
$(UNIFIED_WASM): $(OBJS_UNIFIED)
@echo "Linking unified WASM module..."
$(CC) $(LDFLAGS) $(OBJS_UNIFIED) -o $@
@echo "Built: $@"
@ls -lh $@
unified: bindings-unified $(UNIFIED_WASM)
.PHONY: unified
# =============================================================================
# Extension builds
# =============================================================================
EXTENSIONS_DIR := $(PROJECT_ROOT)/extensions
EXT_BUILD_DIR := $(BUILD_DIR)/extensions
# Extension compiler flags (reactor mode with extension-specific flags)
EXT_CFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-O2 \
-g \
-Wall \
-Wextra \
-Wno-unused-parameter \
-I$(DEPS_DIR)/sqlite \
-I$(SRC_DIR) \
$(WASM_FEATURES) \
$(SQLITE_CFLAGS)
EXT_LDFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-mexec-model=reactor \
-Wl,--export-dynamic \
-Wl,--no-entry
# Create extension build directory
$(EXT_BUILD_DIR):
mkdir -p $(EXT_BUILD_DIR)
# FTS5 Extension
FTS5_WASM := $(EXT_BUILD_DIR)/fts5.wasm
FTS5_OBJS := $(EXT_BUILD_DIR)/fts5_ext.o $(BUILD_DIR)/sqlite3_fts5.o
$(BUILD_DIR)/sqlite3_fts5.o: $(SQLITE_SRC) | $(BUILD_DIR)
@echo "Compiling SQLite with FTS5..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_FTS5 -c $< -o $@
$(EXT_BUILD_DIR)/fts5_ext.o: $(EXTENSIONS_DIR)/fts5/fts5_ext.c | $(EXT_BUILD_DIR)
@echo "Compiling FTS5 extension wrapper..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_FTS5 -c $< -o $@
$(FTS5_WASM): $(FTS5_OBJS)
@echo "Linking FTS5 extension..."
$(CC) $(EXT_LDFLAGS) $(FTS5_OBJS) -o $@
@echo "Built: $@"
@ls -lh $@
# R-Tree Extension
RTREE_WASM := $(EXT_BUILD_DIR)/rtree.wasm
RTREE_OBJS := $(EXT_BUILD_DIR)/rtree_ext.o $(BUILD_DIR)/sqlite3_rtree.o
$(BUILD_DIR)/sqlite3_rtree.o: $(SQLITE_SRC) | $(BUILD_DIR)
@echo "Compiling SQLite with R-Tree..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_RTREE -c $< -o $@
$(EXT_BUILD_DIR)/rtree_ext.o: $(EXTENSIONS_DIR)/rtree/rtree_ext.c | $(EXT_BUILD_DIR)
@echo "Compiling R-Tree extension wrapper..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_RTREE -c $< -o $@
$(RTREE_WASM): $(RTREE_OBJS)
@echo "Linking R-Tree extension..."
$(CC) $(EXT_LDFLAGS) $(RTREE_OBJS) -o $@
@echo "Built: $@"
@ls -lh $@
# JSON1 Extension
JSON1_WASM := $(EXT_BUILD_DIR)/json1.wasm
JSON1_OBJS := $(EXT_BUILD_DIR)/json1_ext.o $(BUILD_DIR)/sqlite3_json1.o
$(BUILD_DIR)/sqlite3_json1.o: $(SQLITE_SRC) | $(BUILD_DIR)
@echo "Compiling SQLite with JSON1..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_JSON1 -c $< -o $@
$(EXT_BUILD_DIR)/json1_ext.o: $(EXTENSIONS_DIR)/json1/json1_ext.c | $(EXT_BUILD_DIR)
@echo "Compiling JSON1 extension wrapper..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_JSON1 -c $< -o $@
$(JSON1_WASM): $(JSON1_OBJS)
@echo "Linking JSON1 extension..."
$(CC) $(EXT_LDFLAGS) $(JSON1_OBJS) -o $@
@echo "Built: $@"
@ls -lh $@
# GeoPoly Extension (requires R-Tree)
GEOPOLY_WASM := $(EXT_BUILD_DIR)/geopoly.wasm
GEOPOLY_OBJS := $(EXT_BUILD_DIR)/geopoly_ext.o $(BUILD_DIR)/sqlite3_geopoly.o
$(BUILD_DIR)/sqlite3_geopoly.o: $(SQLITE_SRC) | $(BUILD_DIR)
@echo "Compiling SQLite with GeoPoly..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_GEOPOLY -DSQLITE_ENABLE_RTREE -c $< -o $@
$(EXT_BUILD_DIR)/geopoly_ext.o: $(EXTENSIONS_DIR)/geopoly/geopoly_ext.c | $(EXT_BUILD_DIR)
@echo "Compiling GeoPoly extension wrapper..."
$(CC) $(EXT_CFLAGS) -DSQLITE_ENABLE_GEOPOLY -DSQLITE_ENABLE_RTREE -c $< -o $@
$(GEOPOLY_WASM): $(GEOPOLY_OBJS)
@echo "Linking GeoPoly extension..."
$(CC) $(EXT_LDFLAGS) $(GEOPOLY_OBJS) -o $@
@echo "Built: $@"
@ls -lh $@
# Build all extensions
extensions: $(FTS5_WASM) $(RTREE_WASM) $(JSON1_WASM) $(GEOPOLY_WASM)
@echo ""
@echo "All extensions built:"
@ls -lh $(EXT_BUILD_DIR)/*.wasm
# =============================================================================
# Unified CLI (command-mode driver for the unified-WIT build)
# =============================================================================
# Command binary that links the same unified glue as the reactor
# (extension-unified.c with its auto-extension chain, low_level /
# high_level / sqlite_wasm / bindings) plus the existing CLI front-end
# (src/cli/sqlite_cli.c). The CLI calls sqlite3 directly; the unified
# glue surfaces the per-slot imports so a `wac plug` of the demo
# extension satisfies them.
CLI_UNIFIED_WASM := $(BUILD_DIR)/sqlite-cli-unified.wasm
CLI_UNIFIED_CFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-O2 \
-g \
-Wall \
-I$(DEPS_DIR)/sqlite \
-I$(SRC_DIR) \
-I$(BINDINGS_UNIFIED_DIR) \
-D_WASI_EMULATED_PROCESS_CLOCKS \
-DSQLITE_WASM_UNIFIED=1 \
$(WASM_FEATURES) \
$(SQLITE_CFLAGS)
CLI_UNIFIED_LDFLAGS := \
--target=$(TARGET) \
--sysroot=$(WASI_SYSROOT) \
-lwasi-emulated-process-clocks \
-Wl,-z,stack-size=131072
CLI_UNIFIED_OBJS := \
$(BUILD_DIR)/sqlite3.o \
$(BUILD_DIR)/vfs_memory.o \
$(BUILD_DIR)/vfs_wasi.o \
$(BUILD_DIR)/sqlite_wasm_unified.o \
$(BUILD_DIR)/extension_unified.o \
$(BUILD_DIR)/low_level_unified.o \
$(BUILD_DIR)/high_level_unified.o \
$(BUILD_DIR)/sqlite_cli_unified_main.o \
$(BUILD_DIR)/sqlite_cli_unified.o \
$(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified_component_type.o
$(BUILD_DIR)/sqlite_cli_unified_main.o: $(CLI_SRC) $(BINDINGS_UNIFIED_DIR)/sqlite_cli_unified.h | $(BUILD_DIR)
@echo "Compiling CLI main (unified)..."
$(CC) $(CLI_UNIFIED_CFLAGS) -c $< -o $@
$(CLI_UNIFIED_WASM): $(CLI_UNIFIED_OBJS)
@echo "Linking CLI (unified)..."
$(CC) $(CLI_UNIFIED_LDFLAGS) $(CLI_UNIFIED_OBJS) -o $@
@echo "Built: $@"
@ls -lh $@
cli-unified: bindings-unified $(CLI_UNIFIED_WASM)
.PHONY: cli-unified
# Demo extension (unified-WIT demonstration; pairs with `unified` target).
# Exports sqlite:wasm/demo-slot and implements wasm_reverse + wasm_double.
DEMO_DIR := $(EXTENSIONS_DIR)/wasm-demo
DEMO_WASM := $(EXT_BUILD_DIR)/wasm-demo.wasm
DEMO_BINDINGS := $(DEMO_DIR)/src
$(DEMO_BINDINGS)/demo_extension.h: $(DEMO_DIR)/wit/world.wit $(DEMO_DIR)/wit/deps/sqlite-wasm/wasm-slots.wit
@echo "Generating demo extension bindings..."
wit-bindgen c $(DEMO_DIR)/wit --world demo-extension --out-dir $(DEMO_BINDINGS)
$(EXT_BUILD_DIR)/demo_ext.o: $(DEMO_DIR)/demo_ext.c $(DEMO_BINDINGS)/demo_extension.h | $(EXT_BUILD_DIR)
@echo "Compiling demo extension wrapper..."
$(CC) $(EXT_CFLAGS) -I$(DEMO_BINDINGS) -c $< -o $@
$(EXT_BUILD_DIR)/demo_extension.o: $(DEMO_BINDINGS)/demo_extension.c $(DEMO_BINDINGS)/demo_extension.h | $(EXT_BUILD_DIR)
@echo "Compiling generated demo bindings..."
$(CC) $(EXT_CFLAGS) -I$(DEMO_BINDINGS) -c $< -o $@
$(DEMO_WASM): $(EXT_BUILD_DIR)/demo_ext.o $(EXT_BUILD_DIR)/demo_extension.o $(DEMO_BINDINGS)/demo_extension_component_type.o
@echo "Linking demo extension..."
$(CC) $(EXT_LDFLAGS) $^ -o $@
@echo "Built: $@"
@ls -lh $@
extension-demo: $(DEMO_WASM)
# Compose the demo extension into the unified host. Produces a single
# wasm where every sqlite:wasm/<name>-slot import is satisfied — the
# real impls for demo-slot (wasm_reverse, wasm_double) and stub
# manifests for the four legacy slots.
COMPOSED_DEMO_WASM := $(BUILD_DIR)/sqlite-demo-composed.wasm
$(COMPOSED_DEMO_WASM): $(UNIFIED_WASM) $(DEMO_WASM)
@echo "Composing sqlite-unified + wasm-demo via wac plug..."
wac plug --plug $(DEMO_WASM) $(UNIFIED_WASM) -o $@
@echo "Built: $@"
@ls -lh $@
cli-demo: $(COMPOSED_DEMO_WASM)
# Composed COMMAND-mode CLI with the demo extension wired in. The
# resulting wasm runs directly under wasmtime, accepts SQL on stdin,
# and prints results on stdout — including the wasm_reverse and
# wasm_double functions the demo extension provides.
CLI_DEMO_WASM := $(BUILD_DIR)/sqlite-cli-demo.wasm
$(CLI_DEMO_WASM): $(CLI_UNIFIED_WASM) $(DEMO_WASM)
@echo "Composing CLI + demo via wac plug..."
wac plug --plug $(DEMO_WASM) $(CLI_UNIFIED_WASM) -o $@
@echo "Built: $@"
@ls -lh $@
cli-demo-test: $(CLI_DEMO_WASM)
.PHONY: extension-demo cli-demo cli-demo-test
# =============================================================================
# WASM Component Composition
# =============================================================================
# Path to zip-wasm component (set via environment or use default)
ZIP_WASM ?= $(HOME)/git/zip-wasm/build/zip-wasm.wasm
# Composed CLI with ZIP support
CLI_ZIP_WASM := $(BUILD_DIR)/sqlite-cli-zip.wasm
# Compose CLI with zip-wasm for .archive command support
$(CLI_ZIP_WASM): $(CLI_WASM) $(ZIP_WASM)
@echo "Composing CLI with zip-wasm..."
@if [ -f "$(ZIP_WASM)" ]; then \
wasm-tools compose $(CLI_WASM) \
-d zip-operations=$(ZIP_WASM) \
-o $@; \
echo "Built: $@"; \
ls -lh $@; \
else \
echo "Warning: zip-wasm not found at $(ZIP_WASM)"; \
echo "Set ZIP_WASM environment variable or build zip-wasm first"; \
echo "Skipping composition, copying CLI without ZIP support"; \
cp $(CLI_WASM) $@; \
fi
cli-zip: $(CLI_ZIP_WASM)
# Compose CLI with common extensions (FTS5 + JSON1)
CLI_COMMON_WASM := $(BUILD_DIR)/sqlite-cli-common.wasm
$(CLI_COMMON_WASM): $(CLI_WASM) $(FTS5_WASM) $(JSON1_WASM)
@echo "Composing CLI with common extensions..."
wasm-tools compose $(CLI_WASM) \
-d fts5=$(FTS5_WASM) \
-d json1=$(JSON1_WASM) \
-o $@
@echo "Built: $@"
@ls -lh $@
cli-common: $(CLI_COMMON_WASM)
# Compose CLI with all features (extensions + ZIP)
CLI_FULL_WASM := $(BUILD_DIR)/sqlite-cli-full.wasm
$(CLI_FULL_WASM): $(CLI_WASM) $(FTS5_WASM) $(JSON1_WASM) $(RTREE_WASM) $(GEOPOLY_WASM)
@echo "Composing full CLI..."
@if [ -f "$(ZIP_WASM)" ]; then \
wasm-tools compose $(CLI_WASM) \
-d fts5=$(FTS5_WASM) \
-d json1=$(JSON1_WASM) \
-d rtree=$(RTREE_WASM) \
-d geopoly=$(GEOPOLY_WASM) \
-d zip-operations=$(ZIP_WASM) \
-o $@; \
else \
wasm-tools compose $(CLI_WASM) \
-d fts5=$(FTS5_WASM) \
-d json1=$(JSON1_WASM) \
-d rtree=$(RTREE_WASM) \
-d geopoly=$(GEOPOLY_WASM) \
-o $@; \
echo "Note: Built without ZIP support (zip-wasm not found)"; \
fi
@echo "Built: $@"
@ls -lh $@
cli-full: extensions $(CLI_FULL_WASM)
# =============================================================================
# Composition via wac (forward-looking; pairs with the unified-WIT migration)
# =============================================================================
# Builds the full CLI by composing sqlite-cli.wasm with all four in-WASM
# extensions via the `wac` composer. Per-instance wiring is described in
# composition.wac. Requires task #12 (the wit/ swap to sqlite:extension +
# per-extension slot interfaces in sqlite:wasm). Until that lands, prefer
# the `cli-full` target above which uses `wasm-tools compose`.
CLI_WAC_WASM := $(BUILD_DIR)/sqlite-cli-wac.wasm
$(CLI_WAC_WASM): composition.wac $(CLI_WASM) $(FTS5_WASM) $(JSON1_WASM) $(RTREE_WASM) $(GEOPOLY_WASM)
@echo "Composing CLI with wac..."
@command -v wac >/dev/null 2>&1 || (echo "wac not found. Install with: cargo install wac-cli" && exit 1)
wac compose composition.wac \
-d sqlite:wasm=$(CLI_WASM) \
-d sqlite:fts5-extension=$(FTS5_WASM) \
-d sqlite:json1-extension=$(JSON1_WASM) \
-d sqlite:rtree-extension=$(RTREE_WASM) \
-d sqlite:geopoly-extension=$(GEOPOLY_WASM) \
-o $@
@echo "Built: $@"
@ls -lh $@
cli-wac: extensions $(CLI_WAC_WASM)
.PHONY: cli-zip cli-common cli-full cli-wac
# =============================================================================
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)
rm -rf $(BINDINGS_DIR)
rm -rf $(BINDINGS_EXT_DIR)
# Clean everything including dependencies
distclean: clean
rm -rf $(DEPS_DIR)/sqlite/sqlite3.*
rm -rf $(DEPS_DIR)/wasi-sdk*
# Verify toolchain
verify-tools:
@echo "Checking required tools..."
@command -v $(CC) >/dev/null 2>&1 || (echo "wasi-sdk not found. Run 'make wasi-sdk'" && exit 1)
@command -v wit-bindgen >/dev/null 2>&1 || (echo "wit-bindgen not found. Install with: cargo install wit-bindgen-cli" && exit 1)
@command -v wasm-tools >/dev/null 2>&1 || (echo "wasm-tools not found. Install with: cargo install wasm-tools" && exit 1)
@echo "All required tools found."
# Fail if deps/sqlite/sqlite3.h and libsqlite3-sys's vendored bundle
# disagree on SQLITE_VERSION. The Makefile's C-built targets compile
# the former; cargo's wasm cli component links the latter with the
# `bundled` feature. Drift means `SELECT sqlite_version()` reports
# different strings depending on which artifact you invoke.
verify-sqlite-version:
@./scripts/check-sqlite-version.sh
# PLAN-wasmmachine.md E3: register sqlite-cli as a wasmMachine
# application. wasmmachine-build hashes the cli component and
# substitutes the digest into the spec template; -seal and -run
# delegate to v86's wasmmachine binary (expected on PATH from
# ~/git/v86/target/release).
wasmmachine-build:
@./wasmmachine/build-spec.sh
wasmmachine-seal: wasmmachine-build
@command -v wasmmachine >/dev/null 2>&1 || \
(echo "wasmmachine not found. Build from ~/git/v86 or add it to PATH." && exit 1)
wasmmachine seal wasmmachine/sqlite-cli.json
wasmmachine-run: wasmmachine-build
@command -v wasmmachine >/dev/null 2>&1 || \
(echo "wasmmachine not found. Build from ~/git/v86 or add it to PATH." && exit 1)
wasmmachine run wasmmachine/sqlite-cli.json
# Print configuration
info:
@echo "Configuration:"
@echo " PROJECT_ROOT: $(PROJECT_ROOT)"
@echo " WASI_SDK: $(WASI_SDK)"
@echo " TARGET: $(TARGET)"
@echo " CC: $(CC)"
@echo ""
@echo "SQLite flags:"
@echo " $(SQLITE_CFLAGS)" | tr ' ' '\n' | grep -v '^$$'
# PLAN-extension-tooling.md T3 + T4: one-shot build + component-wrap
# + provenance scan + smoke for a single extension. Replaces the
# 4-step manual sequence.
#
# Usage:
# make ext NAME=detect
# make ext NAME=detect BOOTSTRAP=1 # if the compat-registry flags it
#
# Expects extensions/<NAME>/ to exist (scaffold via
# tooling/scaffold.py first). Wrapping uses the cached wasi-preview1
# adapter at $HOME/.cache/xtran/.
WASI_ADAPTER ?= $(HOME)/.cache/xtran/wasi_snapshot_preview1.reactor.wasm
# Shared target dir for all scaffolded extensions. wit-bindgen + serde
# + common deps recompile once across the whole catalog instead of once
# per extension. Steady-state per-ext rebuild drops from 30-50s to ~5s.
EXT_SHARED_TARGET := $(PROJECT_ROOT)/extensions/_shared-target
ext:
@test -n "$(NAME)" || (echo "usage: make ext NAME=<extension>"; exit 1)
@test -d "extensions/$(NAME)" || (echo "no such extension: extensions/$(NAME)"; exit 1)
@# Look for the artifact in three places, in order:
@# 1. shared scaffold target (scaffolded extensions w/ shared cache)
@# 2. per-extension target (older scaffold layout, kept for back-compat)
@# 3. top-level target (workspace-member extensions like uuid / crypto)
@NAME_UNDERSCORE=$$(echo "$(NAME)" | tr - _); \
if grep -q '^\[workspace\]' extensions/$(NAME)/Cargo.toml 2>/dev/null; then \
CARGO_TARGET_DIR=$(EXT_SHARED_TARGET) $(if $(BOOTSTRAP),RUSTC_BOOTSTRAP=1 )cargo wbuild --release \
--manifest-path extensions/$(NAME)/Cargo.toml; \
else \
$(if $(BOOTSTRAP),RUSTC_BOOTSTRAP=1) cargo wbuild --release \
--manifest-path extensions/$(NAME)/Cargo.toml; \
fi; \
WASM_BASE=""; \
for D in $(EXT_SHARED_TARGET)/wasm32-wasip2/release \
extensions/$(NAME)/target/wasm32-wasip2/release \
target/wasm32-wasip2/release; do \
CAND=$$D/$${NAME_UNDERSCORE}_extension.wasm; \
if [ -f "$$CAND" ]; then WASM_BASE=$$CAND; break; fi; \
done; \
test -n "$$WASM_BASE" || (echo "no built wasm artifact found"; exit 1); \
mkdir -p extensions/$(NAME)/target/wasm32-wasip2/release; \
COMPONENT_OUT=extensions/$(NAME)/target/wasm32-wasip2/release/$${NAME_UNDERSCORE}_extension.component.wasm; \
bash tooling/wasm-opt-core.sh "$$WASM_BASE"; \
wasm-tools component new "$$WASM_BASE" \
--adapt wasi_snapshot_preview1=$(WASI_ADAPTER) \
-o "$$COMPONENT_OUT"; \
echo "wrote $$COMPONENT_OUT"
@python3 provenance/scan.py 2>&1 | tail -3
@python3 provenance/build_registry.py 2>&1 | tail -1
@python3 tooling/smoke.py $(NAME) || true
ext-list-broken:
@python3 tooling/scaffold.py --list-broken
ext-smoke-all:
@python3 tooling/smoke.py --all -j 0 # T-17: parallel; -j N to override
# T-44: cli-level smokes one .sql per dot command suite
# (.session, .serialize, ...) under tooling/cli-smokes/.
cli-smoke-all:
@python3 tooling/cli-smoke.py --all
# Benchmarks against native sqlite3. See PLAN-benchmarks.md.
# Pass SIZES=... or WORKLOADS=... to narrow; CWASM=1 to use the
# precompiled cli component (cuts ~360 ms startup per invocation).
bench:
@python3 tooling/bench.py $(if $(SIZES),--sizes $(SIZES)) $(if $(WORKLOADS),--workloads $(WORKLOADS)) $(if $(CWASM),--cwasm)
# AOT-compile sqlite_cli.component.wasm to .cwasm. Loading the
# precompiled blob via Component::deserialize_file skips wasmtime's
# parse + validate + cranelift compile, dropping cli startup from
# ~370 ms to ~10 ms. Output is host-CPU-specific not portable.
PRECOMPILE_IN := target/wasm32-wasip2/release/sqlite_cli.component.wasm
PRECOMPILE_OUT := target/wasm32-wasip2/release/sqlite_cli.component.cwasm
precompile-cli: $(PRECOMPILE_OUT)
$(PRECOMPILE_OUT): $(PRECOMPILE_IN) target/release/sqlink
@./target/release/sqlink precompile $(PRECOMPILE_IN) $(PRECOMPILE_OUT)
ext-check-snippets:
@python3 tooling/check-snippets.py
# T-27: end-of-ship wrapper. Build + single-smoke (via `ext`) then
# run --all to catch regressions before committing. Cheap (~15s for
# the full catalog at -j 0); the only reason `ext` itself doesn't
# do this is to keep the compile-fix-iterate loop fast.
ext-ship:
@test -n "$(NAME)" || (echo "usage: make ext-ship NAME=<extension>"; exit 1)
@$(MAKE) ext NAME=$(NAME)
@echo ""
@echo "=== regression check: smoke --all -j 0 ==="
@python3 tooling/smoke.py --all -j 0
# ───────────────────────────────────────────────────────────────────
# Task #227: ext-provider — build a compose:dynlink RESIDENT provider
# (`<ext>-provider.wasm`) for an extension by `wac plug`-ing it into the
# right woco provider world-shape, and drop it into the host fixtures dir
# so `.load <ext>-provider.wasm` and the host matrix tests use an in-tree
# artifact instead of a prebuilt fixture.
#
# Reuses woco-sqlite-ext-endpoint's build recipe (one provider SHAPE per
# tier, same source, `wac plug` with the extension component). The shape
# is picked from a fixed NAME->tier map (extend it as new providers land).
#
# make ext-provider NAME=aba # scalar
# make ext-provider NAME=count_min # aggregate
# make ext-provider NAME=series # vtab
# make ext-provider NAME=inmem # vtab-mut
#
# Vars:
# WOCO_ROOT woco-sqlite-ext-endpoint checkout (default ~/git/...)
# PROVIDER_OUT where the <ext>-provider.wasm lands
# (default host/tests/fixtures/providers)
WOCO_ROOT ?= $(HOME)/git/woco-sqlite-ext-endpoint
PROVIDER_OUT ?= $(PROJECT_ROOT)/host/tests/fixtures/providers
ext-provider:
@test -n "$(NAME)" || (echo "usage: make ext-provider NAME=<extension>"; exit 1)
@test -d "$(WOCO_ROOT)/sqlite-extension-endpoint" || \
(echo "woco-sqlite-ext-endpoint not found at $(WOCO_ROOT); set WOCO_ROOT="; exit 1)
@command -v wac >/dev/null 2>&1 || (echo "wac not found: cargo install wac-cli"; exit 1)
@command -v wasm-tools >/dev/null 2>&1 || (echo "wasm-tools not found"; exit 1)
@# NAME -> woco provider shape (Cargo feature on the provider crate).
@case "$(NAME)" in \
aba) SHAPE=scalar ;; \
count_min) SHAPE=aggregate ;; \
uint) SHAPE=collation ;; \
series) SHAPE=vtab ;; \
inmem) SHAPE=vtab-mut ;; \
hookcb) SHAPE=hooks ;; \
dotret|greet) SHAPE=dotcmd ;; \
*) echo "no known provider shape for '$(NAME)' (edit the NAME->SHAPE map in Makefile)"; exit 1 ;; \
esac; \
echo "==> [ext-provider] $(NAME) shape=$$SHAPE"; \
PROV_DIR="$(WOCO_ROOT)/sqlite-extension-endpoint"; \
PROV_CORE="$$PROV_DIR/provider/target/wasm32-wasip2/release/sqlite_extension_endpoint.wasm"; \
PROV_WASM="$$PROV_DIR/provider/target/wasm32-wasip2/release/sqlite_extension_endpoint.component.wasm"; \
NAME_UNDERSCORE=$$(echo "$(NAME)" | tr - _); \
echo "==> building provider shape '$$SHAPE' (core -> wasm-opt -> component)"; \
( cd "$$PROV_DIR/provider" && RUSTFLAGS="-C link-arg=--no-entry" cargo build --release \
--target wasm32-wasip2 --no-default-features --features "$$SHAPE" \
--config 'target.wasm32-wasip2.linker="rust-lld"' >/dev/null ); \
bash tooling/wasm-opt-core.sh "$$PROV_CORE"; \
wasm-tools component new "$$PROV_CORE" \
--adapt wasi_snapshot_preview1=$(WASI_ADAPTER) -o "$$PROV_WASM" 2>/dev/null \
|| wasm-tools component new "$$PROV_CORE" -o "$$PROV_WASM"; \
echo "==> building + componentizing extension $(NAME)"; \
$(MAKE) ext NAME=$(NAME) >/dev/null 2>&1 || true; \
EXT_COMP=""; \
for D in $(EXT_SHARED_TARGET)/wasm32-wasip2/release \
extensions/$(NAME)/target/wasm32-wasip2/release \
target/wasm32-wasip2/release; do \
C=$$D/$${NAME_UNDERSCORE}_extension.component.wasm; \
[ -f "$$C" ] && EXT_COMP=$$C && break; \
C=$$D/$${NAME_UNDERSCORE}_extension.wasm; \
[ -f "$$C" ] && EXT_COMP=$$C && break; \
done; \
test -n "$$EXT_COMP" || (echo "no built extension component for $(NAME)"; exit 1); \
mkdir -p "$(PROVIDER_OUT)"; \
OUT="$(PROVIDER_OUT)/$(NAME)-provider.wasm"; \
echo "==> wac plug $$EXT_COMP + provider -> $$OUT"; \
wac plug --plug "$$EXT_COMP" "$$PROV_WASM" -o "$$OUT"; \
LEFT=$$(wasm-tools component wit "$$OUT" 2>/dev/null \
| grep -E '^ import sqlite:extension/[a-z-]+@' | grep -vE 'types|policy|cli-' || true); \
echo " -> $$(basename $$OUT) (leftover host imports: $${LEFT:-none})"
.PHONY: ext ext-list-broken ext-smoke-all cli-smoke-all bench precompile-cli ext-check-snippets ext-ship ext-provider