Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ cdn-dev
.claude

__pycache__

# Rust crates (rust/); native/ holds libdbc.a/libdbc.h (local go build or GoReleaser's stage_capi.py)
rust/target/
rust/platforms/*/native/
67 changes: 67 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,73 @@ and you can run the tests by running,
go test -v ./...
```

### C API and Rust crates

`./capi` is dbc's C API. cgo generates its header, `libdbc.h`, from the
preamble and `//export` functions in `capi/exports.go`, so that file is the
only place the API is declared. The Rust crates in `rust/` link a bundled
static build by default, or a system/custom library as described below.
Building libdbc needs a C compiler (cgo) as well as Go; using the Rust crates
also needs Rust. For bundled linking, build the archive for your platform
(`linux-x64`, `linux-arm64`, `darwin-x64`, `darwin-arm64`, or `windows-x64`)
into its platform crate, then run the tests:

```sh
CGO_ENABLED=1 go build -tags netgo,osusergo -buildmode=c-archive -o rust/platforms/linux-x64/native/libdbc.a ./capi
cargo test --manifest-path rust/Cargo.toml -p columnar-dbc
```

#### Linking a system libdbc

To test against a custom static build without staging a platform crate:

```sh
mkdir -p /tmp/dbc-local/lib
CGO_ENABLED=1 go build -tags netgo,osusergo -buildmode=c-archive -o /tmp/dbc-local/lib/libdbc.a ./capi
DBC_SYS_LIB_DIR=/tmp/dbc-local/lib cargo test --manifest-path rust/Cargo.toml -p columnar-dbc --no-default-features
```

Alternatively, install `libdbc-dev` (Debian/Ubuntu) or `libdbc-devel` (RPM),
along with the `pkg-config` executable. For example, use
`sudo apt install ./libdbc-dev_*.deb` for a downloaded Debian package.
These packages provide the static and shared libraries, header, and `dbc.pc`.
Then run:

```sh
cargo test --manifest-path rust/Cargo.toml -p columnar-dbc --no-default-features --features pkg-config
```

Set `PKG_CONFIG_PATH` to the directory containing `dbc.pc` if it is not in
the system search path. Disabling default features avoids downloading or
building the bundled platform crates. Source precedence is `DBC_SYS_LIB_DIR`,
then the `pkg-config` feature or presence of `DBC_SYS_USE_PKG_CONFIG`, then
the default `bundled` feature; environment overrides also work with default
features still enabled. With no source selected, the build fails.

System/custom linking defaults to static. Set `DBC_DYNAMIC` (any value,
including empty) for dynamic linking; bundled linking remains static.
To test a custom shared build on Linux:

```sh
CGO_ENABLED=1 go build -tags netgo,osusergo -buildmode=c-shared -ldflags '-extldflags "-Wl,-soname,libdbc.so"' -o /tmp/dbc-local/lib/libdbc.so ./capi
DBC_SYS_LIB_DIR=/tmp/dbc-local/lib DBC_DYNAMIC=1 LD_LIBRARY_PATH=/tmp/dbc-local/lib cargo test --manifest-path rust/Cargo.toml -p columnar-dbc --no-default-features
```

Dynamic linking requires `libdbc.so` on the runtime loader's search path;
the crate does not configure it. See the
[Rust crate README](rust/columnar-dbc/README.md#linking-a-system-libdbc)
for dependency configuration.

#### Regenerating Rust bindings

After changing anything in `capi/exports.go`, regenerate the Rust bindings
with bindgen-cli 0.73.2 (CI fails if they are stale):

```sh
cargo install bindgen-cli --version 0.73.2 --locked
python3 scripts/gen_rust_bindings.py rust/platforms/linux-x64/native/libdbc.h
```

## Debugging

Debugging dbc can be done similarly to any Golang project and editor setups like VSCode with the official Go extension should work out of the box.
Expand Down
153 changes: 153 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2026 Columnar Technologies Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[workspace]
resolver = "2"
members = ["columnar-dbc", "columnar-dbc-sys", "platforms/*"]

[workspace.package]
# Placeholder: scripts/publish_crates.py stamps the release version here and
# in the pins below while packaging/publishing. Every crate ships with the
# dbc release version.
version = "0.0.0-dev"
edition = "2021"
rust-version = "1.82"
license = "Apache-2.0"
repository = "https://github.com/columnar-tech/dbc"
homepage = "https://columnar.tech/dbc"

[workspace.dependencies]
columnar-dbc-sys = { path = "columnar-dbc-sys", version = "=0.0.0-dev", default-features = false }
columnar-dbc-sys-linux-x64 = { path = "platforms/linux-x64", version = "=0.0.0-dev" }
columnar-dbc-sys-linux-arm64 = { path = "platforms/linux-arm64", version = "=0.0.0-dev" }
columnar-dbc-sys-darwin-x64 = { path = "platforms/darwin-x64", version = "=0.0.0-dev" }
columnar-dbc-sys-darwin-arm64 = { path = "platforms/darwin-arm64", version = "=0.0.0-dev" }
columnar-dbc-sys-windows-x64 = { path = "platforms/windows-x64", version = "=0.0.0-dev" }
55 changes: 55 additions & 0 deletions rust/columnar-dbc-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2026 Columnar Technologies Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[package]
name = "columnar-dbc-sys"
description = "Raw FFI bindings to dbc's C ABI with bundled or system linking. Use columnar-dbc instead."
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
# Two copies of the Go runtime in one binary would collide at link time;
# `links` makes Cargo reject that during resolution instead.
links = "columnar_dbc"
build = "build.rs"

[features]
default = ["bundled"]
bundled = [
"dep:columnar-dbc-sys-linux-x64",
"dep:columnar-dbc-sys-linux-arm64",
"dep:columnar-dbc-sys-darwin-x64",
"dep:columnar-dbc-sys-darwin-arm64",
"dep:columnar-dbc-sys-windows-x64",
]
pkg-config = []

[build-dependencies]
pkg-config = "0.3"

[target.'cfg(all(target_os = "linux", target_arch = "x86_64", target_env = "gnu"))'.dependencies]
columnar-dbc-sys-linux-x64 = { workspace = true, optional = true }

[target.'cfg(all(target_os = "linux", target_arch = "aarch64", target_env = "gnu"))'.dependencies]
columnar-dbc-sys-linux-arm64 = { workspace = true, optional = true }

[target.'cfg(all(target_os = "macos", target_arch = "x86_64"))'.dependencies]
columnar-dbc-sys-darwin-x64 = { workspace = true, optional = true }

[target.'cfg(all(target_os = "macos", target_arch = "aarch64"))'.dependencies]
columnar-dbc-sys-darwin-arm64 = { workspace = true, optional = true }

[target.'cfg(all(target_os = "windows", target_arch = "x86_64"))'.dependencies]
columnar-dbc-sys-windows-x64 = { workspace = true, optional = true }
Loading
Loading