Repository navigation
feat: add typed C API static library for language bindings - #547
Conversation
…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.
| return config.Config{}, errors.New("either level or location is required") | ||
| return checked(config.Default(), "default") |
There was a problem hiding this comment.
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,
- Keep this but update the Node bindings to error when
level == "". - Opus seems to have caught a but where, in Node,
install("pg")installs to./undefinedbecause of hownormalizeLocationworks.
There was a problem hiding this comment.
Good catch, both were real. Fixed in 57ca77c:
- 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 withlocation 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. ./undefined. Confirmed:normalizeLocationdidString(loc), soinstall("pg")installed into a directory namedundefinedin the cwd. It now passes non-strings through for the Go side to reject. Go'sjs.Value.String()would otherwise have turnedundefinedinto"<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.
`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]>
capi/builds as a Goc-archiveexposing 13 functions: an opaquedbc_clientconfigured with ADBC-style key/value options, and a singledbc_listresult type read withdbc_list_get/dbc_list_info(DBC_FIELD_*ids).libdbc.his generated by cgo fromcapi/exports.go; there is no hand-written header.Stacked on #546.