Skip to content

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.#745

Merged
Bill-hbrhbr merged 41 commits into
y-scope:mainfrom
Bill-hbrhbr:upgrade-apple-clang-16
Mar 12, 2025

Conversation

@Bill-hbrhbr

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

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented Mar 5, 2025

Copy link
Copy Markdown
Contributor

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
@Bill-hbrhbr

Copy link
Copy Markdown
Contributor Author

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

@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

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

@coderabbitai

coderabbitai Bot commented Mar 12, 2025

Copy link
Copy Markdown
Contributor

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

✅ Actions performed

Comments resolved.

@kirkrodrigues kirkrodrigues left a comment

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.

A few more suggestions.

Comment thread components/core/cmake/Toolchains/llvm-clang-toolchain.cmake Outdated
Comment thread components/core/cmake/Toolchains/utils.cmake Outdated
Comment thread components/core/cmake/Toolchains/utils.cmake Outdated

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.

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

Copy link
Copy Markdown
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

Comment thread components/core/cmake/Toolchains/utils.cmake Outdated
Comment thread components/core/CMakeLists.txt Outdated
Bill-hbrhbr and others added 2 commits March 12, 2025 12:06
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>

@kirkrodrigues kirkrodrigues left a comment

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.

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

@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

🧹 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
@Bill-hbrhbr Bill-hbrhbr deleted the upgrade-apple-clang-16 branch March 12, 2025 17:42
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 2026
…es necessary for compiling `ystdlib-cpp`; Add toolchain file for LLVM Clang 16 on macOS 13 & 14. (y-scope#745)

Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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