src/db/sqlite.sx grows from the P5.1 subset (~19 fns) to the complete practical surface (~100): open_v2 + flags, extended errcodes + error_offset, txn_state/autocommit, changes64/total_changes64, limits, the full bind/column families (double/blob/zeroblob), parameter and column introspection (built with SQLITE_ENABLE_COLUMN_METADATA), table_column_metadata, statement introspection (sql/expanded_sql/ readonly/busy/isexplain/status), incremental blob I/O (SqliteBlob), online backup (SqliteBackup + sqlite_backup_run), serialize/ deserialize, and library utilities (complete, strglob/strlike/stricmp, randomness, memory, compileoptions). One variant per duplicate family (modern/64-bit preferred; bind_text/blob keep the 32-bit length forms that skip text64's encoding arg). Not bound, by design: callback-taking APIs (hooks/UDFs/collations need C->sx callbacks), sqlite3_value_* (UDF-coupled), varargs config, UTF-16, and subsystems this build omits — the boundary list lives in the module header and vendor README. rename.h is now GENERATED by make into build/vendor/ from the bindings' #foreign names — src/db/sqlite.sx is the single source of truth and the rename list cannot drift (checked-in vendor/sqlite/rename.h removed). make test 21/21 (new: sqlite_api.sx — 15 cases over every wrapper family, including a blob round trip with interior NULs, UNIQUE constraint extended errcodes, txn_state through BEGIN IMMEDIATE, backup db->db, and a serialize->deserialize round trip). KNOWN sx BOUNDARY (filed as a followup): 'if !e' on an error binding evaluates true even when the error is set — negated error logic in tests routes through plain bools.
71 lines
2.9 KiB
Makefile
71 lines
2.9 KiB
Makefile
# distribution — build/test gate.
|
|
#
|
|
# The sx compiler lives in a separate repo; locate it via SX (overridable):
|
|
# make build SX=/path/to/sx
|
|
SX ?= /Users/agra/projects/sx/zig-out/bin/sx
|
|
|
|
BUILD_DIR := build
|
|
|
|
# Programs compiled by `make build`: the smoke program and the `dist`
|
|
# product entry point. Further entry points under src/ get added here as
|
|
# they land.
|
|
SMOKE := tests/smoke.sx
|
|
DIST := src/dist.sx
|
|
|
|
# Vendored SQLite (vendor/sqlite/README.md): one amalgamation, two build
|
|
# products in two DIRECTORIES — the macOS linker prefers a dylib over an
|
|
# archive in the same -L directory, and `sx build` must link the static
|
|
# copy while `sx run` (the test runner) dlopens the dylib.
|
|
#
|
|
# rename.h is GENERATED from the bindings: every `dist_sqlite3_*` symbol
|
|
# named in src/db/sqlite.sx gets a #define, so the rename list and the
|
|
# bound surface cannot drift (see the README for why renaming exists).
|
|
VENDOR_DIR := $(BUILD_DIR)/vendor
|
|
SQLITE_SRC := vendor/sqlite/sqlite3.c
|
|
SQLITE_DEFS := -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 \
|
|
-DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_SHARED_CACHE \
|
|
-DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_ENABLE_COLUMN_METADATA \
|
|
-include $(VENDOR_DIR)/rename.h
|
|
|
|
$(VENDOR_DIR)/rename.h: src/db/sqlite.sx
|
|
@mkdir -p $(VENDOR_DIR)
|
|
@{ echo '/* GENERATED by make from src/db/sqlite.sx — do not edit. */'; \
|
|
grep -o '"dist_sqlite3_[a-z0-9_]*"' src/db/sqlite.sx | tr -d '"' | sort -u | \
|
|
sed 's/^dist_\(.*\)/#define \1 dist_\1/'; } > $@
|
|
|
|
$(VENDOR_DIR)/libsqlite3.a: $(SQLITE_SRC) vendor/sqlite/sqlite3.h $(VENDOR_DIR)/rename.h
|
|
@mkdir -p $(VENDOR_DIR)
|
|
cc $(SQLITE_DEFS) -O2 -c $(SQLITE_SRC) -o $(VENDOR_DIR)/sqlite3.o
|
|
ar rcs $@ $(VENDOR_DIR)/sqlite3.o
|
|
|
|
$(VENDOR_DIR)/jit/libsqlite3.dylib: $(SQLITE_SRC) vendor/sqlite/sqlite3.h $(VENDOR_DIR)/rename.h
|
|
@mkdir -p $(VENDOR_DIR)/jit
|
|
cc $(SQLITE_DEFS) -O2 -dynamiclib $(SQLITE_SRC) -o $@
|
|
|
|
.PHONY: build test publish-example vendor clean
|
|
|
|
vendor: $(VENDOR_DIR)/libsqlite3.a $(VENDOR_DIR)/jit/libsqlite3.dylib
|
|
|
|
# Compile the product sources (and the smoke program) without running.
|
|
build: vendor
|
|
@mkdir -p $(BUILD_DIR)
|
|
$(SX) build -o $(BUILD_DIR)/smoke $(SMOKE)
|
|
$(SX) build -o $(BUILD_DIR)/dist $(DIST) -L $(VENDOR_DIR)
|
|
|
|
# Run the test runner over every tests/**/*.sx. Exits non-zero on any
|
|
# failure. Depends on `build` so the CLI acceptance test (tests/cli_*.sx)
|
|
# finds a fresh `build/dist` to drive.
|
|
test: build
|
|
@SX="$(SX)" ./tests/run.sh
|
|
|
|
# End-to-end local publish of examples/dist.json into a fresh .sx-tmp/
|
|
# store, emitting the machine-readable JSON result on stdout. Depends on
|
|
# `build` so build/dist exists; the store is reset first so re-runs don't
|
|
# collide on the release id.
|
|
publish-example: build
|
|
@rm -rf .sx-tmp/publish-example
|
|
./$(BUILD_DIR)/dist ci publish --manifest examples/dist.json --local-store .sx-tmp/publish-example --json
|
|
|
|
clean:
|
|
@rm -rf $(BUILD_DIR)
|