Skip to content

fix(cmake): prefer generated proto headers over in-source leftovers - #3506

Open
darion-yaphet wants to merge 1 commit into
apache:masterfrom
darion-yaphet:fix/generated-proto-include-order
Open

fix(cmake): prefer generated proto headers over in-source leftovers#3506
darion-yaphet wants to merge 1 commit into
apache:masterfrom
darion-yaphet:fix/generated-proto-include-order

Conversation

@darion-yaphet

@darion-yaphet darion-yaphet commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Problem Summary:

CMake searched ${PROJECT_SOURCE_DIR}/src before the build directory. Make generates protobuf headers in-tree (src/**/*.pb.h, gitignored). After a .proto update, CMake already writes the new header into the build directory, but the compiler still picks the leftover in-source file.

This showed up after #3469 (EPROGREADTIMEOUT):

src/brpc/controller.cpp:76:28: error: no member named 'EPROGREADTIMEOUT' in namespace 'brpc'

src/brpc/errno.proto and build/brpc/errno.pb.h both had EPROGREADTIMEOUT = 1019; the stale src/brpc/errno.pb.h still stopped at EREJECT = 1018.

What is changed and the side effects?

Changed:

  • Add ${CMAKE_CURRENT_BINARY_DIR} as a BEFORE include on brpc_common_config, so generated protobuf headers are searched before src/ and leftover Make-generated *.pb.h cannot shadow them.

Side effects:

  • Performance effects: none. Compile-time include order only; no runtime change.

  • Breaking backward compatibility: no. Generated headers remain the source of truth. In-source *.pb.h from Make is still valid when it is up to date; it just no longer wins over a newer build-dir copy. Existing Make and Bazel flows are unchanged.


Check List:

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.

Pull request overview

This PR fixes a CMake include-path precedence issue in bRPC’s build system so that build-directory generated protobuf headers are preferred over stale, Make-generated (gitignored) src/**/*.pb.h leftovers. This prevents compilation against outdated proto headers after .proto changes.

Changes:

  • Reorders BRPC_COMMON_INCLUDE_DIRS to put ${CMAKE_CURRENT_BINARY_DIR} before ${PROJECT_SOURCE_DIR}/src.
  • Prepends the build directory to brpc_common_config include dirs using target_include_directories(... BEFORE ...) to ensure build-generated headers win in include resolution.

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

Comment thread CMakeLists.txt
Comment on lines 70 to 73
set(BRPC_COMMON_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/src
)
Make-generated src/**/*.pb.h can shadow newer build-dir headers and
break compiles after proto updates such as EPROGREADTIMEOUT.
@darion-yaphet
darion-yaphet force-pushed the fix/generated-proto-include-order branch from 6ccd87d to d72f1cc Compare August 31, 2026 06:02
@chenBright
chenBright requested a lite review from Copilot August 31, 2026 12:28

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

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