Skip to content

lib: zstd: only require a C compiler#10316

Open
ThomasDevoogdt wants to merge 2 commits intofluent:masterfrom
ThomasDevoogdt:bugfix/lib-zstd-only-require-a-c-compiler
Open

lib: zstd: only require a C compiler#10316
ThomasDevoogdt wants to merge 2 commits intofluent:masterfrom
ThomasDevoogdt:bugfix/lib-zstd-only-require-a-c-compiler

Conversation

@ThomasDevoogdt
Copy link
Copy Markdown
Contributor

@ThomasDevoogdt ThomasDevoogdt commented May 8, 2025

Upstream: facebook/zstd@769723a

Summary by CodeRabbit

  • Chores

    • Removed a system zstd package from CI installs to streamline environment setup; retained other native dependencies.
    • Kept CI build flags aligned for external Kafka support.
  • Refactor

    • C++ compilation is now enabled only when needed (e.g., tests), making builds leaner.
    • Compilation and linker flags made conditional per language for clearer, more portable builds.
  • Tests

    • Adjusted build pathways to better isolate test-related components.

No changes to user-facing functionality.

cosmo0920
cosmo0920 previously approved these changes May 9, 2025
@cosmo0920 cosmo0920 added this to the Fluent Bit v4.0.2 milestone May 9, 2025
@edsiper
Copy link
Copy Markdown
Member

edsiper commented May 9, 2025

(cc: @cosmo0920) the changes should not touch the bundled dependencies because when we upgrade those changes will be lost. I recommend trying to merge the changes in libzstd repo first

@ThomasDevoogdt
Copy link
Copy Markdown
Contributor Author

@edsiper The changes are already upstream. See the git commit message.

@ThomasDevoogdt
Copy link
Copy Markdown
Contributor Author

@edsiper @cosmo0920 this has been approved (and upstreamed) for quite some time, can this be merged?

@ThomasDevoogdt ThomasDevoogdt force-pushed the bugfix/lib-zstd-only-require-a-c-compiler branch from 1a33abe to 2cc0058 Compare July 14, 2025 20:59
@ThomasDevoogdt
Copy link
Copy Markdown
Contributor Author

@cosmo0920 @edsiper It's again a bit silent around this PR. Everything is approved and ready to be merged, on what do we exactly wait? Can you just merge this one?

@ThomasDevoogdt
Copy link
Copy Markdown
Contributor Author

@cosmo0920 Can you merge this one? Or add milestone that might land anytime soon. I have the feeling that next means forgotten.

@cosmo0920
Copy link
Copy Markdown
Contributor

cosmo0920 commented Aug 8, 2025

We don't want to merge this PR without merging for upstream libzstd library itself.

@cosmo0920
Copy link
Copy Markdown
Contributor

This commit facebook/zstd@769723a is not released as a stable version officially, so we need to wait for merging this.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 4, 2025

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 53c5d0ee-5832-4d3d-9c40-72fc9e0bbdc8

📥 Commits

Reviewing files that changed from the base of the PR and between 163b99c and b0d89f1.

📒 Files selected for processing (1)
  • .github/workflows/pr-compile-check.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/pr-compile-check.yaml

📝 Walkthrough

Walkthrough

Remove system libzstd from CI and make zstd's C++ usage conditional: CMake no longer declares CXX by default, instead sets ZSTD_ENABLE_CXX from ZSTD_BUILD_TESTS, conditionally enables CXX, and refactors compilation flags to be parameter-driven per C/CXX/LD.

Changes

Cohort / File(s) Summary
CI workflow
.github/workflows/pr-compile-check.yaml
Stop installing libzstd-dev and remove the -DFLB_PREFER_SYSTEM_LIB_ZSTD=ON preference; other deps (e.g., librdkafka-dev) unchanged.
Zstd top-level CMake
lib/zstd-1.5.7/build/cmake/CMakeLists.txt
Drop CXX from project(... LANGUAGES ...); add set(ZSTD_ENABLE_CXX ${ZSTD_BUILD_TESTS}); conditionally enable_language(CXX); include and invoke ADD_ZSTD_COMPILATION_FLAGS with CXX controlled by ZSTD_ENABLE_CXX.
Zstd compilation flags module
lib/zstd-1.5.7/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
Change ADD_ZSTD_COMPILATION_FLAGS signature to accept _C _CXX _LD; route all EnableCompilerFlag/flag logic through these parameters enabling per-language/linker flag control.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Dev as Developer
    participant CI as CI Workflow
    participant CMake as CMake (configure)
    participant Zstd as zstd CMakeLists
    participant Flags as AddZstdCompilationFlags

    Dev->>CI: Push PR
    CI->>CI: Setup build env (omit system libzstd)
    CI->>CMake: Run configure (no -DFLB_PREFER_SYSTEM_LIB_ZSTD)

    CMake->>Zstd: Load CMakeLists
    Zstd->>Zstd: set(ZSTD_ENABLE_CXX ${ZSTD_BUILD_TESTS})
    alt ZSTD_ENABLE_CXX = ON
        Zstd->>CMake: enable_language(CXX)
    else ZSTD_ENABLE_CXX = OFF
        Zstd->>CMake: skip CXX enablement
    end
    Zstd->>Flags: ADD_ZSTD_COMPILATION_FLAGS(ON, ZSTD_ENABLE_CXX, ON)
    Flags-->>CMake: Apply per-language (C/CXX) and linker flags
    CMake-->>CI: Generate build system
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • edsiper
  • leonardo-albertovich
  • fujimotos
  • patrick-stephens
  • niedbalski
  • cosmo0920

Poem

A rabbit nudges CMake with a twitchy nose,
"C first, C++ only if testing shows."
Flags hop lanes—C, CXX, and LD,
CI sheds zstd, light as a reed.
Hoppity build, the burrow glows. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the changeset—making the zstd library compilation require only a C compiler by removing CXX language requirement and making it conditional based on build tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/zstd-1.5.7/build/cmake/CMakeLists.txt (1)

119-130: LGTM with maintenance concern: bundled dependency modification before upstream stable release.

The conditional C++ enablement logic is technically correct:

  • C++ is enabled only when tests are built (ZSTD_ENABLE_CXX is tied to ZSTD_BUILD_TESTS)
  • The macro call ADD_ZSTD_COMPILATION_FLAGS(ON ZSTD_ENABLE_CXX ON) correctly passes C (always on), C++ (conditional), and linker (always on) flag enablement parameters

However, per the PR discussion, modifying bundled dependencies (lib/zstd-1.5.7/) before the upstream changes are released in a stable zstd version creates maintenance risk. When fluent-bit updates to the next stable zstd release, these local modifications will be overwritten, requiring re-application or coordination with upstream timing.

Recommendation: Consider one of the following approaches to reduce maintenance burden:

  1. Wait for the upstream zstd stable release that includes commit 769723aee2540aaff8951ac432a1babed358aa71 before merging this PR
  2. If immediate merge is required, document this local modification in the fluent-bit repository (e.g., in a ZSTD_PATCHES.md file) to ensure the changes are re-applied during the next zstd bundle update
  3. Track the upstream zstd release schedule and coordinate the bundle update timing with this PR merge

Based on learnings from the PR discussion.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d9593e and 163b99c.

📒 Files selected for processing (3)
  • .github/workflows/pr-compile-check.yaml (2 hunks)
  • lib/zstd-1.5.7/build/cmake/CMakeLists.txt (1 hunks)
  • lib/zstd-1.5.7/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-31T12:46:11.940Z
Learnt from: ThomasDevoogdt
PR: fluent/fluent-bit#9277
File: .github/workflows/pr-compile-check.yaml:147-151
Timestamp: 2025-08-31T12:46:11.940Z
Learning: In fluent-bit CMakeLists.txt, the system library preference flags are defined as FLB_PREFER_SYSTEM_LIB_ZSTD and FLB_PREFER_SYSTEM_LIB_KAFKA with the FLB_ prefix.

Applied to files:

  • .github/workflows/pr-compile-check.yaml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
🔇 Additional comments (5)
.github/workflows/pr-compile-check.yaml (2)

138-138: LGTM! Consistent with the goal of testing bundled zstd.

Removing libzstd-dev installation from the pr-compile-without-cxx job is correct since this job now tests the bundled zstd library (which no longer requires C++) rather than the system-provided one.


152-152: LGTM! Correctly uses bundled zstd.

Removing the -DFLB_PREFER_SYSTEM_LIB_ZSTD=ON flag ensures the job uses the bundled zstd library, which aligns with testing the C-only compilation capability.

lib/zstd-1.5.7/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake (2)

52-52: LGTM! Macro signature correctly extended for conditional flag control.

The updated signature ADD_ZSTD_COMPILATION_FLAGS(_C _CXX _LD) enables fine-grained control over which compiler flags to enable, supporting the conditional C++ enablement pattern introduced in the related CMakeLists.txt changes.


66-111: LGTM! All EnableCompilerFlag calls consistently updated.

All calls to EnableCompilerFlag have been correctly updated to pass the new _C, _CXX, and _LD parameters, enabling conditional flag application based on language availability.

lib/zstd-1.5.7/build/cmake/CMakeLists.txt (1)

36-40: LGTM! Correctly removes C++ from default languages.

Removing CXX from the initial LANGUAGES list is appropriate for making zstd buildable with C-only toolchains. C++ is now enabled conditionally based on ZSTD_BUILD_TESTS (see lines 119-124).

@ThomasDevoogdt
Copy link
Copy Markdown
Contributor Author

@cosmo0920 @edsiper I understand that this is not yet part of an upstream release, but the commit at least has been merged upstream, AND there are tests which are checking the functionality. So is there any reason to keep waiting for it and to not take this along?

Upstream: facebook/zstd@769723a
Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
This reverts commit e816c48.

Not needed anymore since libzstd has been bumped.

Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
@ThomasDevoogdt ThomasDevoogdt force-pushed the bugfix/lib-zstd-only-require-a-c-compiler branch from 163b99c to b0d89f1 Compare March 7, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants