Vendored DuckDB prebuilt#
This directory holds the prebuilt DuckDB C library and header the bindings
compile and link against. We do not vendor DuckDB source (see spec.md);
instead we download an official prebuilt archive, exactly like the Python and Go
bindings do, so end users need not install DuckDB separately.
What's committed vs provisioned#
Committed (tracked in git):
| File | Role |
|---|---|
duckdb.version |
The single source of truth for the pinned DuckDB version. |
duckdb.checksums |
Pinned SHA-256 of each platform archive (bump alongside version). |
README.md |
This file. |
Provisioned on demand by ../scripts/fetch-duckdb.sh (gitignored, never
committed — see /vendor/duckdb/ in .gitignore):
File under duckdb/ |
Role |
|---|---|
duckdb.h |
C API header (compiled against). |
duckdb.hpp |
C++ header (shipped by upstream; unused by these bindings). |
libduckdb.so / .dylib |
Shared library (linked; resolved at runtime via rpath). |
libduckdb_static.a |
Static archive (Linux only; upstream ships none on macOS). |
libduckdb.a |
Stable-name symlink to libduckdb_static.a when present. |
cflags.sexp |
-I include flag, spliced into lib/duckdb_c/dune. |
link-flags.sexp |
-L/-l/-rpath flags, spliced into lib/duckdb_c/dune. |
Provisioning#
./scripts/fetch-duckdb.sh
The script reads the pinned version from vendor/duckdb.version, picks the
platform-correct archive, downloads it, verifies it against
vendor/duckdb.checksums, unpacks it here, and emits the dune flag fragments.
It refuses unsupported platforms (notably Windows) with a clear error.
Bumping the DuckDB version (e.g. to 2.x)#
This is a one-line change plus checksums:
- Edit
vendor/duckdb.versionto the new version (e.g.2.0.0). - Update the two checksums in
vendor/duckdb.checksumsto match the new archives (download them once and runsha256sum). - Run
./scripts/fetch-duckdb.shanddune build.
No OCaml or dune file changes are required — the version flows into the build
through the generated Duckdb_c.target_api_version, and the test asserts the
linked library actually reports the pinned version.
opam strategy#
Decision: ship the prebuilt via the package, gated to Linux + macOS. Like
the Python (duckdb wheel) and Go bindings, an end user installing this opam
package should not need a system DuckDB. The package provisions the prebuilt
itself:
-
Platform gate. The package is available only on Linux and macOS. In the published opam file this is the field:
available: [ os = "linux" | os = "macos" ]Windows is explicitly out of scope for now. As a defence in depth,
scripts/fetch-duckdb.shalso fails fast with a clear message on any unsupported platform/architecture. -
Provisioning, without network in the build. The opam build sandbox has no network, so the prebuilt archives are declared as
extra-sources induckdb.opam(pinned by URL and SHA-256); opam downloads and verifies them before the build.scripts/fetch-duckdb.shthen runs in thebuild:step, uses the opam-provided archive (instead of downloading), unpacks it intovendor/duckdb/, and emits the dune compile/link-flag fragments. -
Shared library, installed into the switch. DuckDB is C++ and its official prebuilt static archive is not self-contained (it references extension symbols defined only in the shared object), so static linking is not viable. The package therefore links the shared
libduckdb.so/.dyliband the opaminstall:step (scripts/install-duckdb-lib.sh) copies it into%{lib}%/duckdb. The link step embeds an rpath to that install location (plus the vendor dir, so the package's own build-time tests resolve it), so a consumer's binary finds the library at runtime with no system DuckDB. -
Single version pin.
vendor/duckdb.versionis the only place the version lives; bump it withvendor/duckdb.checksumsand the matchingextra-sourceURLs/checksums induckdb.opam.
duckdb.opamis hand-maintained (not generated by dune): it needs fields dune cannot emit —available:, theextra-sourcearchives, and the custom build/install.generate_opam_filesis therefore off indune-project.
Publishing to a private opam repository#
The repository here builds and installs locally (dune build, and opam install . once the prebuilt is provisioned). To publish a versioned release into a
private opam-repository:
- Tag a release (e.g.
v0.1.0) and produce a source tarball of the OCaml project (this repo's source — not the prebuilt; that comes viaextra-source). - Add
packages/duckdb/duckdb.0.1.0/opamto the private repo: a copy ofduckdb.opamplus aurl { src: "<tarball-url>" checksum: "sha256=…" }pointing at that source tarball. - If the repo is served over HTTP, run
opam admin index. - Consumers:
opam repo add <name> <repo-url>thenopam install duckdb.