0273. Vendored SQLite as a toolchain battery
- Status: Accepted (maintainer, 2026-11-22: "follow the existing plans" for R3; the plan's recommended defaults are adopted here and can be revisited)
- Date: 2026-11-22
- Plan: SQ0 (SQLite plan, SQ1–SQ7)
- Builds on: ADR-0245 (SQLite is in the toolchain set), ADR-0067/0210/0236 (native build cache)
Context
plugins/sqlite needs a system
libsqlite3 (pkg-config) and returns only text cells.
ADR-0245 lists SQLite in the toolchain set. SQ0 left three
questions: may the toolchain vendor C sources, what the package's
capability boundary is, and what the defaults are.
Decision
- Vendoring. The toolchain may vendor C sources
under
third_party/<name>/<version>/with the upstream version, a SHA3-256 or SHA-256 checksum and a license note. The first is SQLite's public-domain amalgamation (sqlite3.c,sqlite3.h). The driver compiles vendored translation units once into cached objects (keyed like other native builds, including the compiler and its flags) and links them into C builds and the ffi-host helper. An owner-run script updates the pinned copy. A system-library opt-out (TENON_SQLITE=system) keeps the pkg-config path. - Compile options. Use a fixed, documented set:
threadsafe off (single-threaded use, as today), extension loading
omitted, defensive mode on, and the ATTACH-denying authorizer
kept.
PRAGMA compile_optionshas a golden. - Capability boundary. The toolchain-shipped
sqlitepackage needs onlyfs. Apps do not declare anfficeiling for it, because its native code ships with the toolchain.Fsgrants and sandbox rules cover the database directory, since SQLite writes-wal,-shmand-journalfiles beside the file. - Defaults. WAL journal mode, a busy timeout,
foreign keys on,
BEGIN IMMEDIATEfor write transactions, and STRICT tables recommended. Hostile-input guards stay: defensive mode, no extensions,sqlite3_limitsettings and a progress-handler deadline (SQ4). plugins/sqlitestays as the FFI teaching example until SQ7 decides whether to keep or remove it.
Alternatives considered
- System library only: apps fail to build on machines without libsqlite3 and get mixed versions.
- Keep the
fficeiling: this is honest about native code, but it makes every app that only wants a database grant arbitrary FFI.
Consequences
SQ1 changes the build path that every test uses. It lands
behind the full make check and a test-suite timing
check. The vendored copy is the toolchain's to update, and the
release checklist reviews SQLite's security page.