sqlite is part of the program: #import c unit replaces the Makefile cc build

src/db/sqlite.sx declares the vendored amalgamation as a named
'#import c' unit (pinned defines + -O2 + #source); every #foreign
binding resolves against it with UNPREFIXED sqlite3_* names. sx
compiles the unit through its content-addressed object cache — once
per checkout — links the objects into 'sx build' binaries, and loads
them as a priority symbol target under 'sx run', so the OS libsqlite3
can never shadow the vendored copy (the version pin in sqlite_smoke
proves it).

Retired: the Makefile vendor targets (cc -> .a + jit/.dylib), the
GENERATED dist_sqlite3_* rename.h (the JIT no longer resolves
program-owned symbols through the process images, so the rename's
reason is gone), and the -L plumbing in make build + tests/run.sh.
make test 22/22; otool -L build/dist carries no libsqlite3.
This commit is contained in:
agra
2026-06-12 17:27:21 +03:00
parent a1f13c4356
commit 06f99b3606
6 changed files with 154 additions and 172 deletions

View File

@@ -9,48 +9,23 @@ 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.
#
# The vendored SQLite (vendor/sqlite/) is part of the PROGRAM, not the
# build system: src/db/sqlite.sx declares it as a named `#import c` unit
# (pinned defines + -O2 + #source), so sx compiles and links it through
# its content-addressed object cache (.sx-cache/) — once per checkout.
# `sx build` links the unit's objects into the binary; `sx run` loads
# them as a priority symbol target the OS libsqlite3 cannot shadow.
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
.PHONY: build test publish-example clean
# Compile the product sources (and the smoke program) without running.
build: vendor
build:
@mkdir -p $(BUILD_DIR)
$(SX) build -o $(BUILD_DIR)/smoke $(SMOKE)
$(SX) build -o $(BUILD_DIR)/dist $(DIST) -L $(VENDOR_DIR)
$(SX) build -o $(BUILD_DIR)/dist $(DIST)
# 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)
@@ -67,4 +42,4 @@ publish-example: build
./$(BUILD_DIR)/dist ci publish --manifest examples/dist.json --local-store .sx-tmp/publish-example --json
clean:
@rm -rf $(BUILD_DIR)
@rm -rf $(BUILD_DIR) .sx-cache