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

@@ -7,26 +7,21 @@
`sqlite3ext.h` dropped — no shell, no loadable extensions)
- License: public domain (<https://sqlite.org/copyright.html>)
`make build` compiles this into `build/vendor/libsqlite3.a` (statically
linked into the `dist` binary via `-L build/vendor`) and
`build/vendor/jit/libsqlite3.dylib` (dlopen'd by `sx run`, which is how
`make test` executes the test programs). The two locations are separate
on purpose: the macOS linker prefers a dylib over an archive in the same
search directory, and the AOT binary must link the static copy.
`tests/sqlite_smoke.sx` asserts `sqlite3_libversion()` equals the version
above, so a fallback to the OS libsqlite3 fails loudly in both modes.
## Symbol renaming
The sx JIT resolves `#foreign` symbols via `dlsym(RTLD_DEFAULT)`, which
searches every image already loaded into the process — the OS libsqlite3
is usually among them and wins by load order. So every API function the
bindings use is renamed `dist_sqlite3_*` in the vendored build: those
symbols exist ONLY here, making resolution unambiguous in both JIT and
AOT modes. The rename header is GENERATED by `make` into
`build/vendor/rename.h` from the `#foreign` names in
`src/db/sqlite.sx` — the bindings file is the single source of truth,
and the rename list cannot drift from it.
The amalgamation is part of the program, not the build system:
`src/db/sqlite.sx` declares it as a named `#import c` unit carrying the
pinned compile options (`SQLITE_DQS=0`, `SQLITE_THREADSAFE=0`,
`SQLITE_DEFAULT_MEMSTATUS=0`, `SQLITE_OMIT_DEPRECATED`,
`SQLITE_OMIT_SHARED_CACHE`, `SQLITE_LIKE_DOESNT_MATCH_BLOBS`,
`SQLITE_ENABLE_COLUMN_METADATA`, `-O2`), and every `#foreign sqlib`
binding resolves against that unit. sx compiles the unit through its
content-addressed object cache (`.sx-cache/`), so the 250k-line source
builds once per checkout — `sx build` links the objects into the
binary, `sx run` loads them as a PRIORITY symbol-search target ahead of
the process images, which is why the OS libsqlite3 (a different
version, loaded into the compiler process by CoreServices) can never
shadow this copy. `tests/sqlite_smoke.sx` asserts
`sqlite3_libversion()` equals the version above, so any fallback fails
loudly in both modes.
## Bound surface
@@ -42,5 +37,6 @@ variants, and subsystems this build omits (mutex/VFS under
`SQLITE_THREADSAFE=0`, sessions/snapshots/vtabs, deprecated API).
To upgrade: replace `sqlite3.c`/`sqlite3.h` with a newer amalgamation,
update this file and the version constant in `tests/sqlite_smoke.sx`, and
run `make clean test`.
update this file and the version constant in `tests/sqlite_smoke.sx`,
and run `make clean test` (the object cache keys on the source bytes,
so the new amalgamation recompiles automatically).