Skip to content

Conversation

@Bill-hbrhbr
Copy link
Collaborator

@Bill-hbrhbr Bill-hbrhbr commented Mar 24, 2025

Description

This PR refactors and improves the cpp_library() CMake function:

  • Added require_argument_values() helper to enforce argument check in a fail-fast way.
  • Add a new option TESTS_LINK_LIBRARIES for 3rdparty libraries that are not used in implementation but are used for testing purposes for a target library.
  • Improve all doc strings with variable type specifications.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • No functionality changes.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced library configuration with improved argument validation to ensure all required inputs are provided, reducing build misconfigurations.
    • Updated the linking process to improve handling of public, private, and test dependencies for a more robust building experience.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2025

Walkthrough

This change introduces a new CMake function, require_argument_values, to validate the presence of required arguments for a library target. The cpp_library function is modified to expand its lists of multi-value and required arguments, incorporating TESTS_LINK_LIBRARIES, BUILD_INCLUDE_DIR, and TESTS_SOURCES. Additionally, it centralizes argument validation and enhances library linking mechanisms, including updates to the linking of test libraries.

Changes

Files Change Summary
CMake/ystdlib-cpp-helpers.cmake - Introduced the require_argument_values function for validating required argument values.
- Updated cpp_library to include TESTS_LINK_LIBRARIES and BUILD_INCLUDE_DIR in multiValueArgs and TESTS_SOURCES in requireValueArgs.
- Replaced conditional checks for BUILD_INCLUDE_DIR with a call to the new function.
- Enhanced library linking logic for both interface and non-interface libraries, including linking of arg_cpp_lib_TESTS_LINK_LIBRARIES for unit tests.

Sequence Diagram(s)

sequenceDiagram
    participant User as CMake Config
    participant CLib as cpp_library
    participant Validator as require_argument_values

    User->>CLib: Call cpp_library(args)
    CLib->>Validator: Validate required arguments
    alt Missing argument values
        Validator-->>CLib: Return fatal error
        CLib-->>User: Configuration error reported
    else All required values present
        CLib->>CLib: Process updated linking logic (interface, non-interface, test linking)
        CLib-->>User: Configuration continues successfully
    end
Loading

Possibly related PRs

Suggested reviewers

  • kirkrodrigues
  • davidlion

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c5bda7 and 5724932.

📒 Files selected for processing (1)
  • CMake/ystdlib-cpp-helpers.cmake (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-24.04)
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (9)
CMake/ystdlib-cpp-helpers.cmake (9)

1-10: New helper function enhances argument validation

The new require_argument_values function provides a clean way to validate required arguments with proper error messages, which improves the fail-fast behavior. This is particularly useful for enforcing consistent usage across different targets.


12-14: Documentation improvement for clarity

The updated parameter documentation provides clear type information, which makes it easier for users to understand the expected inputs and outputs of the function.


34-44: Enhanced documentation with parameter types

The addition of type information for all parameters significantly improves the documentation. This helps users understand what values are expected for each parameter and makes the function more self-documenting.


57-59: Expanded multi-value arguments list

Adding TESTS_LINK_LIBRARIES and BUILD_INCLUDE_DIR to the multi-value arguments list allows these parameters to accept multiple values, which is consistent with their expected usage in CMake.


60-65: Centralized required arguments definition

Creating a dedicated requireValueArgs list makes it clear which arguments must have values. This improves code maintainability and ensures consistent argument validation.


71-75: Centralized argument validation

Using the new require_argument_values function to validate required arguments centralizes the validation logic and ensures consistent error messages across all argument checks.


77-79: Improved variable check pattern

Using if(NOT DEFINED arg_cpp_lib_BUILD_INCLUDE_DIR) is a more standard CMake pattern for checking if a variable is defined. This is more idiomatic than the previous approach.


142-142: Added support for test-specific dependencies

Including ${arg_cpp_lib_TESTS_LINK_LIBRARIES} when linking the unit test target allows for test-specific libraries to be linked without polluting the main library's dependencies.


155-160: Consistent linking for unified test target

The updated target_link_libraries call for the unified test target ensures consistency with the individual test target linking. This guarantees that both test targets have access to the same dependencies.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Bill-hbrhbr Bill-hbrhbr changed the title Improve refactor(Cmake): Improve cpp_library(); Adding argument missing value validation; Fix linking with header-only libraries; Add TESTS_LINK_LIBRARIES for test-only tools; Improve doc strings with types. Mar 24, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title refactor(Cmake): Improve cpp_library(); Adding argument missing value validation; Fix linking with header-only libraries; Add TESTS_LINK_LIBRARIES for test-only tools; Improve doc strings with types. refactor(Cmake): Improve cpp_library(); Adding argument missing value validation; Fix linking for header-only libraries; Add TESTS_LINK_LIBRARIES for test-only tools; Improve doc strings with types. Mar 24, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title refactor(Cmake): Improve cpp_library(); Adding argument missing value validation; Fix linking for header-only libraries; Add TESTS_LINK_LIBRARIES for test-only tools; Improve doc strings with types. feat(Cmake): Improve cpp_library(); Adding argument missing value validation; Fix linking for header-only libraries; Add TESTS_LINK_LIBRARIES for test-only tools; Improve doc strings with types. Mar 24, 2025
@Bill-hbrhbr Bill-hbrhbr marked this pull request as ready for review March 24, 2025 18:30
@Bill-hbrhbr Bill-hbrhbr requested a review from a team as a code owner March 24, 2025 18:30
@Bill-hbrhbr Bill-hbrhbr changed the title feat(Cmake): Improve cpp_library(); Adding argument missing value validation; Fix linking for header-only libraries; Add TESTS_LINK_LIBRARIES for test-only tools; Improve doc strings with types. feat(cmake): Enhance cpp_library() with argument validation, test-only linking, and improved docstrings. Mar 25, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
CMake/ystdlib-cpp-helpers.cmake (2)

37-37: Fix documentation typo

There's a typo in the parameter documentation.

-# @parms {string[]} TESTS_SOURCES
+# @param {string[]} TESTS_SOURCES

41-41: Fix documentation typo

There's a typo in the parameter documentation.

-# @parms {string[]} [TESTS_LINK_LIBRARIES]
+# @param {string[]} [TESTS_LINK_LIBRARIES]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6dd560d and 8dd5a14.

📒 Files selected for processing (1)
  • CMake/ystdlib-cpp-helpers.cmake (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (macos-15)
  • GitHub Check: lint-check (ubuntu-24.04)
🔇 Additional comments (7)
CMake/ystdlib-cpp-helpers.cmake (7)

1-10: Well-implemented validation function

The new require_argument_values function provides a clean, centralized way to validate required arguments, improving the fail-fast behavior when arguments are missing. The documentation clearly indicates parameter types and purpose.


57-59: Good addition of test-only linking support

Adding TESTS_LINK_LIBRARIES to multiValueArgs satisfies the PR objective of allowing third-party libraries that are necessary for testing but not required in the implementation of the target library. Also, moving BUILD_INCLUDE_DIR to multiValueArgs is appropriate as it can accept multiple include paths.


60-65: Improved argument validation

Adding TESTS_SOURCES to requireValueArgs ensures proper validation when using the test functionality. This change aligns with the PR objective of enhancing argument validation.


71-75: Centralized argument validation

Replacing conditional checks with a call to require_argument_values centralizes the validation logic and makes the code more maintainable. This change aligns with the PR objective of enforcing argument validation in a fail-fast manner.


77-79: Simple BUILD_INCLUDE_DIR default handling

This check correctly handles the default value for BUILD_INCLUDE_DIR when not defined by the user. The replacement of the previous validation with the new centralized validation function maintains the same behavior while improving code organization.


135-135: Test-only linking properly implemented

Adding the TESTS_LINK_LIBRARIES to the unit test target's dependencies allows for test-only dependencies, satisfying a key PR objective.


148-153: Consistent linking for unified test target

The implementation correctly applies the same test library linking to the unified test target, ensuring consistent behavior between individual and unified tests. This is a good improvement that maintains the symmetry between the two test targets.

Copy link
Member

@davidlion davidlion left a comment

Choose a reason for hiding this comment

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

The suggestions should fit the character limit, but double check just in case.

Co-authored-by: davidlion <davidlion2@protonmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
CMake/ystdlib-cpp-helpers.cmake (1)

37-37: Correct the typo in parameter documentation.

There's a typo in the parameter documentation - @parms should be @param.

-# @parms {string[]} TESTS_SOURCES
+# @param {string[]} TESTS_SOURCES
-# @parms {string[]} [TESTS_LINK_LIBRARIES]
+# @param {string[]} [TESTS_LINK_LIBRARIES]

Also applies to: 41-41

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8dd5a14 and 6c5bda7.

📒 Files selected for processing (1)
  • CMake/ystdlib-cpp-helpers.cmake (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-24.04)
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (7)
CMake/ystdlib-cpp-helpers.cmake (7)

1-10: Excellent addition of a helper function for centralized argument validation.

This new require_argument_values function implements a fail-fast validation pattern for required arguments, which improves error reporting and makes the code more maintainable. The implementation is clear and the error messages are informative.


57-59: Good addition of TESTS_LINK_LIBRARIES to multiValueArgs.

The addition of TESTS_LINK_LIBRARIES to the multiValueArgs list allows for test-specific library dependencies, which is a useful feature for projects that need different libraries for testing compared to their main implementation.


60-65: Well-structured required argument validation.

The explicit definition of requireValueArgs makes it clear which arguments must have values, improving code maintainability and documentation.


71-75: Great implementation of centralized argument validation.

The call to require_argument_values centralizes argument validation logic, making the code more maintainable and consistent in error handling.


77-79: Improved conditional logic for BUILD_INCLUDE_DIR.

This code handles the default value assignment for BUILD_INCLUDE_DIR after validation, which is a cleaner approach than the previous implementation.


135-135: Great addition for test-specific dependencies.

Adding ${arg_cpp_lib_TESTS_LINK_LIBRARIES} to the unit test target's linked libraries fulfills the PR goal of allowing test-only library dependencies.


148-153: Consistent linking approach for unified unit test target.

The updated structure for linking libraries to the unified unit test target matches the pattern used for individual test targets, providing consistency and clarity.

@Bill-hbrhbr Bill-hbrhbr requested a review from davidlion March 25, 2025 20:50
@Bill-hbrhbr Bill-hbrhbr merged commit 2ac1757 into y-scope:main Mar 25, 2025
7 checks passed
@Bill-hbrhbr Bill-hbrhbr deleted the improve-cpp-library branch April 9, 2025 07:34
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