Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

#92

Link SQLite dynamically through cgo

merged · by keenan 10d ago · merged into main at 95425af7 by keenan 10d ago

keenan opened this 10d ago

Replaces the pure-Go SQLite translation with the cgo driver linked against the system libsqlite3, so the release binaries and packages get smaller and the database work gets faster.

Measured with the release flags (-trimpath -ldflags "-s -w -buildid=", linux/amd64, go1.27.3):

Artifact Before After
vole-linux-amd64 23,085,180 B 19,336,944 B (−16.2%)
vole-linux-arm64 — 17,882,840 B
vole_0.0.0-1_amd64.deb 18,108,946 B 8,043,712 B
vole-0.0.0-1.x86_64.rpm 18,531,697 B 8,406,400 B

The trade: the binary now needs libsqlite3.so.0 where it runs. Both packages declare it (libsqlite3-0 for deb, sqlite-libs for rpm), and building from source needs a C compiler and the SQLite headers (libsqlite3-dev, sqlite-devel). README and Getting started say so.

What changed:

  • modernc.org/sqlite → github.com/mattn/go-sqlite3, with the -tags libsqlite3 build tag so the driver links the system library instead of compiling its bundled copy.
  • The six DSNs: modernc-only _pragma=busy_timeout(5000) / _pragma=journal_mode(WAL) / _pragma=foreign_keys(1) became _busy_timeout=5000 / _journal_mode=WAL / _foreign_keys=1; the driver name became sqlite3. The busy timeout, WAL, immediate write transactions, and foreign keys are the same as before.
  • Verify and release images set CGO_ENABLED=1 and GOFLAGS=-tags=libsqlite3, and install the SQLite development headers, so CI tests against the same library the packages depend on.
  • The release image adds the arm64 architecture and gcc-aarch64-linux-gnu, so both architectures are still built in one job. Both binaries still rebuild byte for byte from the same tag; I checked by building each twice.
  • packaging/nfpm.yaml declares the per-format runtime dependency through nfpm’s overrides.
  • The release image also defines the ci user that the verify image already has. Without it, vole workflow run release fails its test step when the container runs as the host’s uid, because the ssh tests call getpwuid().

Verified locally: vole workflow run verify passes end to end (format, vet, build, govulncheck, packages, links, go test -race), and vole workflow run release against a throwaway local tag passes too, producing both architectures. readelf shows libsqlite3.so.0 and libc.so.6 in NEEDED for both, and dpkg -I / rpm -qpR show the new dependencies in both formats.

If keeping one self-contained file matters more than the last 1.2 MB, dropping -tags libsqlite3 compiles the driver’s bundled SQLite into the binary and removes the runtime dependency; the packages would then not need libsqlite3. Say the word and I will switch it.

Closes #91.

Discussion (0)

No discussion yet.