Skip to content

feat: Make spider installable (resolves #138). #139

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

anlowee
Copy link
Member

@anlowee anlowee commented May 18, 2025

Description

#138

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

# In devcontainer
cd /workspaces/spider
cmake -B _build -DCMAKE_INSTALL_PREFIX=/workspaces/install-test
cmake --build _build --target install -j$(nproc)

cd /workspaces/spider/examples/quick-start
cmake -S . -B build/spider -DCMAKE_PREFIX_PATH="/workspaces/install-test;"
cmake --build build/spider --parallel $(nproc) --target tasks client

Summary by CodeRabbit

  • New Features
    • Added CMake packaging support, enabling easier discovery and use of the project by downstream projects via CMake's package mechanism.
  • Refactor
    • Enhanced build configuration with formal alias targets, export rules, and comprehensive install rules for libraries and headers to improve integration and usability.
  • Chores
    • Introduced new CMake configuration files to manage dependencies and streamline build setup.
    • Updated build and install task commands to include installation steps and proper prefix path configuration for examples.
    • Improved module inclusion paths to ensure reliable resolution relative to the source directory.

@anlowee anlowee requested review from sitaowang1998 and a team as code owners May 18, 2025 23:31
Copy link
Contributor

coderabbitai bot commented May 18, 2025

"""

Walkthrough

This update introduces CMake packaging support, generates and installs CMake package configuration files, and formalizes install/export rules for the spider_core and spider_client libraries. It also refactors example project integration to use find_package, and adds alias targets and explicit header installation for downstream CMake compatibility.

Changes

File(s) Change Summary
CMakeLists.txt, cmake/Config.cmake.in Added CMake packaging support: generates and installs package config/version files, introduces a new config template managing dependencies and enforcing build variables, and includes export files for core/client components.
src/spider/CMakeLists.txt Updated to use PRIVATE header visibility, added PUBLIC include directories, created alias targets (spider_core, spider_client), and added comprehensive install/export rules for headers and targets, including error_handling.
examples/quick-start/CMakeLists.txt Refactored to remove direct subdirectory inclusion; now finds Spider via find_package, updates linked targets, and simplifies dependency handling for example projects.
taskfile.yaml Modified config-cmake-project task to add explicit build and install steps for the main project and set installation/prefix paths, enabling the example project to find the installed main project via CMAKE_PREFIX_PATH.
cmake/Modules/FindMariaDBClientCpp.cmake Changed inclusion of FindLibraryDependencies.cmake to use an absolute path based on ${CMAKE_CURRENT_LIST_DIR} instead of a relative path, ensuring correct module resolution.

Sequence Diagram(s)

sequenceDiagram
    participant DownstreamProject
    participant CMake
    participant SpiderPackage

    DownstreamProject->>CMake: find_package(spider REQUIRED)
    CMake->>SpiderPackage: Load Config.cmake
    SpiderPackage->>CMake: find_dependency(Boost, fmt, spdlog, etc.)
    SpiderPackage->>CMake: Check SPIDER_YSTDLIB_SOURCE_DIRECTORY
    SpiderPackage->>CMake: add_subdirectory(ystdlib)
    SpiderPackage->>CMake: include spider_core_export.cmake
    SpiderPackage->>CMake: include spider_client_export.cmake
    CMake->>DownstreamProject: Make spider::spider_client and spider::spider_core available
Loading

Possibly related PRs

  • y-scope/spider#15: The main PR focuses on adding CMake packaging support and installation/export rules for the already separated spider_core and spider_client libraries, while the retrieved PR introduces the initial split of the core into a separate library and sets up its basic build targets; thus, the main PR builds upon and extends the structural changes introduced in the retrieved PR.
  • y-scope/spider#13: The main PR adds CMake package configuration files and installation/export rules to enable downstream usage of the spider project as a CMake package, while the retrieved PR introduces the initial CMake build setup including adding dependencies like spdlog, fmt, and MariaDBClient but does not include packaging or export configuration; thus, they modify related build system files but focus on different aspects of CMake integration.
  • y-scope/spider#36: The main PR adds CMake packaging support and refactors example build configuration to use find_package(spider REQUIRED) and link against spider::spider_client, while the retrieved PR adds a quick-start guide and example code including a CMakeLists.txt for building a Spider client and tasks; thus, both PRs modify the example's CMake setup and usage of the Spider library, showing a direct relation in build configuration and example integration.

Suggested reviewers

  • sitaowang1998
  • kirkrodrigues
    """

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 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 67a7bc6 and 6eece79.

📒 Files selected for processing (1)
  • cmake/Modules/FindMariaDBClientCpp.cmake (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cmake/Modules/FindMariaDBClientCpp.cmake
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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
Contributor

@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

🧹 Nitpick comments (4)
cmake/Config.cmake.in (1)

14-16: Consider making YSTDLIB dependency optional

The current check forces users to define SPIDER_YSTDLIB_SOURCE_DIRECTORY to use the spider package. Consider making this dependency optional or providing an alternative way to configure it.

 if(NOT DEFINED SPIDER_YSTDLIB_SOURCE_DIRECTORY)
-    message(FATAL_ERROR "SPIDER_YSTDLIB_SOURCE_DIRECTORY must be set to use spider")
+    # Look for an installed ystdlib or provide a default path option
+    set(SPIDER_YSTDLIB_SOURCE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../ystdlib
+        CACHE PATH "Path to ystdlib source directory")
+    message(STATUS "SPIDER_YSTDLIB_SOURCE_DIRECTORY not defined, using default: ${SPIDER_YSTDLIB_SOURCE_DIRECTORY}")
 endif()
src/spider/CMakeLists.txt (3)

65-113: Consider simplifying header installation with GLOB

The current approach lists each header file individually, which is verbose and error-prone when adding new headers. Consider using GLOB to simplify maintenance.

-install(
-    FILES
-    ${CMAKE_CURRENT_SOURCE_DIR}/core/Error.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/core/Data.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/core/Driver.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/core/KeyValueData.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/core/Task.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/core/TaskGraph.hpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/core/JobMetadata.hpp
-    DESTINATION include/${PROJECT_NAME}/core
-)
+file(GLOB CORE_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/core/*.hpp")
+install(
+    FILES ${CORE_HEADERS}
+    DESTINATION include/${PROJECT_NAME}/core
+)

Note: While this approach simplifies the code, be aware that CMake generally discourages using GLOB for build targets due to potential issues with newly added files not triggering rebuilds. For installation rules, this limitation is less important.


273-273: Consider renaming alias target for clarity

The current alias ${PROJECT_NAME}::spider for the spider_client target might cause confusion. Consider using ${PROJECT_NAME}::spider_client for consistency with the actual target name.

-add_library(${PROJECT_NAME}::spider ALIAS spider_client)
+add_library(${PROJECT_NAME}::spider_client ALIAS spider_client)

169-186: Consider adding installation rules for executables

The current changes don't include installation rules for executables like spider_task_executor, spider_worker, and spider_scheduler. Consider adding installation rules for these executables to make them available to users.

target_link_libraries(
    spider_task_executor
    PRIVATE
        Boost::filesystem
        Boost::program_options
        Boost::system
        ${CMAKE_DL_LIBS}
        fmt::fmt
        spdlog::spdlog
)

+install(
+    TARGETS spider_task_executor
+    RUNTIME DESTINATION bin
+)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a29306 and c736585.

📒 Files selected for processing (4)
  • CMakeLists.txt (1 hunks)
  • cmake/Config.cmake.in (1 hunks)
  • examples/quick-start/CMakeLists.txt (3 hunks)
  • src/spider/CMakeLists.txt (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: lint
🔇 Additional comments (12)
CMakeLists.txt (1)

200-218: LGTM: CMake packaging support properly implemented

The changes correctly add CMake packaging support, enabling the project to be installed and used via CMake's find_package() mechanism. The implementation follows best practices by using CMakePackageConfigHelpers to generate and install the necessary configuration files.

examples/quick-start/CMakeLists.txt (3)

4-7: LGTM: Proper package consumption setup

The example project correctly demonstrates how to use the spider package as an installable dependency. Setting the right paths and using find_package(spider REQUIRED) showcases the intended use case.


18-18: LGTM: Updated target reference

Correctly updated to use the namespaced target spider::spider_client from the installed package instead of direct linking.


27-27: LGTM: Consistent target naming

Target reference is consistent with the exported namespace and matches the one used for the tasks library.

cmake/Config.cmake.in (2)

1-12: LGTM: Well-structured package configuration

The configuration properly initializes the package and correctly handles dependency discovery with appropriate version requirements.


18-25: LGTM: Proper integration of required components

The configuration correctly adds the ystdlib subdirectory and includes the export files for the core and client components.

src/spider/CMakeLists.txt (6)

46-51: LGTM: Properly configured include directories

The changes correctly switch header files from PUBLIC to PRIVATE in target_sources while adding explicit PUBLIC include directories with proper build and install interfaces.


63-63: LGTM: Added proper alias target for spider_core

The alias target follows CMake best practices by using the project namespace.


115-125: LGTM: Properly configured export targets for spider_core

The export targets are correctly defined with namespace and installed to the appropriate location.


127-137: LGTM: Properly configured export targets for error_handling

The export targets are correctly defined with namespace and installed to the appropriate location.


258-263: LGTM: Properly configured include directories for spider_client

Similar to spider_core, the changes correctly switch header files from PUBLIC to PRIVATE in target_sources while adding explicit PUBLIC include directories with proper build and install interfaces.


275-306: LGTM: Properly configured installation and export for spider_client

The installation rules for header files and export targets are correctly defined.

Copy link
Contributor

@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)
taskfile.yaml (2)

45-47: Extract and reuse the install-test path as a variable & clean it up

To avoid hard-coded paths and ensure idempotent runs, pull install-test into a dedicated vars entry (e.g. G_INSTALL_TEST), replace inline literals, and update the clean task to remove it:

 vars:
   G_DEPS_CMAKE_SETTINGS_FILE: "{{.G_DEPS_CMAKE_SETTINGS_DIR}}/settings.cmake"
+  G_INSTALL_TEST: "{{.ROOT_DIR}}/install-test"

 tasks:
   clean:
     cmds:
-      - "rm -rf '{{.G_BUILD_DIR}}'"
+      - "rm -rf '{{.G_BUILD_DIR}}' '{{.G_INSTALL_TEST}}'"

 config-cmake-project:
   cmds:
-      - "cmake -S '{{.ROOT_DIR}}' -B '{{.G_BUILD_SPIDER_DIR}}' -DCMAKE_INSTALL_PREFIX='{{.ROOT_DIR}}/install-test'"
-      - "cmake --build '{{.G_BUILD_SPIDER_DIR}}' --target install -j$(nproc)"
+      - "cmake -S '{{.ROOT_DIR}}' -B '{{.G_BUILD_SPIDER_DIR}}' -DCMAKE_INSTALL_PREFIX='{{.G_INSTALL_TEST}}'"
+      - "cmake --build '{{.G_BUILD_SPIDER_DIR}}' --target install -j$(nproc)"

Happy to draft the full updated taskfile.yaml if you’d like.


47-47: Remove trailing semicolon & add example build step

The trailing semicolon in CMAKE_PREFIX_PATH may introduce an empty search entry, and currently the example is only configured, not built. Consider:

 config-cmake-project:
   cmds:
-      - "cmake -S '{{.ROOT_DIR}}/examples/quick-start' -B '{{.G_BUILD_EXAMPLES_DIR}}' -DCMAKE_PREFIX_PATH='{{.ROOT_DIR}}/install-test;'"
+      - "cmake -S '{{.ROOT_DIR}}/examples/quick-start' -B '{{.G_BUILD_EXAMPLES_DIR}}' -DCMAKE_PREFIX_PATH='{{.ROOT_DIR}}/install-test'"
+      - "cmake --build '{{.G_BUILD_EXAMPLES_DIR}}' --target all -j$(nproc)"

Let me know if you’d like me to integrate these changes.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c736585 and fa147aa.

📒 Files selected for processing (4)
  • CMakeLists.txt (1 hunks)
  • examples/quick-start/CMakeLists.txt (3 hunks)
  • src/spider/CMakeLists.txt (4 hunks)
  • taskfile.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • examples/quick-start/CMakeLists.txt
  • CMakeLists.txt
  • src/spider/CMakeLists.txt
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)

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