Skip to content

build!: Install ystdlib as a CMake package to avoid issues when projects use both Spider and ystdlib through add_subdirectory. - #160

Merged
sitaowang1998 merged 13 commits into
y-scope:mainfrom
sitaowang1998:ystdlib_package
Aug 6, 2025
Merged

build!: Install ystdlib as a CMake package to avoid issues when projects use both Spider and ystdlib through add_subdirectory.#160
sitaowang1998 merged 13 commits into
y-scope:mainfrom
sitaowang1998:ystdlib_package

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jun 26, 2025

Copy link
Copy Markdown
Collaborator

Description

Both clp and spider add ystdlib as subdirectory. When integrating spider into clp, compilation fails because duplicated ystdlib files.

This PR updates ystdlib version to use the latest version that supports install ystdlib as a package. This PR changes the dependency install tasks to install ystdlib as a package.

Because the updated ystdlib requires CMake minimum version 3.23, this PR also updates minimum CMake version required and updates GitHub workflows to install CMake 3.23.5.

This PR adds POSITION_INDEPENDENT_CODE to the dependency build tasks because Spider produces shared library spider_client.so.

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

  • GitHub workflows pass.
  • ystdlib install task works in dev container.
  • Project builds using the ystdlib package in dev container.
  • Unit tests pass in dev container.
  • Integration tests pass in dev container.

Summary by CodeRabbit

  • Chores
    • Updated the build process to require CMake version 3.23 or higher, with automated installation of this version via a new script.
    • Changed dependency management to use a pre-installed ystdlib package instead of building it from source.
    • Renamed and updated dependency installation tasks for clarity and improved automation.

@sitaowang1998
sitaowang1998 requested a review from a team as a code owner June 26, 2025 16:00
@coderabbitai

coderabbitai Bot commented Jun 26, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update the CMake minimum version, switch ystdlib integration from a subdirectory build to using find_package for a pre-installed package, and revise dependency installation tasks and scripts. A new script for installing a specific CMake version is added, and the Linux development installation script is modified to use this script instead of the package manager.

Changes

File(s) Change Summary
Build configuration
CMakeLists.txt
Updated minimum CMake version from 3.22.1 to 3.23; replaced subdirectory build of ystdlib-cpp with find_package for a pre-installed ystdlib package.
Dependency task definitions
dep-tasks.yaml
Renamed task download-ystdlib to install-ystdlib; updated dependency in install-all-run; changed ystdlib install command to :utils:cmake:install-remote-tar; updated tarball URL, SHA256, output/working directories, and CMake arguments; removed shell command for CMake settings, replaced with direct arguments.
CMake installation script
tools/scripts/lib_install/install-cmake.sh
Added new Bash script to automate downloading, building, and installing a specified CMake version from source, with parallel build and cleanup.
Linux development environment setup
tools/scripts/lib_install/linux/install-dev.sh
Removed apt-get install cmake; now runs install-cmake.sh 3.23.5 to install CMake; continues to verify version with check-cmake-version.sh.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant install-dev.sh
    participant install-cmake.sh
    participant System

    User->>install-dev.sh: Run script
    install-dev.sh->>install-cmake.sh: Call with version 3.23.5
    install-cmake.sh->>System: Download and extract CMake source
    install-cmake.sh->>System: Build and install CMake
    install-cmake.sh->>install-dev.sh: Return control
    install-dev.sh->>System: Run check-cmake-version.sh
Loading
sequenceDiagram
    participant CMake
    participant System
    participant ystdlib (pre-installed)

    CMake->>System: Run configure
    CMake->>ystdlib (pre-installed): find_package(ystdlib)
    ystdlib (pre-installed)-->>CMake: Provide package info (if found)
    CMake->>System: Print status message
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • LinZhihao-723

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 d2ceaf5 and 49e8759.

📒 Files selected for processing (1)
  • dep-tasks.yaml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • dep-tasks.yaml
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (7)
tools/scripts/lib_install/install-cmake.sh (4)

6-10: Exit with a non-zero status when printing usage

exit without an explicit code may propagate a previous success status, misleading CI checks.

-    exit
+    exit 1

13-16: sudo echo is a fragile privilege test

sudo echo can still prompt for a password (breaking unattended runs) and produces no actionable side-effect. Prefer a one-liner that validates sudo rights up-front:

if ! sudo -n true 2>/dev/null; then
  echo "Password-less sudo not available; the build may stall."
fi

18-20: Use nproc fallback for CPU count

/proc/cpuinfo is Linux-only and may misbehave in containers with CPU limits. nproc is more portable:

-num_cpus=$(grep -c ^processor /proc/cpuinfo)
+num_cpus=$(nproc 2>/dev/null || grep -c ^processor /proc/cpuinfo)

46-47: Ensure cleanup even on early exit

If the build fails, the temp directory persists. Add a trap:

trap 'rm -rf "$temp_dir"' EXIT
CMakeLists.txt (1)

181-185: Missing version hint for ystdlib

If multiple incompatible ystdlib versions are published, find_package(ystdlib REQUIRED) may resolve an older one first on users’ systems. Consider:

find_package(ystdlib 0.4 REQUIRED) # replace with actual minimum

This safeguards subtle ABI breaks.

dep-tasks.yaml (2)

15-26: Duplicate install-boost dependency

install-all-run already depends on install-boost; adding it again inside install-ystdlib is redundant and lengthens no-op DAG traversal. Removing the extra edge keeps the task graph cleaner.


57-76: Hard-coded commit hash without comment

The URL pins ystdlib to commit 0ae886c but there is no inline rationale (tag, security fix, etc.). Future maintainers will struggle to know when it is safe to upgrade. Append a brief comment, e.g.:

# 0ae886c = v1.2.0 + cmake-package support
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fdfd8f2 and c77c662.

📒 Files selected for processing (4)
  • CMakeLists.txt (2 hunks)
  • dep-tasks.yaml (2 hunks)
  • tools/scripts/lib_install/install-cmake.sh (1 hunks)
  • tools/scripts/lib_install/linux/install-dev.sh (1 hunks)
⏰ 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)
🔇 Additional comments (2)
tools/scripts/lib_install/linux/install-dev.sh (1)

34-37: Possible double-sudo invocation

privileged_command_prefix may already be sudo, yet install-cmake.sh internally invokes sudo when EUID ≠ 0. Running sudo sudo … is harmless on most systems but unnecessary and can confuse log analysis. You could call the installer unprivileged and let it elevate itself:

-${privileged_command_prefix} "$lib_install_scripts_dir"/install-cmake.sh 3.23.5
+"$lib_install_scripts_dir"/install-cmake.sh 3.23.5
CMakeLists.txt (1)

1-1: Bump to 3.23 may break downstream consumers

Raising cmake_minimum_required to 3.23 is fine for the dev container, but external users on LTS distros (e.g., Ubuntu 22.04 ships 3.22.x) will now fail to configure. Confirm that packaging/distribution notes and CI matrices reflect this new floor version.

Comment on lines +30 to +33
tar_filename=cmake-${version}.tar.gz
curl -fsSL https://github.com/Kitware/CMake/releases/download/v${version}/${tar_filename} -o ${tar_filename}
tar xzf ${tar_filename}
cd cmake-${version}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

No integrity check on downloaded tarball

Blindly piping an archive into the build chain is a supply-chain risk. Fetch the official SHA256 from the same release and validate:

curl -fsSL -O https://github.com/Kitware/CMake/releases/download/v${version}/${tar_filename}.sha256
sha256sum -c ${tar_filename}.sha256
🤖 Prompt for AI Agents
In tools/scripts/lib_install/install-cmake.sh around lines 30 to 33, the script
downloads and extracts the CMake tarball without verifying its integrity. To fix
this, add steps to download the corresponding SHA256 checksum file from the same
release URL and verify the downloaded tarball using sha256sum -c before
extracting it. This ensures the tarball is authentic and prevents supply-chain
risks.

Comment thread tools/scripts/lib_install/install-cmake.sh
Comment on lines +24 to +25
temp_dir=/tmp/${package_name}-installation
mkdir -p $temp_dir

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Race-safe temporary directory

A fixed /tmp/cmake-installation can collide with parallel runs. Leverage mktemp:

-temp_dir=/tmp/${package_name}-installation
-mkdir -p $temp_dir
+temp_dir=$(mktemp -d /tmp/${package_name}-installation-XXXXXX)
🤖 Prompt for AI Agents
In tools/scripts/lib_install/install-cmake.sh around lines 24 to 25, the
temporary directory is set to a fixed path which can cause collisions in
parallel runs. Replace the fixed directory assignment with a call to mktemp to
create a unique, race-safe temporary directory. Use mktemp with appropriate
options to generate a unique directory under /tmp and assign it to temp_dir.

@sitaowang1998
sitaowang1998 requested a review from davidlion June 26, 2025 17:28
@sitaowang1998 sitaowang1998 changed the title build: Install ystdlib as a package to avoid duplicate ystdlib files. build!: Install ystdlib as a package to avoid duplicate ystdlib files. Jun 26, 2025
Comment thread dep-tasks.yaml Outdated
Comment on lines +70 to +75
CMAKE_SETTINGS_DIR: "{{.G_DEPS_CMAKE_SETTINGS_DIR}}"
GEN_ARGS:
- "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
- "-Dystdlib_BUILD_TESTING=OFF"
- "-C {{.G_DEPS_CMAKE_SETTINGS_DIR}}/boost.cmake"
- "-DCMAKE_POLICY_DEFAULT_CMP0144=NEW"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Previously we discussed whether CMAKE_POSITION_INDEPENDENT_CODE and CMAKE_POLICY_DEFAULT_CMP0144. Iirc it wasn't clear they were necessary.

I remember I couldn't reproduce needing CMAKE_POLICY_DEFAULT_CMP0144 and iirc I don't think you could either.

If they are necessary the reasons need to be documented in the description.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

PIC is required because Spider produces a shared library.
CMP0144 is removed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
dep-tasks.yaml (1)

74-77: Explain or drop hard-coding of CMP0144 policy

-DCMAKE_POLICY_DEFAULT_CMP0144=NEW is still being forced even though earlier discussion concluded we could not reproduce the need for it. This policy changes how project() sets variables and can silently mask configuration issues in downstream packages. If there is now concrete evidence that ystdlib requires it, please document the reason; otherwise remove the flag to keep the build surface minimal.

🧹 Nitpick comments (2)
dep-tasks.yaml (2)

62-64: Redundant dependency declaration

install-ystdlib is already executed after install-boost via the install-all-run chain, so keeping install-boost in the local deps: list is unnecessary duplication and slightly stretches the DAG. Consider dropping it for clarity.


59-70: Pass JOBS to align with other install tasks

All other install-* tasks propagate JOBS: "{{.G_DEPS_MAX_PARALLELISM_PER_TASK}}" to :utils:cmake:install-remote-tar, enabling parallel builds. ystdlib omits this, which will fall back to the tool’s default and slow CI-runtime.

           GEN_ARGS:
             - "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
             - "-Dystdlib_BUILD_TESTING=OFF"
             - "-C {{.G_DEPS_CMAKE_SETTINGS_DIR}}/boost.cmake"
             - "-DCMAKE_POLICY_DEFAULT_CMP0144=NEW"
+          JOBS: "{{.G_DEPS_MAX_PARALLELISM_PER_TASK}}"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c99c31e and 61cb255.

📒 Files selected for processing (1)
  • dep-tasks.yaml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)

@sitaowang1998
sitaowang1998 requested a review from davidlion August 4, 2025 17:59
@sitaowang1998 sitaowang1998 changed the title build!: Install ystdlib as a package to avoid duplicate ystdlib files. build!: Install ystdlib as a package to avoid duplicate ystdlib files. Aug 5, 2025
@sitaowang1998 sitaowang1998 changed the title build!: Install ystdlib as a package to avoid duplicate ystdlib files. build!: Install ystdlib as a cmake package to avoid duplicate ystdlib files when a project add both Spider and ystdlib as submodule. Aug 6, 2025
@sitaowang1998 sitaowang1998 changed the title build!: Install ystdlib as a cmake package to avoid duplicate ystdlib files when a project add both Spider and ystdlib as submodule. build: Install ystdlib as a CMake package to avoid issues when projects use both Spider and ystdlib through add_subdirectory. Aug 6, 2025
@sitaowang1998 sitaowang1998 changed the title build: Install ystdlib as a CMake package to avoid issues when projects use both Spider and ystdlib through add_subdirectory. build!: Install ystdlib as a CMake package to avoid issues when projects use both Spider and ystdlib through add_subdirectory. Aug 6, 2025
@sitaowang1998
sitaowang1998 merged commit 0882c17 into y-scope:main Aug 6, 2025
6 checks passed
@sitaowang1998
sitaowang1998 deleted the ystdlib_package branch August 6, 2025 03:15
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