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

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary:

CMake puts ${PROJECT_SOURCE_DIR}/src ahead of ${CMAKE_CURRENT_BINARY_DIR} on the include path. 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:

  • Search ${CMAKE_CURRENT_BINARY_DIR} before src/ in BRPC_COMMON_INCLUDE_DIRS.
  • Mark the build directory as BEFORE on brpc_common_config so leftover Make-generated *.pb.h cannot shadow updated generated headers.
    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:

Make-generated src/**/*.pb.h can shadow newer build-dir headers and
break compiles after proto updates such as EPROGREADTIMEOUT.

Co-authored-by: Cursor <cursoragent@cursor.com>

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
)
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