Skip to content

Link zstd statically into the NIF - #21

Open
vans163 wants to merge 1 commit into
EnkiMultimedia:masterfrom
vans163:static-zstd-linking
Open

vans163 wants to merge 1 commit into
EnkiMultimedia:masterfrom
vans163:static-zstd-linking

Conversation

@vans163

@vans163 vans163 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

The NIF currently links libzstd dynamically even when zstd is bundled: the wrapper picks the shared lib, and build-rocksdb.cmake passes -DWITH_ZSTD to the inner rocksdb without the resolved library path, so rocksdb runs its own find and grabs libzstd.so. This leaves a libzstd.so.1 runtime dependency on the final binary.

This branch:

  • FindZstd.cmake — prefer the static libzstd.a (fall back to shared if no .a), so zstd is embedded in the NIF.
  • build-rocksdb.cmake — propagate the resolved ZSTD_LIBRARIES/ZSTD_INCLUDE_DIRS to the inner rocksdb ExternalProject (snappy and lz4 were already propagated; zstd was missed).
  • build-rocksdb.cmake — add the bundled-zstd build-step dependency so a parallel clean build can't configure rocksdb before libzstd.a is installed (snappy/lz4 had this ordering; zstd did not, causing intermittent clean-build failures).

Verified: with -DWITH_ZSTD=ON -DWITH_BUNDLE_ZSTD=ON, ldd liberocksdb.so shows no libzstd/libz/libcrypto — fully static — and rocksdb+zstd works at runtime.

- FindZstd: prefer the static libzstd.a over the shared lib so zstd is embedded
  in the NIF (portable binary, no libzstd.so runtime dependency)
- build-rocksdb: propagate the resolved zstd lib+include to the inner rocksdb
  ExternalProject. Without this rocksdb runs its own find_package(zstd) and grabs
  the shared .so, silently undoing the wrapper's static choice (snappy/lz4 were
  already propagated; zstd was missed)
- build-rocksdb: add the bundled-zstd build-step dependency so a parallel clean
  build can't configure rocksdb before libzstd.a is installed (snappy/lz4 had
  this ordering; zstd did not, causing intermittent clean-build failures)
@benoitc

benoitc commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Hi, PR looks usefuful but tests don't pass for now. Can you look at it?

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