fix(cmake): prefer generated proto headers over in-source leftovers - #3506
Open
darion-yaphet wants to merge 1 commit into
Open
fix(cmake): prefer generated proto headers over in-source leftovers#3506darion-yaphet wants to merge 1 commit into
darion-yaphet wants to merge 1 commit into
Conversation
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>
Contributor
There was a problem hiding this comment.
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_DIRSto put${CMAKE_CURRENT_BINARY_DIR}before${PROJECT_SOURCE_DIR}/src. - Prepends the build directory to
brpc_common_configinclude dirs usingtarget_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 on lines
70
to
73
| set(BRPC_COMMON_INCLUDE_DIRS | ||
| ${PROJECT_SOURCE_DIR}/src | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| ${PROJECT_SOURCE_DIR}/src | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Problem Summary:
CMake puts
${PROJECT_SOURCE_DIR}/srcahead of${CMAKE_CURRENT_BINARY_DIR}on the include path. Make generates protobuf headers in-tree (src/**/*.pb.h, gitignored). After a.protoupdate, 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.protoandbuild/brpc/errno.pb.hboth hadEPROGREADTIMEOUT = 1019; the stalesrc/brpc/errno.pb.hstill stopped atEREJECT = 1018.What is changed and the side effects?
Changed:
${CMAKE_CURRENT_BINARY_DIR}beforesrc/inBRPC_COMMON_INCLUDE_DIRS.BEFOREonbrpc_common_configso leftover Make-generated*.pb.hcannot shadow updated generated headers.Side effects:
*.pb.hfrom 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: