Skip to content

Add OPENZL_USE_SYSTEM_ZSTD option to use system-installed zstd#288

Open
otegami wants to merge 1 commit into
facebook:devfrom
otegami:use-system-zstd
Open

Add OPENZL_USE_SYSTEM_ZSTD option to use system-installed zstd#288
otegami wants to merge 1 commit into
facebook:devfrom
otegami:use-system-zstd

Conversation

@otegami

@otegami otegami commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Summary

Fixes #105

Add a new CMake option OPENZL_USE_SYSTEM_ZSTD that
allows using system-installed zstd library via
find_package(zstd CONFIG) instead of the bundled
version. This is useful for Linux distributions that
package zstd separately.

When enabled:

  • Uses find_package(zstd CONFIG REQUIRED) to find system zstd
  • Creates a libzstd alias target for compatibility with existing code
  • Exported config includes find_dependency(zstd) for downstream projects

When disabled (default):

  • Behavior unchanged (uses git submodule or FetchContent)

Type of Change

New feature (non-breaking change which adds functionality)

Test Plan

Build with system zstd

cmake \
	-S .\
	-B ../openzl.build \
	-DOPENZL_USE_SYSTEM_ZSTD=ON \
	-DOPENZL_BUILD_TESTS=ON \
	-DCMAKE_INSTALL_PREFIX=/tmp/local &&\
cmake --build ../openzl.build -j4 &&\
ctest --test-dir ../openzl.build --output-on-failure

Verify installation does not include zstd files

cmake --install ../openzl.build
ls /tmp/local/lib/ | grep libzstd # should be empty

Build with bundled zstd (default)

cmake \
	-S . \
	-B ../openzl.build \
	-DOPENZL_BUILD_TESTS=ON \
	-DCMAKE_INSTALL_PREFIX=/tmp/local &&\
cmake --build openzl.build -j4 &&\
ctest --test-dir ../openzl.build --output-on-failure

Verify installation includes zstd files

cmake --install ../openzl.build
ls /tmp/local/lib/ | grep libzstd
libzstd.a
libzstd.so
libzstd.so.1
libzstd.so.1.5.7

Test Configuration

  • Compiler: GCC 13.3.0
  • Build type: default
  • Platform: Linux (Ubuntu)
@meta-cla meta-cla Bot added the cla signed label Dec 9, 2025
@otegami otegami marked this pull request as draft December 9, 2025 08:21
## Summary

GitHub: GH-facebook#105

Add a new CMake option `OPENZL_USE_SYSTEM_ZSTD` that
allows using system-installed zstd library via
`find_package(zstd CONFIG)` instead of the bundled
version. This is useful for Linux distributions that
package zstd separately.

When enabled:
- Uses `find_package(zstd CONFIG REQUIRED)` to find
  system zstd
- Creates a `libzstd` alias target for compatibility
  with existing code
- Exported config includes `find_dependency(zstd)` for
  downstream projects

When disabled (default):
- Behavior unchanged (uses git submodule or FetchContent)

## Type of Change

New feature (non-breaking change which adds functionality)

## Test Plan

### Build with system zstd

```console
cmake \
  -S .\
  -B ../openzl.build \
  -DOPENZL_USE_SYSTEM_ZSTD=ON \
  -DOPENZL_BUILD_TESTS=ON \
  -DCMAKE_INSTALL_PREFIX=/tmp/local &&\
cmake --build ../openzl.build -j4 &&\
ctest --test-dir ../openzl.build --output-on-failure
```

### Verify installation does not include zstd files

```console
cmake --install ../openzl.build
ls /tmp/local/lib/ | grep libzstd # should be empty
```

### Build with bundled zstd (default)

```console
cmake \
  -S . \
  -B ../openzl.build \
  -DOPENZL_BUILD_TESTS=ON \
  -DCMAKE_INSTALL_PREFIX=/tmp/local &&\
cmake --build openzl.build -j4 &&\
ctest --test-dir ../openzl.build --output-on-failure
```

### Verify installation includes zstd files

```console
cmake --install ../openzl.build
ls /tmp/local/lib/ | grep libzstd
libzstd.a
libzstd.so
libzstd.so.1
libzstd.so.1.5.7
```

### Test Configuration
- Compiler: GCC 13.3.0
- Build type: default
- Platform: Linux (Ubuntu)
@otegami otegami marked this pull request as ready for review December 9, 2025 08:32
@neiljohari

Copy link
Copy Markdown
Contributor

Hi @terrelln, would you consider accepting this patch or something similar?

I'm building Rust bindings for OpenZL (vendored + custom FFI). My project also
depends on zstd-rs, which statically links its own zstd. Currently both libraries
compile zstd independently, resulting in duplicate symbols and ~10MB binary bloat.

With OPENZL_USE_SYSTEM_ZSTD, I could point OpenZL's CMake at the zstd that zstd-rs
already built, avoiding the duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants