Skip to content

Conversation

@liuzicheng1987
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @liuzicheng1987, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and maintainability of the reflectcpp library by introducing a mechanism to enforce header self-containment. A new CMake option allows developers to enable a build-time check that verifies each header file can be compiled in isolation. This is crucial for preventing subtle build errors, improving compilation times, and making the codebase easier to understand and refactor. The changes also include necessary adjustments to individual header files to ensure they meet this new standard, along with general code cleanup and formatting improvements.

Highlights

  • New CMake Option for Header Self-Containment: A new CMake option, REFLECTCPP_CHECK_HEADERS, has been introduced. When enabled, this option triggers a build process to verify that all header files are self-contained, meaning they can be included independently without requiring other headers to be included beforehand.
  • Automated Header Self-Containment Testing: The build system now includes a custom step that automatically generates a small C++ file for each public header. Each generated file simply includes its corresponding header, and these files are then compiled. This ensures that every header explicitly includes all its necessary dependencies, preventing hidden dependencies and improving modularity.
  • Dependency Management Updates: The CMake configuration has been updated to integrate the REFLECTCPP_CHECK_HEADERS option into existing dependency logic. This ensures that when header checking is enabled, all required third-party libraries (e.g., via VCPKG) are correctly pulled in and linked for the header test builds.
  • Header File Refinements: Numerous header files across various modules (e.g., rfl/avro, rfl/bson, rfl/capnproto, rfl/flexbuf, rfl/msgpack, rfl/parsing, rfl/internal, rfl/thirdparty/enchantum, rfl/yaml) have been modified to explicitly include previously implicit dependencies. This directly addresses the self-containment goal by making each header fully functional on its own.
Ignored Files
  • Ignored by pattern: .github/workflows/** (2)
    • .github/workflows/linux.yaml
    • .github/workflows/macos.yaml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to make headers self-contained by adding missing includes. The changes across the header files look correct. However, the CMake logic to verify self-contained headers is flawed. I've provided a suggestion to fix it. The main issue is that the test targets for each header are not configured with the necessary include paths and dependencies, which my suggestion addresses by linking them against the main reflectcpp library.

Comment on lines 419 to 443
if(REFLECTCPP_CHECK_HEADERS)
file(GLOB_RECURSE PROJECT_HEADERS "include/*.hpp")

set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/self_contained_tests")
file(MAKE_DIRECTORY "${TEST_DIR}")

foreach(HEADER_FILE ${PROJECT_HEADERS})
string(MAKE_C_IDENTIFIER ${HEADER_FILE} HEADER_NAME)
set(TEST_SOURCE_FILE "${TEST_DIR}/test_${HEADER_NAME}.cpp")

file(GENERATE
OUTPUT ${TEST_SOURCE_FILE}
CONTENT "#include \"${HEADER_FILE}\"\n"
)

add_library(check_header_${HEADER_NAME} "${TEST_SOURCE_FILE}")

target_include_directories(check_header_${HEADER_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${ADDITIONAL_INCLUDE_DIRS}
)

add_custom_target(check_${HEADER_NAME} ALL DEPENDS check_header_${HEADER_NAME})
endforeach()
endif()

Choose a reason for hiding this comment

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

high

The current implementation for checking if headers are self-contained is not correctly configured. The check_header_* targets are missing the necessary include directories and link dependencies from third-party libraries (like avro, bson, etc.). This will cause the compilation of the test sources to fail.

A better approach is to create executables for each header check and link them against the reflectcpp target. This ensures they inherit all the necessary public/interface dependencies and include paths. Using an executable also verifies that linking succeeds, which is a more thorough check than just compiling a static library.

I've also added a main function to the generated source file to make it a valid executable source.

if(REFLECTCPP_CHECK_HEADERS)
    file(GLOB_RECURSE PROJECT_HEADERS "include/*.hpp")

    set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/self_contained_tests")
    file(MAKE_DIRECTORY "${TEST_DIR}")

    foreach(HEADER_FILE ${PROJECT_HEADERS})
        string(MAKE_C_IDENTIFIER ${HEADER_FILE} HEADER_NAME)
        set(TEST_SOURCE_FILE "${TEST_DIR}/test_${HEADER_NAME}.cpp")

        file(GENERATE
            OUTPUT ${TEST_SOURCE_FILE}
            CONTENT "#include \"${HEADER_FILE}\"\nint main() { return 0; }\n"
        )

        add_executable(check_header_${HEADER_NAME} "${TEST_SOURCE_FILE}")
        target_link_libraries(check_header_${HEADER_NAME} PRIVATE reflectcpp)
        
        add_custom_target(check_${HEADER_NAME} ALL DEPENDS check_header_${HEADER_NAME})
    endforeach()
endif()

@liuzicheng1987 liuzicheng1987 merged commit d0f60b2 into main Oct 25, 2025
292 checks passed
@liuzicheng1987 liuzicheng1987 deleted the f/make_sure_headers_are_self_contained branch October 25, 2025 11:03
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