Skip to content

Conversation

Bill-hbrhbr
Copy link
Contributor

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

Description

To meet the c++20 feature requirements of ystdlib-cpp, we must use Clang/AppleClang version 16 or later.

On macOS 13 and 14, a good solution is to install LLVM Clang v16 compilers. However, by default CMake only picks up the new toolchain's llvm-ranlib, while still using /usr/bin/ar for AR, which creates a mismatch in tool versions. For instance, after running brew install llvm@16 on macOS 14:

-- CMAKE_AR: /usr/bin/ar
-- CMAKE_RANLIB: /opt/homebrew/opt/llvm@16/bin/llvm-ranlib

It’s essential that both AR and RANLIB originate from the same LLVM distribution, otherwise linker errors will arise.

While one could technically use /usr/bin/ar together with /usr/bin/ranlib, since we're using LLVM's clang and clang++, it's best to ensure consistency by using llvm-ar and llvm-ranlib from the same distribution.

To ensure consistency within the toolchain, we add an OS platform detection + loading the appropriate toolchain setting file before the project(CLP ...) call. We also add a compiler check after the toolchains have been loaded.
All the new CMake utilities are inside ./cmake/Toolchains.

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

  • Existing workflows run successfully.

Summary by CodeRabbit

  • Chores
    • Refined the macOS build workflow to enhance dependency management and configuration.
    • Introduced the installation of a newer LLVM version to improve compiler support.
    • Improved toolchain setup and compatibility checks for a smoother build and development experience.
  • Documentation
    • Updated compiler requirements to specify support for multiple C++20 features, enhancing clarity for users.

Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Walkthrough

This pull request modifies the macOS build workflow and updates the CMake configuration. In the CI workflow, the use_shared_libs property format has been changed, and a conditional LLVM upgrade step has been removed. In CMake, a new utility file is introduced to set up toolchains and validate compiler versions, with corresponding changes in the main configuration file. Additionally, a new LLVM Clang 16 toolchain file is added, and the macOS installation script now includes the installation of llvm@16 via Homebrew.

Changes

File(s) Change Summary
.github/workflows/clp-core-build-macos.yaml Updated job matrix: changed use_shared_libs from inline array to block format; removed conditional step that upgraded AppleClang to LLVM Clang.
components/core/CMakeLists.txt
components/core/cmake/Toolchains/utils.cmake
Updated CMake configuration: included utils.cmake for toolchain setup; added setup_toolchains() and validate_compiler_versions() functions; removed previous compiler status messages.
components/core/cmake/Toolchains/llvm-clang-16-toolchain.cmake Added new LLVM Clang 16 toolchain configuration file that sets C/C++ compilers, archiver, and ranlib using the LLVM prefix determined from Homebrew, and issues an error if LLVM v16 is not installed.
components/core/tools/scripts/lib_install/macos/install-all.sh Modified installation script to include llvm@16 in the Homebrew install sequence, positioned after libarchive and before lz4.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant CMake as CMake Process
    participant Setup as setup_toolchains()
    participant Validate as validate_compiler_versions()
    
    Dev->>CMake: Run CMake configuration
    CMake->>Setup: Call setup_toolchains()
    Setup-->>CMake: Set toolchain variables (conditional on macOS version)
    CMake->>Validate: Call validate_compiler_versions()
    Validate-->>CMake: Return validation outcome (error if unsupported)
    CMake-->>Dev: Build system configured
Loading

Suggested reviewers

  • kirkrodrigues

🪧 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 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 Upgrade apple clang 16 ci: Use Apple Clang 16 to support C++20 features on macOS 13 & 14. Mar 5, 2025
@Bill-hbrhbr Bill-hbrhbr changed the title ci: Use Apple Clang 16 to support C++20 features on macOS 13 & 14. ci: Upgrade to LLVM Clang 16 to support C++20 features on macOS before version 15. Mar 6, 2025
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 (5)
components/core/cmake/Toolchains/llvm-clang-toolchain.cmake (2)

10-13: Verify that toolchain executables exist

The script sets toolchain paths but doesn't verify that the executables actually exist at those paths, which could lead to cryptic build errors later.

+# Verify executables exist
+foreach(TOOL_PATH "${CMAKE_C_COMPILER}" "${CMAKE_CXX_COMPILER}" "${CMAKE_AR}" "${CMAKE_RANLIB}")
+    if(NOT EXISTS "${TOOL_PATH}")
+        message(FATAL_ERROR "Required LLVM toolchain executable not found: ${TOOL_PATH}")
+    endif()
+endforeach()

1-13: Consider adding version and platform information to the file name

The current file name is generic and doesn't specify the LLVM version or platform. Since this is specifically for LLVM v16 on macOS, consider renaming the file to better reflect its purpose.

Consider renaming the file to something like macos-llvm16-clang-toolchain.cmake to clearly indicate its purpose and scope.

components/core/CMakeLists.txt (3)

3-3: Use a relative path for including utils.cmake

The include statement uses ${CMAKE_SOURCE_DIR} which makes assumptions about the project structure. For better modularity, consider using a relative path from this file to utils.cmake.

-include("${CMAKE_SOURCE_DIR}/cmake/Toolchains/utils.cmake")
+include("cmake/Toolchains/utils.cmake")

5-6: Add documentation about the setup_toolchains function

The function setup_toolchains() is called without any explanation of what it does or what parameters it accepts. Adding a brief comment would improve code readability.

 # Toolchain setup must come before the project() call
-setup_toolchains()
+# Set up appropriate toolchains based on platform detection (macOS uses LLVM v16)
+setup_toolchains()

10-10: Add documentation about the validate_compiler_versions function

The function validate_compiler_versions() is called without any explanation of what it does or what parameters it accepts. Adding a brief comment would improve code readability.

-validate_compiler_versions()
+# Verify that compiler versions meet minimum requirements (C++20 support)
+validate_compiler_versions()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a97c38 and 9c7e93d.

📒 Files selected for processing (3)
  • components/core/CMakeLists.txt (1 hunks)
  • components/core/cmake/Toolchains/llvm-clang-toolchain.cmake (1 hunks)
  • components/core/cmake/Toolchains/utils.cmake (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/cmake/Toolchains/utils.cmake
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-macos (macos-13, true)
  • GitHub Check: build-macos (macos-13, false)
  • GitHub Check: build-macos (macos-15, true)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (1)
components/core/CMakeLists.txt (1)

3-10:

❓ Verification inconclusive

Verify toolchain utilities are properly implemented

The PR introduces two new functions (setup_toolchains() and validate_compiler_versions()) that aren't visible in this review. Ensure they properly handle all platforms and error cases.


🏁 Script executed:

#!/bin/bash
# Check the implementation of the utils.cmake file to ensure proper error handling

# First, check if the utils.cmake file exists
if [ -f "${PWD}/components/core/cmake/Toolchains/utils.cmake" ]; then
  echo "Found utils.cmake file. Checking implementation..."
  
  # Check if setup_toolchains function exists and handles platforms
  grep -A 20 "function(setup_toolchains" "${PWD}/components/core/cmake/Toolchains/utils.cmake"
  
  # Check if validate_compiler_versions function exists and checks for C++20
  grep -A 20 "function(validate_compiler_versions" "${PWD}/components/core/cmake/Toolchains/utils.cmake"
  
  # Check if there's platform detection for macOS
  grep -i "darwin\|apple\|macos" "${PWD}/components/core/cmake/Toolchains/utils.cmake"
else
  echo "ERROR: utils.cmake file not found at expected location"
fi

Length of output: 2236


Toolchain utilities implementation appears sound, but please verify non-Darwin support

  • The setup_toolchains() function is present and correctly detects Darwin systems by invoking sw_vers to obtain the macOS version. It conditionally sets the toolchain file when the macOS version is below "15".
  • The validate_compiler_versions() function correctly sets minimum required versions for AppleClang (16), Clang (16), and GNU (11), and it properly issues a fatal error for unsupported compilers.
  • Note that the current implementation in setup_toolchains() explicitly handles Darwin systems only. Please confirm that non-Darwin platforms are either intentionally unconfigured at this stage or that their toolchain setup is managed elsewhere.

@Bill-hbrhbr
Copy link
Contributor Author

@coderabbitai void the rest of your existing comments. Too verbose for this PR.

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 (1)
components/core/CMakeLists.txt (1)

2-7: Toolchain Setup and Configuration

Lines 2–7 now include the explicit inclusion of cmake/Toolchains/utils.cmake and the call to setup_toolchains(). This ordering is critical as all toolchain settings must be established before the project() command is invoked. Please verify that the setup_toolchains() function is correctly defined in the included file and that its implementation properly configures the LLVM v16 toolchain for macOS. Also, ensure that any toolchain-related functions or variables follow the project’s naming conventions (for example, using a CLP_ prefix) as noted in earlier reviews.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0e68f8e and 23d9de5.

📒 Files selected for processing (1)
  • components/core/CMakeLists.txt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: filter-relevant-changes
  • GitHub Check: build-macos (macos-15, false)
  • GitHub Check: build-macos (macos-14, true)
  • GitHub Check: build-macos (macos-15, true)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (1)
components/core/CMakeLists.txt (1)

10-11: Compiler Version Validation

The addition of the validate_compiler_versions() call immediately after the project declaration is a good measure to ensure that the correct compiler is being used. This function should verify that the compiler meets the minimum requirements (i.e. LLVM Clang v16) for supporting C++20 features on macOS 13/14. Please ensure that its implementation in utils.cmake accurately detects incompatible compiler versions and provides clear error messages.

Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

@Bill-hbrhbr I'll resolve my existing comments as requested.

✅ Actions performed

Comments resolved.

Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

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

A few more suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, since we're hardcoding the version to 16, can we rename this file to llvm-16-clang-toolchain.cmake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to llvm-clang-16-toolchain.cmake

Bill-hbrhbr and others added 2 commits March 12, 2025 12:06
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

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

Can you change this line to:

A recent compiler that supports C++20

The rationale being that we can avoid having to keep that doc up-to-date with the precise versions required, but if the user has too low a compiler version, the validation in this PR will inform them.

For the PR title, how about:

build(cmake): Require compiler versions that support the C++20 features necessary for compiling `ystdlib-cpp`; Add toolchain file for LLVM Clang 16 on macOS 13 & 14.

@Bill-hbrhbr Bill-hbrhbr changed the title build(cmake): Add toolchain specification and validations utilities to support C++20 features on macOS 13/14 via LLVM Clang v16. build(cmake): Require compiler versions that support the C++20 features necessary for compiling ystdlib-cpp; Add toolchain file for LLVM Clang 16 on macOS 13 & 14. Mar 12, 2025
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 (1)
docs/src/dev-guide/components-core/index.md (1)

9-11: Enhance Compiler Requirement Clarity
The updated text now clearly specifies that a recent compiler supporting full C++20 features is needed. Explicitly listing both std::span and std::source_location helps users understand the minimum feature set required by the project. This aligns with the changes in your CMake configuration and ensures consistency in the documentation.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f35cd77 and e88f940.

📒 Files selected for processing (1)
  • docs/src/dev-guide/components-core/index.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: ubuntu-jammy-dynamic-linked-bins
  • GitHub Check: ubuntu-jammy-lint
  • GitHub Check: ubuntu-jammy-static-linked-bins
  • GitHub Check: centos-stream-9-static-linked-bins
  • GitHub Check: centos-stream-9-dynamic-linked-bins
  • GitHub Check: build-macos (macos-15, true)
  • GitHub Check: build-macos (macos-14, false)
  • GitHub Check: build-macos (macos-14, true)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build (macos-latest)

@Bill-hbrhbr Bill-hbrhbr merged commit 3017856 into y-scope:main Mar 12, 2025
21 checks passed
@Bill-hbrhbr Bill-hbrhbr deleted the upgrade-apple-clang-16 branch March 12, 2025 17:42
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