Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Split core into spearate library #15

Merged
merged 4 commits into from
Oct 31, 2024

Conversation

sitaowang1998
Copy link
Collaborator

@sitaowang1998 sitaowang1998 commented Oct 31, 2024

Description

Split core into a separate library for faster compile time and better dependency management.

Validation performed

  • task:lint

Summary by CodeRabbit

  • New Features

    • Updated project to use C++20 standard, enabling new language features.
    • Enhanced modularity in the Spider project by restructuring core and worker component definitions.
  • Bug Fixes

    • Improved linking of the spider_core library to the spider_worker executable for better build configuration.

Copy link

coderabbitai bot commented Oct 31, 2024

Warning

Rate limit exceeded

@sitaowang1998 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 57c94a4 and cd6f4ff.

Walkthrough

The pull request modifies two CMakeLists.txt files to adjust the C++ standard and restructure the build configuration for the Spider project. A new setting for C++20 is introduced in the main CMakeLists.txt, while the Spider project's CMakeLists.txt is updated to improve modularity by redefining how core and worker components are linked and structured. This includes the addition of a core library and adjustments to the worker executable's source file management.

Changes

File Change Summary
CMakeLists.txt Added set(CMAKE_CXX_STANDARD 20) and set(CMAKE_CXX_STANDARD_REQUIRED ON) to specify C++20 as the required standard for compilation.
src/spider/CMakeLists.txt Restructured build configuration: defined spider_core library (static/shared), linked it to spider_worker, and updated SPIDER_WORKER_SOURCES. An alias for spider_worker as spider::worker was also added.

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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.

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: 4

🧹 Outside diff range and nitpick comments (1)
src/spider/CMakeLists.txt (1)

Line range hint 1-30: Consider adding installation and package configuration.

To make this library properly reusable, consider:

  1. Adding installation rules for headers and binaries
  2. Generating and installing package configuration files
  3. Adding version information

This will allow other projects to properly find and use the spider_core library through CMake's find_package mechanism.

Would you like me to provide an example of these configurations?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1b0c0a9 and 8d2414d.

📒 Files selected for processing (2)
  • CMakeLists.txt (1 hunks)
  • src/spider/CMakeLists.txt (1 hunks)
🔇 Additional comments (1)
CMakeLists.txt (1)

12-13: Verify all dependencies support C++20.

While the specified minimum versions of Boost, fmt, and spdlog support C++20, let's verify there are no compatibility issues.

✅ Verification successful

C++20 compatibility is verified with all dependencies

The CMakeLists.txt shows that all dependencies have compatible minimum versions that support C++20:

  • Boost 1.74+ (supports C++20)
  • fmt 8.0.1+ (supports C++20)
  • spdlog 1.9.2+ (supports C++20)
  • Abseil-cpp (explicitly propagates C++ standard via ABSL_PROPAGATE_CXX_STD)
  • MariaDB Client 3.1.0+ (C++20 compatible)

Additionally, no C++20-specific features that might cause compatibility issues were found in the codebase, except for standard build configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential C++20 compatibility issues in dependencies

# Test 1: Check if any C++20 features are used in the codebase
echo "Checking for C++20 feature usage..."
rg -l "concept|requires|constinit|consteval|co_await|co_yield|co_return|ranges::|views::|<span>|<concepts>|<ranges>|<coroutine>"

# Test 2: Look for any compiler compatibility checks
echo "Checking for compiler version checks..."
rg -l "CMAKE_CXX_COMPILER_VERSION|__cplusplus.*202"

# Test 3: Check for C++20-specific CMake configurations in dependencies
echo "Checking dependency CMake configurations..."
fd -e cmake -e txt CMakeLists --exec rg -l "CMAKE_CXX_STANDARD.*(20|2a)"

Length of output: 559


Script:

#!/bin/bash
# Let's check the specific C++20 features used in lint-tasks.yaml and examine CMakeLists.txt more closely

echo "Checking C++20 features in lint-tasks.yaml:"
cat lint-tasks.yaml

echo -e "\nChecking complete CMakeLists.txt content:"
cat CMakeLists.txt

echo -e "\nChecking for third-party dependency requirements:"
fd -t f "CMakeLists.txt|*.cmake|*.pc|*.pri|requirements" -X grep -l "REQUIRED|minimum|VERSION"

Length of output: 9616

Comment on lines 22 to 26
spider_core
Boost::boost
absl::flat_hash_map
)

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Specify dependency visibility for linked libraries.

Each dependency should explicitly declare its visibility scope to prevent unnecessary transitive dependencies.

 target_link_libraries(
     spider_core
-    Boost::boost
-    absl::flat_hash_map
+    PUBLIC
+        Boost::boost
+    PRIVATE
+        absl::flat_hash_map
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
spider_core
Boost::boost
absl::flat_hash_map
)
target_link_libraries(
spider_core
PUBLIC
Boost::boost
PRIVATE
absl::flat_hash_map
)

Comment on lines 27 to 30
set(SPIDER_WORKER_SOURCES worker/worker.cpp CACHE INTERNAL "spider worker source files")

add_executable(spider_worker)
target_sources(spider_worker PRIVATE ${SPIDER_WORKER_SOURCES})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing dependency on spider_core library.

The worker executable needs to link against the core library it depends on.

 add_executable(spider_worker)
 target_sources(spider_worker PRIVATE ${SPIDER_WORKER_SOURCES})
+target_link_libraries(spider_worker PRIVATE spider_core)
 add_executable(spider::worker ALIAS spider_worker)

Committable suggestion was skipped due to low confidence.

Comment on lines +15 to +20
if(SPIDER_USE_STATIC_LIBS)
add_library(spider_core STATIC)
else()
add_library(spider_core SHARED)
endif()
target_sources(spider_core PRIVATE ${SPIDER_CORE_SOURCES})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding modern CMake target properties and export controls.

The core library definition could benefit from additional configuration:

 if(SPIDER_USE_STATIC_LIBS)
     add_library(spider_core STATIC)
 else()
     add_library(spider_core SHARED)
 endif()
 target_sources(spider_core PRIVATE ${SPIDER_CORE_SOURCES})
+target_include_directories(spider_core
+    PUBLIC
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+        $<INSTALL_INTERFACE:include>
+)
+set_target_properties(spider_core PROPERTIES
+    CXX_VISIBILITY_PRESET hidden
+    VISIBILITY_INLINES_HIDDEN YES
+    POSITION_INDEPENDENT_CODE ON
+)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if(SPIDER_USE_STATIC_LIBS)
add_library(spider_core STATIC)
else()
add_library(spider_core SHARED)
endif()
target_sources(spider_core PRIVATE ${SPIDER_CORE_SOURCES})
if(SPIDER_USE_STATIC_LIBS)
add_library(spider_core STATIC)
else()
add_library(spider_core SHARED)
endif()
target_sources(spider_core PRIVATE ${SPIDER_CORE_SOURCES})
target_include_directories(spider_core
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
set_target_properties(spider_core PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN YES
POSITION_INDEPENDENT_CODE ON
)

CMakeLists.txt Outdated
Comment on lines 12 to 13
set(CMAKE_CXX_STANDARD 20)

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding additional C++ standard configuration flags.

The C++20 standard setting looks good, but consider adding these flags for more precise control:

 set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)

This ensures:

  • Compilation fails if C++20 is not available (STANDARD_REQUIRED)
  • Only ISO C++20 features are used, without compiler-specific extensions (EXTENSIONS OFF)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

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: 1

🧹 Outside diff range and nitpick comments (1)
src/spider/CMakeLists.txt (1)

Line range hint 1-13: Consider separating interface and implementation files.

The source list combines header and implementation files. For better maintainability and to clearly distinguish the public interface, consider organizing them into separate lists.

-set(SPIDER_CORE_SOURCES
+set(SPIDER_CORE_PUBLIC_HEADERS
     core/Error.hpp
     core/Data.hpp
     core/Task.hpp
     core/TaskGraph.hpp
     storage/MetadataStorage.hpp
     storage/DataStorage.hpp
+    storage/MysqlStorage.hpp
+    CACHE INTERNAL
+    "spider core public headers"
+)
+
+set(SPIDER_CORE_SOURCES
     storage/MysqlStorage.cpp
-    storage/MysqlStorage.hpp
     CACHE INTERNAL
     "spider core source files"
 )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8d2414d and 57c94a4.

📒 Files selected for processing (2)
  • CMakeLists.txt (1 hunks)
  • src/spider/CMakeLists.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CMakeLists.txt
🔇 Additional comments (3)
src/spider/CMakeLists.txt (3)

15-19: Previous suggestion about modern CMake properties is still applicable.

The library definition would benefit from additional target properties as suggested in the previous review.


26-26: LGTM! Worker executable configuration is well-structured.

The worker executable configuration follows CMake best practices with proper source management and aliasing.


Line range hint 1-28: Verify complete separation of core components.

The changes successfully implement the core library split. Let's verify there are no remaining direct inclusions of core files in the worker component.

✅ Verification successful

Core separation successfully verified

The worker component shows proper separation from core components with:

  • No direct includes of core headers found
  • No relative path includes to core directory
  • Clean worker implementation without any dependencies on internal core headers
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any direct includes of core headers in worker files
# that should now come through the library interface

# Test: Search for direct includes of core headers in worker files
# Expect: No direct includes of core headers in worker sources
rg -t cpp -t hpp '#include.*"core/' src/spider/worker/

Length of output: 84


Script:

#!/bin/bash
# Search for any includes of core headers in worker files, fixing the file type flags
rg --type cpp '#include.*"core/' src/spider/worker/

# Also check for potential indirect includes through relative paths
rg --type cpp '#include.*"\.\./core/' src/spider/worker/

# List all files in worker directory to ensure we're searching the right place
fd . src/spider/worker/

# Check the actual content of worker.cpp to analyze its dependencies
cat src/spider/worker/worker.cpp

Length of output: 269

absl::flat_hash_map
)
target_sources(spider_worker PRIVATE ${SPIDER_WORKER_SOURCES})
target_link_libraries(spider_worker PRIVATE ${spider_core})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect library reference.

The ${spider_core} variable reference is incorrect. The library target name should be used directly.

-target_link_libraries(spider_worker PRIVATE ${spider_core})
+target_link_libraries(spider_worker PRIVATE spider_core)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
target_link_libraries(spider_worker PRIVATE ${spider_core})
target_link_libraries(spider_worker PRIVATE spider_core)

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.

1 participant