Skip to content

build: keep the prebuilt cache out of the crate source tree; opt-in localization of bundled C symbols - #33

Merged
adsharma merged 1 commit into
LadybugDB:mainfrom
querygraph:prebuilt-cache-and-symbol-localization
Sep 7, 2026
Merged

build: keep the prebuilt cache out of the crate source tree; opt-in localization of bundled C symbols#33
adsharma merged 1 commit into
LadybugDB:mainfrom
querygraph:prebuilt-cache-and-symbol-localization

Conversation

@alexy

@alexy alexy commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Two build-script changes found while driving lbug 0.20.2 from a Rust graph adapter on x86_64 Linux. Both keep the default build byte-for-byte the same for anyone who does not opt in.

Prebuilt cache location

build.rs downloaded the prebuilt archive into .cache/lbug-prebuilt inside CARGO_MANIFEST_DIR. For a registry dependency that is ~/.cargo/registry/src/…/lbug-0.20.2/, which Cargo treats as immutable: it broke cargo vendor, read-only registries and offline builds. The archive now lives under OUT_DIR, or under LBUG_PREBUILT_CACHE_DIR for a persistent cache shared between builds. An archive already present in the legacy location is still used, so existing checkouts do not re-download.

Opt-in localization of bundled C symbols

liblbug.a bundles zstd, lz4, brotli, simsimd, yyjson and CRoaring with their ordinary global names (192 ZSTD_*, 194 roaring/bitset symbols including bare helpers such as get and union). A binary that also links zstd-sys, lz4-sys, simsimd or croaring-sys (here through Lance and Arrow) fails with rust-lld on Linux: duplicate symbol: ZSTD_compressBound and nineteen more before the linker stops; ld64 on macOS silently takes the first definition, which is why it only shows up on Linux. With LBUG_LOCALIZE_BUNDLED_SYMBOLS=1 (Linux, static library only) the build script partially links the archive into one relocatable object, keeps every lbug_* C API symbol, C++-mangled symbol and weak symbol global, makes the rest local, and archives it back under OUT_DIR. Without the variable nothing changes.

Verified on Debian 13 x86_64 against the prebuilt archive: the localized library links into a binary that also links zstd-sys and simsimd without --allow-multiple-definition, and the crate's tests pass either way. The crate docs list both variables.

Context

Measurements and notes from the strain harness that motivated this, written for the maintainer: https://github.com/querygraph/adversarial-graph/blob/main/LADYBUG-NOTES.md (load path, point-lookup cost, buffer-pool sizing, and this packaging section).

🤖 Generated with Claude Code

https://claude.ai/code/session_013H2j2wjVBdmiK6v5sWM4u1

…ocalization of bundled C symbols

- The downloaded prebuilt archive now lives under OUT_DIR (or
  LBUG_PREBUILT_CACHE_DIR for a persistent, shared cache) instead of
  .cache/lbug-prebuilt inside CARGO_MANIFEST_DIR. For a registry
  dependency that directory is ~/.cargo/registry/src/…, which Cargo treats
  as immutable; writing there broke `cargo vendor`, read-only registries and
  offline builds. An archive already present in the legacy location is
  still used.
- LBUG_LOCALIZE_BUNDLED_SYMBOLS=1 (Linux, static) partially links liblbug.a
  into one relocatable object, makes every strong unmangled symbol outside
  the lbug_* C API local, and archives it back. liblbug.a exports zstd, lz4,
  brotli, simsimd, yyjson and CRoaring with their ordinary names (192 ZSTD_*,
  194 roaring/bitset/… including bare helpers such as `get` and `union`);
  a binary that also links zstd-sys, lz4-sys, simsimd or croaring-sys fails
  with rust-lld on Linux (duplicate symbol), while ld64 on macOS silently
  keeps whichever copy comes first. Opt-in because an extension that
  resolves one of those symbols from the host binary would stop finding it.
  Weak (COMDAT) symbols stay global so the linker can still deduplicate them.
  Verified: 0 ZSTD_/roaring_/simsimd_/LZ4 globals remain, 179 lbug_* and the
  mangled lbug:: API do, and the examples crate links and runs.
- Crate docs: the two new variables, a bulk-loading section (COPY FROM and
  the Arrow table registration; one MERGE per row measured at tens of
  milliseconds each), and a note on the buffer pool's host-sized default.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013H2j2wjVBdmiK6v5sWM4u1
@adsharma

adsharma commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

The CI here tests only Linux. Will test windows/mac before merging.

@adsharma
adsharma merged commit 47bfd12 into LadybugDB:main Sep 7, 2026
1 check passed
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