Skip to content

feat: add typed C API static library for language bindings - #547

Merged
zeroshade merged 4 commits into
refactor/wasm-internal-apifrom
feat/capi
Nov 4, 2026
Merged

zeroshade merged 4 commits into
refactor/wasm-internal-apifrom
feat/capi

Conversation

@zeroshade

Copy link
Copy Markdown
Member

capi/ builds as a Go c-archive exposing 13 functions: an opaque dbc_client configured with ADBC-style key/value options, and a single dbc_list result type read with dbc_list_get/dbc_list_info (DBC_FIELD_* ids). libdbc.h is generated by cgo from capi/exports.go; there is no hand-written header.

Stacked on #546.

@zeroshade
zeroshade added this pull request to stack #550 October 28, 2026 22:46
@zeroshade
zeroshade marked this pull request as ready for review November 3, 2026 19:27
Comment thread capi/exports.go Resolved
Comment thread capi/exports.go Resolved
Comment thread capi/exports.go Resolved
Comment thread capi/convert.go Resolved
zeroshade added a commit that referenced this pull request Nov 4, 2026
…url fields

Address review on #547:
- DBC_TARGET_DEFAULT resolves like `dbc install` without -l (env level from
  ADBC_DRIVER_PATH/VIRTUAL_ENV/CONDA_PREFIX, else user), via new
  config.Default shared with the CLI. Target kinds renumbered to match
  config.ConfigLevel: DEFAULT=0, SYSTEM=1, USER=2, DIRECTORY=3.
- dbc_client_new option keys are DBC_OPTION_* macros in libdbc.h.
- Search rows gain DBC_FIELD_REGISTRY and DBC_FIELD_DOCS_URL.
- Document that strings are NUL-terminated.
I removed the sentence in `capi/main.go` that said releases build the C library through a `capi` GoReleaser build, since no such build exists. Release artifacts still won't include `libdbc.a`.
I didn't add the GoReleaser build. The existing release config builds everything with `CGO_ENABLED=0`, and a `-buildmode=c-archive` build needs cgo plus a C cross-compiler for every OS/architecture pair, which CI doesn't have yet. That needs its own change if you want the library in releases. The package comment still gives the manual `go build` command.
The build passes and `go test ./...` passes.
Changes:
- Removed the comment in `capi/main.go` saying a `capi` build in `.goreleaser.yaml` produces the C archive, since that packaging isn't set up yet
…url fields

Address review on #547:
- DBC_TARGET_DEFAULT resolves like `dbc install` without -l (env level from
  ADBC_DRIVER_PATH/VIRTUAL_ENV/CONDA_PREFIX, else user), via new
  config.Default shared with the CLI. Target kinds renumbered to match
  config.ConfigLevel: DEFAULT=0, SYSTEM=1, USER=2, DIRECTORY=3.
- dbc_client_new option keys are DBC_OPTION_* macros in libdbc.h.
- Search rows gain DBC_FIELD_REGISTRY and DBC_FIELD_DOCS_URL.
- Document that strings are NUL-terminated.
Comment thread internal/api/ops.go
Comment on lines -47 to +48
return config.Config{}, errors.New("either level or location is required")
return checked(config.Default(), "default")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we re-check this? I'm having Opus review all the PRs and all of my reviews and it caught a thing.

This change is good but the Node package's behavior now changes. I think previously Node had a "you must specify where to install" behavior which basically meant Node was opting out of the CLI's behavior.

I think we need to,

  1. Keep this but update the Node bindings to error when level == "".
  2. Opus seems to have caught a but where, in Node, install("pg") installs to ./undefined because of how normalizeLocation works.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, both were real. Fixed in 57ca77c:

  1. Default location reaching Node. api.Target{} now means the CLI's default, and the npm ops passed an empty location straight through, so Node silently picked it up. The Node ops (wasm/ops_node_js.go) now reject any location that isn't a non-empty string with location is required: the npm API installs to an explicit directory. That restores the old contract. The default stays for the C API and Go callers.
  2. ./undefined. Confirmed: normalizeLocation did String(loc), so install("pg") installed into a directory named undefined in the cwd. It now passes non-strings through for the Go side to reject. Go's js.Value.String() would otherwise have turned undefined into "<undefined>".

smoke.cjs now runs install, uninstall and listInstalled with undefined, null and "" from an empty cwd, and checks that each rejects with a dbc-wasm: error and nothing is written. Before the fix it failed on the first case (install(undefined) succeeded). It passes in Node and Deno, and I checked the worker backend rejects the same nine cases. The stack above is restacked.

An empty api.Target now means the CLI's default location, so the npm
package's operations, which take a directory only, picked it up when called
without one. Worse, normalizeLocation turned a missing location into the
string "undefined", so install("pg") installed into ./undefined.

normalizeLocation passes non-strings through, and the Node ops reject any
location that is not a non-empty string. The smoke test checks that each
operation rejects undefined, null and "" without writing to the working
directory.
@zeroshade
zeroshade merged commit d6f6292 into main Nov 4, 2026
15 checks passed
@zeroshade
zeroshade deleted the feat/capi branch November 4, 2026 20:11
zeroshade added a commit that referenced this pull request Nov 4, 2026
`rust/`: `columnar-dbc` (safe API), `columnar-dbc-sys` (bindgen 0.73.2
bindings generated from `libdbc.h`, committed) and five
`columnar-dbc-sys-<platform>` crates, each bundling a prebuilt
`libdbc.a`. Supported targets: x86_64/aarch64 Linux (glibc),
x86_64/aarch64 macOS, `x86_64-pc-windows-msvc` and
`x86_64-pc-windows-gnu`. Other targets fail at build time.

**MSVC:** a Go c-archive registers its runtime entry in `.ctors`, which
only the MinGW CRT runs. Under MSVC the first dbc call blocked forever.
The Windows platform crate registers `_rt0_amd64_windows_lib` in
`.CRT$XCU` for `target_env = "msvc"`. A local `cargo xwin` link map
shows the pointer in the CRT's `XCA..XCZ` initializer table. CI in the
top PR of the stack runs the tests.

Stacked on #547.

### Linking libdbc
Modeled on `zstd-sys`, with pkg-config as the default. The source is
chosen in this order:
1. `DBC_SYS_LIB_DIR=<dir>`: a custom directory.
2. `DBC_SYS_USE_PKG_CONFIG` set: pkg-config module `dbc`, even with
`bundled` on.
3. The opt-in `bundled` feature: the per-platform prebuilt crates.
4. Otherwise (default): pkg-config module `dbc`.

By default the platform crates aren't downloaded at all; `features =
["bundled"]` opts into them. Env overrides win even when `bundled` is
on: the platform crate is never `extern crate`d, so its archive isn't
linked. docs.rs builds with `bundled` since it has no installed libdbc.

Linking is static by default; `DBC_DYNAMIC` (pkg-config-rs's own
convention) links `libdbc.so`. pkg-config-rs refuses static links for
archives under `/usr`, so `build.rs` emits the link directives itself
rather than using `.statik(true)`.

The MSVC Go runtime initializer moved from the Windows platform crate
into `-sys`. It's applied to any static x86_64 MSVC link, and static
MSVC links on other architectures fail with a clear error.

---------

Co-authored-by: Felipe Oliveira Carvalho <[email protected]>

This branch was previously deployed

1 inactive deployment
snapshot — 57ca77c5 Deployed Nov 4, 2026 by zeroshade via snapshot #1220
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants