Skip to content

feat: add columnar-dbc Rust crates linking dbc statically - #548

Merged
zeroshade merged 10 commits into
feat/capifrom
feat/rust-crates
Nov 4, 2026
Merged

zeroshade merged 10 commits into
feat/capifrom
feat/rust-crates

Conversation

@zeroshade

@zeroshade zeroshade commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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 crated, 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.

@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

@amoeba amoeba left a comment

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.

Generally I think this looks fine. I looked closer at some files than others and I expect I may have more review comments once this is all merged together.

Comment thread rust/columnar-dbc/README.md Resolved
Comment thread rust/columnar-dbc/README.md Resolved
Comment thread rust/columnar-dbc/README.md Resolved
Comment thread rust/columnar-dbc/README.md Resolved
Comment thread rust/columnar-dbc/README.md Resolved
Comment thread rust/columnar-dbc/README.md Resolved
Comment thread rust/columnar-dbc/src/types.rs Resolved
Comment thread rust/columnar-dbc/src/types.rs Resolved
Comment thread rust/columnar-dbc/README.md Resolved
zeroshade added a commit that referenced this pull request Nov 4, 2026
…and docs_url

Address review on #548:
- Client::install(name) installs where `dbc install` would without -l
  (InstallLocation::Default); install_at(name, &location) for an explicit
  level or directory.
- Driver gains docs_url and registry.
- Option keys come from libdbc.h's DBC_OPTION_* macros.
- README is the crate docs, so its example is compiled as a doctest;
  wording per review.
zeroshade added a commit that referenced this pull request Nov 4, 2026
…and docs_url

Address review on #548:
- Client::install(name) installs where `dbc install` would without -l
  (InstallLocation::Default); install_at(name, &location) for an explicit
  level or directory.
- Driver gains docs_url and registry.
- Option keys come from libdbc.h's DBC_OPTION_* macros.
- README is the crate docs, so its example is compiled as a doctest;
  wording per review.
zeroshade added a commit that referenced this pull request Nov 4, 2026
On Unix, Go reads a copy of the environment taken when its runtime starts,
and only its own os.Setenv updates it. A C, Rust, or Python host changes the
environment through libc, so changes it made after libdbc loaded were
ignored: e.g. Python setting os.environ["ADBC_DRIVER_PATH"] after import still
installed to the user level (#548 review).

config now reads the three variables through internal/hostenv, which
defaults to os.LookupEnv; capi replaces it on Unix with libc getenv, so cgo
stays in the C API build. Pure Go programs were already effectively live, and
Windows reads the live process environment. The Rust default_location test
now sets ADBC_DRIVER_PATH after startup instead of re-running itself, and
fails against the previous libdbc.
zeroshade added a commit that referenced this pull request Nov 4, 2026
On Unix, Go reads a copy of the environment taken when its runtime starts,
and only its own os.Setenv updates it. A C, Rust, or Python host changes the
environment through libc, so changes it made after libdbc loaded were
ignored: e.g. Python setting os.environ["ADBC_DRIVER_PATH"] after import still
installed to the user level (#548 review).

config now reads the three variables through internal/hostenv, which
defaults to os.LookupEnv; capi replaces it on Unix with libc getenv, so cgo
stays in the C API build. Pure Go programs were already effectively live, and
Windows reads the live process environment. The Rust default_location test
now sets ADBC_DRIVER_PATH after startup instead of re-running itself, and
fails against the previous libdbc.
zeroshade added a commit that referenced this pull request Nov 4, 2026
On Unix, Go reads a copy of the environment taken when its runtime starts,
and only its own os.Setenv updates it. A C, Rust, or Python host changes the
environment through libc, so changes it made after libdbc loaded were
ignored: e.g. Python setting os.environ["ADBC_DRIVER_PATH"] after import still
installed to the user level (#548 review).

config now reads the three variables through internal/hostenv, which
defaults to os.LookupEnv; capi replaces it on Unix with libc getenv, so cgo
stays in the C API build. Pure Go programs were already effectively live, and
Windows reads the live process environment. The Rust default_location test
now sets ADBC_DRIVER_PATH after startup instead of re-running itself, and
fails against the previous libdbc.
zeroshade and others added 10 commits November 4, 2026 15:01
…http

tiny_http 0.12 unwraps peer_addr() on accept; on Windows it fails with WSAENOTCONN when the client has already closed the connection, killing the worker and failing the next request with EOF.
…LIB_DIR

Keep bundled platform crates as the default, with custom-directory and pkg-config overrides selecting static or opt-in dynamic linking. Move the MSVC Go initializer into the sys crate and reject non-x86_64 static MSVC links.

pkg-config 0.3.34 parse_libs defaults the non-macOS/non-Windows system root to /usr, and is_static_available requires an archive path outside every system root. Thus statik(true) alone emits an unqualified link for /usr/lib/<triplet>/libdbc.a, allowing the shared library to win. Probe without Cargo link metadata and explicitly emit static=dbc, leaving private system libraries dynamic.
The default build now locates an installed libdbc through the dbc
pkg-config module. The prebuilt platform crates move behind the
`bundled` feature, and the `pkg-config` feature is removed since it is
now the default. DBC_SYS_LIB_DIR and DBC_SYS_USE_PKG_CONFIG keep their
precedence over `bundled`.
…and docs_url

Address review on #548:
- Client::install(name) installs where `dbc install` would without -l
  (InstallLocation::Default); install_at(name, &location) for an explicit
  level or directory.
- Driver gains docs_url and registry.
- Option keys come from libdbc.h's DBC_OPTION_* macros.
- README is the crate docs, so its example is compiled as a doctest;
  wording per review.
columnar-dbc-sys accepted any installed dbc pkg-config module, so a crate
built against an older or newer libdbc compiled and then failed at run time
(unknown client options) or used shifted target ids. Require libdbc in
[crate version, next minor) before 1.0 (next major after); the 0.0.0-dev
repository placeholder stays unchecked. Document the requirement, and that
DBC_SYS_LIB_DIR libraries can't be checked.
Co-authored-by: Felipe Oliveira Carvalho <[email protected]>
Co-authored-by: Felipe Oliveira Carvalho <[email protected]>
Per review on #548:
- Generate the DBC_OPTION_* string macros as &CStr (bindgen
  --generate-cstr, c"..." literals), so with_config passes them to C
  without the runtime CStr::from_bytes_with_nul check.
- Drop the crate's Result alias; signatures spell out
  std::result::Result<T, Error>.
zeroshade added a commit that referenced this pull request Nov 4, 2026
On Unix, Go reads a copy of the environment taken when its runtime starts,
and only its own os.Setenv updates it. A C, Rust, or Python host changes the
environment through libc, so changes it made after libdbc loaded were
ignored: e.g. Python setting os.environ["ADBC_DRIVER_PATH"] after import still
installed to the user level (#548 review).

config now reads the three variables through internal/hostenv, which
defaults to os.LookupEnv; capi replaces it on Unix with libc getenv, so cgo
stays in the C API build. Pure Go programs were already effectively live, and
Windows reads the live process environment. The Rust default_location test
now sets ADBC_DRIVER_PATH after startup instead of re-running itself, and
fails against the previous libdbc.
@zeroshade
zeroshade merged commit 0a62d3a into main Nov 4, 2026
10 checks passed
@zeroshade
zeroshade deleted the feat/rust-crates branch November 4, 2026 20:11
zeroshade added a commit that referenced this pull request Nov 4, 2026
- `.goreleaser.yaml` gains a `capi` c-archive build that cross-compiles
all 5 targets with Zig 0.17.0 (glibc 2.28 / macOS 12 floors).
- `scripts/stage_capi.py` checks size and stages each archive;
`scripts/publish_crates.py` runs `cargo package` (snapshot) or `cargo
publish` (on `v*` tag pushes, from the `production_deploy` GoReleaser
run). Publishing skips crate versions already on crates.io, so
re-running a partially published release finishes the rest. `ids: [dbc]`
filters keep the archives out of the CLI packaging.
- New `rust_test` job runs on the snapshot's archives on six native
runners (Linux x64/arm64, macOS arm64/x64, Windows MSVC and GNU), with a
30-minute timeout.
- Needs a `CARGO_REGISTRY_TOKEN` secret in the `production` environment
(see RELEASE.md).

Stacked on #548. Supersedes #543.

### libdbc-dev / libdbc-devel
- A new `capi-shared` build (linux amd64/arm64, SONAME `libdbc.so`).
- Two nfpm entries: deb `libdbc-dev` (`/usr/lib/<triplet>`) and rpm
`libdbc-devel` (`/usr/lib64`). Each ships `libdbc.a`, `libdbc.so`,
`/usr/include/libdbc.h` and `pkgconfig/dbc.pc`.
- `scripts/stage_devel.py` stages the `.so` and `.pc` files.
- nfpm takes only the c-archive build's artifacts, because both builds
emit `libdbc.h` and GoReleaser doesn't deduplicate.
- The packages ship in `release`, `blobs`, and Cloudsmith
(`columnar/dbc`, alongside the CLI packages; stable releases only).

New CI job `devel packages` (amd64 + arm64):
- installs the snapshot `.deb`;
- runs the Rust tests with the default build (pkg-config, statically
linked, checked with `ldd`), with `DBC_DYNAMIC`, and with
`DBC_SYS_LIB_DIR` (`scripts/test_devel_rust.sh`);
- installs the `.rpm` in a Fedora container, runs the same Rust tests
against it, and compiles and runs a C smoke program, statically and
dynamically.



### Docs
- `docs/getting_started/installation.md` gains a "Linux Package
Repositories (deb/rpm)" section: adding the Cloudsmith `columnar/dbc`
apt/dnf repo (setup script or manual config), installing `dbc` /
`libdbc-dev` / `libdbc-devel`, or installing a file from GitHub
Releases. Linked from the README.
- The `columnar-dbc` / `columnar-dbc-sys` rustdoc and crate README
explain installing the dev package from the repo or from GitHub
Releases, with links to the repo, releases, and install docs.


### macOS / Windows static libdbc-dev
- New `libdbc-dev` archive from the `capi` build:
`libdbc-dev_<v>_darwin_{amd64,arm64}.tar.gz` and
`libdbc-dev_<v>_windows_amd64.zip` with `libdbc.a` (`libdbc.lib` on
Windows), `libdbc.h`, `LICENSE`, and a relocatable `dbc.pc`
(`prefix=${pcfiledir}`). Attached to the release and the bucket.
- `libdbc` Homebrew formula via GoReleaser `brews` →
`columnar-tech/homebrew-tap` (`brew install columnar-tech/tap/libdbc`).
`brews` is deprecated in favor of casks, but casks can't install into
`lib/`/`include/`, so a formula is the only option for a library.
- Windows zip → Cloudsmith raw package `libdbc-dev-windows-x64` via a
`cloudsmith-raw` custom publisher (`scripts/publish_cloudsmith_raw.py`);
the `cloudsmiths` pipe only handles deb/rpm/apk. Stable releases only.
- `DBC_SYS_LIB_DIR` accepts `libdbc.lib` on Windows. winget is now
restricted to the CLI archives (it otherwise skips with "multiple
archives for the same platform").
- New CI job `devel archive`: on macOS arm64/x64 installs the snapshot
formula from a local tap, runs `brew test`, and runs the Rust suite with
the default pkg-config build; on Windows MSVC/GNU runs the Rust suite
against the unpacked zip with `DBC_SYS_LIB_DIR`.
zeroshade added a commit that referenced this pull request Nov 4, 2026
On Unix, Go reads a copy of the environment taken when its runtime starts,
and only its own os.Setenv updates it. A C, Rust, or Python host changes the
environment through libc, so changes it made after libdbc loaded were
ignored: e.g. Python setting os.environ["ADBC_DRIVER_PATH"] after import still
installed to the user level (#548 review).

config now reads the three variables through internal/hostenv, which
defaults to os.LookupEnv; capi replaces it on Unix with libc getenv, so cgo
stays in the C API build. Pure Go programs were already effectively live, and
Windows reads the live process environment. The Rust default_location test
now sets ADBC_DRIVER_PATH after startup instead of re-running itself, and
fails against the previous libdbc.

This branch was previously deployed

1 inactive deployment
snapshot — f3a2557f Deployed Nov 4, 2026 by zeroshade via snapshot #1225
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.

3 participants