Skip to content

[ML] Do not treat third-party warnings as errors - #3208

Merged
valeriy42 merged 1 commit into
elastic:mainfrom
edsavage:fix/thirdparty-warning-as-error
Sep 23, 2026
Merged

valeriy42 merged 1 commit into
elastic:mainfrom
edsavage:fix/thirdparty-warning-as-error

Conversation

@edsavage

@edsavage edsavage commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The debug Linux CI build (which enables -DCMAKE_COMPILE_WARNING_AS_ERROR=ON, #3198) fails once third-party dependencies are actually compiled from the 3rd_party subtree. ml-cpp applies its strict warning flags (-Wconversion, -Wunused-parameter, ...) to every target via add_compile_options(${ML_CXX_FLAGS}), and these leak into third-party code. This surfaces in two distinct places:

  1. Compiling the third-party sources themselves — their own value-changing conversions are promoted to errors, e.g.:
    ... error: conversion from 'int64_t' to 'double' may change value [-Werror=conversion]
    cc1plus: all warnings being treated as errors
    
  2. Compiling our own targets that include Sandbox2/Abseil/protobuf headers (MlSandbox and its unit tests ml_test_sandbox). Those headers are not warning-clean (conversion, unused-parameter, ...) and, under -Werror, fail the build of our own targets.

Fix

Two complementary changes, neither of which weakens linting of ml-cpp's own code:

  1. 3rd_party/CMakeLists.txt: disable warnings-as-errors for the third-party subtree only (CMAKE_COMPILE_WARNING_AS_ERROR OFF), matching the block's existing save/restore of BUILD_TESTING, BUILD_SHARED_LIBS, and CMAKE_UNITY_BUILD. Third-party warnings stay visible but non-fatal.
  2. lib/sandbox/CMakeLists.txt + lib/sandbox/unittest/CMakeLists.txt: set COMPILE_WARNING_AS_ERROR OFF on just the two ml-cpp targets that include third-party sandbox headers. This is order-safe and covers every warning class those headers may trip (rather than chasing individual -Wno-error=<class> flags). All other ml-cpp targets keep -Werror.

Why not SYSTEM includes?

Marking the third-party include directories SYSTEM (so consumers get -isystem) was tried and rejected: it demotes the vendored protobuf/Abseil source includes from -I to -isystem, which places them after PyTorch's bundled protobuf in the search path. Protobuf then compiles against a mix of its own generated headers and PyTorch's older protobuf, producing version-mismatch errors (FeatureSetDefaults not declared, PROTOBUF_NODISCARD does not name a type, ...). Keeping the includes as -I avoids this collision entirely.

Test plan

  • CI: the debug Linux build compiles the third-party sources, MlSandbox, and ml_test_sandbox without failing on their warnings.
  • Verify ml-cpp's own targets still treat warnings as errors in the debug build (unchanged behaviour).
  • Introduce a (temporary) change that emits a warning in 3rd party code. The build should still succeed. (Verified on an earlier run: a probe target and the real Abseil/Sandbox2 sources emitted -Wconversion warnings and the build proceeded past them.)

Note: the modified blocks are Linux-only, so this is validated by CI rather than my local macOS build.

@elasticsearchmachine

Copy link
Copy Markdown

Pinging @elastic/ml-core (Team:ML)

@edsavage
edsavage force-pushed the fix/thirdparty-warning-as-error branch from 734f2c5 to 7a48d5e Compare September 22, 2026 23:20
@edsavage edsavage changed the title [ML] Do not treat third-party Abseil/Sandbox2 warnings as errors [ML] Do not treat third-party warnings as errors Sep 22, 2026
@edsavage
edsavage force-pushed the fix/thirdparty-warning-as-error branch 3 times, most recently from 7a48d5e to 3671ecd Compare September 23, 2026 00:58
ml-cpp applies its strict warning flags (including -Wconversion,
-Wunused-parameter, ...) to every target via
add_compile_options(${ML_CXX_FLAGS}), and the debug Linux CI build enables
CMAKE_COMPILE_WARNING_AS_ERROR=ON (elastic#3198). Once third-party dependencies are
actually compiled from the 3rd_party subtree this breaks the build in two
places:

  1. Compiling the third-party sources themselves, whose own warnings are
     promoted to errors. Fixed by disabling warnings-as-errors for the
     third-party subtree only (matching the existing save/restore pattern),
     so their warnings stay visible but non-fatal.

  2. Compiling our own targets that include Sandbox2/Abseil/protobuf headers
     (MlSandbox and its unit tests). Those headers are pulled in as normal
     (-I) includes - deliberately not -isystem, so they stay ahead of
     PyTorch's bundled protobuf in the search path - and are not warning-clean
     (conversion, unused-parameter, ...). Fixed by turning off
     warnings-as-errors on just those consuming targets, which is order-safe
     and covers every warning class the third-party headers may trip.

ml-cpp's own code keeps warnings-as-errors everywhere else.

Co-authored-by: Cursor <cursoragent@cursor.com>
@edsavage
edsavage force-pushed the fix/thirdparty-warning-as-error branch from 3671ecd to c1b2d86 Compare September 23, 2026 01:21
@edsavage
edsavage requested review from valeriy42 and a lite review from Copilot September 23, 2026 02:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Two moderate findings remain regarding target-wide suppression of warning enforcement.

Review effort: Lite
Findings: None

What changed in this PR

This PR prevents third-party warnings from failing Linux debug builds while preserving strict warning handling elsewhere.

Changes:

  • Disable warnings-as-errors for third-party dependencies.
  • Disable it for MlSandbox and ml_test_sandbox.
File Summary
lib/​sandbox/​unittest/​CMakeLists.txt Disables warning failures for the sandbox test target; this also affects ml-cpp test sources. Moderate finding (1 vote).
lib/​sandbox/​CMakeLists.txt Disables warning failures for MlSandbox; this also affects ml-cpp production sources. Moderate finding (1 vote).
3rd_party/​CMakeLists.txt Disables and restores warnings-as-errors for third-party targets.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

4 participants