Skip to content

Build/improve llvm development - #51

Merged
creeper5820 merged 3 commits into
mainfrom
build/improve-llvm-development
Mar 3, 2026
Merged

Build/improve llvm development#51
creeper5820 merged 3 commits into
mainfrom
build/improve-llvm-development

Conversation

@creeper5820

@creeper5820creeper5820 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

改进 LLVM 开发工具链

概述

本 PR 改进了 RMCS 项目的 LLVM 开发工具链与构建体验:在构建脚本中加入基于可用 LLVM 工具链的自动检测与启用逻辑、为构建命令添加统一的 colcon/CMake 参数化调用与输出控制,在 Dockerfile 中引入可参数化的 LLVM 版本安装与 update-alternatives 注册;同时新增 zsh 命令补全脚本以改善交互体验。

核心改动

1. 构建脚本增强(.script/build-rmcs)

  • 增加条件化的 LLVM 工具链检测与启用:当 RMCS_USE_GCC != "ON" 时,验证 clang、clang++、llvm-ar、llvm-ranlib、ld.lld 等工具存在,缺失则报错退出;否则支持回退到 GCC 路径。
  • 将 CC/CXX 设为 clang/clang++(通过 command -v 获取绝对路径),并通过 -DCMAKE_AR 与 -DCMAKE_RANLIB 传递 llvm-ar/llvm-ranlib 给 CMake;为链接器添加 -fuse-ld=lld。
  • 使用数组构建 cmake_toolchain_args、cmake_args、colcon_args,以及新增 event_handlers_args(包含 console_cohesion+),并通过 cmake_args wrapper 将工具链参数传给 CMake。
  • 改用组装好的参数数组调用 colcon build,强制彩色输出(CLICOLOR_FORCE=1)、启用 verbose-colcon、清空 NINJA_STATUS 以控制输出一致性;默认使用 Ninja 生成器和较低的 CMake 日志等级(-DCMAKE_MESSAGE_LOG_LEVEL=ERROR)。

2. Docker 镜像更新(Dockerfile)

  • 引入 ARG LLVM_VERSION=22,参数化 LLVM 版本号。
  • 使用 llvm-toolchain-noble-${LLVM_VERSION} apt 源并安装版本化的 LLVM 包(clang-${LLVM_VERSION}、clangd-${LLVM_VERSION}、clang-format-${LLVM_VERSION}、clang-tidy-${LLVM_VERSION}、lldb-${LLVM_VERSION}、lld-${LLVM_VERSION}、llvm-${LLVM_VERSION} 等)。
  • 通过 update-alternatives 为版本化二进制(clang、clang++、clangd、clang-format、clang-tidy、lldb、llvm-ar、llvm-ranlib、ld.lld 等)注册无版本别名,包含将 clang-tidy、llvm-ar、llvm-ranlib、ld.lld 加入 alternatives 集合并设置优先级。
  • 保留镜像清理步骤(apt autoremove/clean)。

3. zsh 补全脚本(.script/complete/_build-rmcs)

  • 新增针对命令别名 build-rmcs 的 zsh 补全函数(compdef 注册)。
  • 补全函数选择可用后端(优先 _python_argcomplete,其次 _colcon)。使用 python_argcomplete 时构造合适的 COMP_LINE/COMP_POINT 以代理 colcon build 的补全;否则在参数中注入 "colcon build" 并调整游标,完成后恢复 shell 状态。
  • 提供回退与错误提示,当两种后端均不可用时返回错误信息。

影响范围

  • 主要修改文件及行数变化:
    • .script/build-rmcs(约 +41 / -4)
    • Dockerfile(约 +11 / -7)
    • .script/complete/_build-rmcs(约 +51 / -0)
  • 未改变任何对外导出/公共接口的签名或声明。

其它

  • 提高了容器与本地开发环境中使用 LLVM 工具链的一致性与可配置性,并改善了交互式补全与构建输出可读性。
  • PR 作者已请求 @qzhhhi 审核,qzhhhi 表示会尽快审查。

@coderabbitai

coderabbitaiBot commented Feb 26, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

在构建脚本与镜像中引入基于 LLVM 的可选工具链与构建参数:.script/build-rmcs 在满足条件时检测并导出 Clang/LLVM 工具、组装并传递 cmake/colcon 参数以使用 LLD/Ninja;Dockerfile 参数化 LLVM 版本;新增 Zsh 补全文件 .script/complete/_build-rmcs

Changes

Cohort / File(s)Summary
构建脚本工具链配置
​.script/build-rmcs
改为基于条件的 LLVM 工具链路径:检测 clang, clang++, llvm-ar, llvm-ranlib, ld.lld;当使用 LLVM 时导出 CC/CXX/AR/RANLIB、加入 -fuse-ld=lld、构建 cmake_toolchain_argscolcon_argscmake_args,并用这些参数调用 colcon build(强制彩色输出、清除 Ninja 状态);缺失则报错或回退到原流程。
Docker 镜像 LLVM 工具包
Dockerfile
新增 ARG LLVM_VERSION=22,将 apt 源与安装包参数化为 ${LLVM_VERSION};安装版本化的 clang, clangd, clang-format, clang-tidy, lld, llvm 等;通过 update-alternatives 注册并指向版本化的 clang, clang++, clangd, clang-format, clang-tidy, lld, llvm-ar, llvm-ranlib, ld.lld
Zsh 补全脚本
.script/complete/_build-rmcs
新增 zsh 补全函数并为 build-rmcs 注册 compdef:根据可用 completer 选择 _python_argcomplete_colcon,在使用 _python_argcomplete 时构造 COMP_LINE/COMP_POINT 并委托,否则在词数组中注入 colcon build 并调用 completer,完成后恢复 shell 状态。

Sequence Diagram(s)

sequenceDiagram
participant DevEnv as "触发者"
participant Script as ".script/build-rmcs"
participant Tools as "系统 Clang/LLD 工具"
participant Colcon as "colcon / CMake / Ninja"
DevEnv->>Script: 运行 `build-rmcs`
Script->>Tools: 检查 `clang`, `clang++`, `llvm-ar`, `llvm-ranlib`, `ld.lld`
alt 工具齐全 且 RMCS_USE_GCC != ON
Script->>Tools: 导出 CC/CXX/AR/RANLIB,设置 `-fuse-ld=lld`
Script->>Colcon: 传递 cmake_toolchain_args / cmake_args / colcon_args
Script->>Colcon: 执行带参数的 `colcon build`(CLICOLOR_FORCE=1,清空 NINJA_STATUS)
else 否则
Script->>Colcon: 执行默认 `colcon build`
end
Colcon->>DevEnv: 返回构建结果
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • qzhhhi

Poem

🐇 我是小兔去编译,
🥕 换上 Clang 穿新衣,
🐾 LLD 把线牵一牵,
🌱 脚本轻唱参数诗,
🎉 二二版本乐无穷.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ Passed标题与变更集主要内容相关。PR通过参数化LLVM版本、增强LLVM工具链集成和构建系统改进来改进LLVM开发流程,这与标题"Build/improve llvm development"相符。
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch build/improve-llvm-development

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@creeper5820creeper5820 self-assigned this Feb 26, 2026
@creeper5820creeper5820 moved this from Todo to In progress in RMCSFeb 26, 2026
@creeper5820
creeper5820force-pushed the build/improve-llvm-development branch from 406cc0f to 009c0a7CompareFebruary 26, 2026 07:31
@creeper5820

Copy link
Copy Markdown
ContributorAuthor

@qzhhhi 老大,审代码

@qzhhhi

Copy link
Copy Markdown
Member

马上审,我还在修bug

@qzhhhiqzhhhi 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.

是不是干脆直接加 LLVM 全家桶进来好了
好像也没差几个了

Comment threadDockerfile
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} 100 && \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} 100 && \
update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-${LLVM_VERSION} 100 && \
update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-${LLVM_VERSION} 100 && \

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.

漏了 clang-tidy

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

下载的包还是显式写出来吧,这样可以看出我们用到了什么

…port
- Refactor build-rmcs to use bash arrays for colcon/cmake args
- Add complete LLVM toolchain detection (clang, llvm-ar, llvm-ranlib, lld)
- Pass absolute paths for CMAKE_AR and CMAKE_RANLIB via command -v
- Add RMCS_USE_GCC env var to allow fallback to GCC toolchain
- Install lld-22, llvm-ar-22, llvm-ranlib-22 in Dockerfile
- Register update-alternatives for lld, llvm-ar, llvm-ranlib
@creeper5820
creeper5820force-pushed the build/improve-llvm-development branch from 009c0a7 to a9e1cc5CompareFebruary 28, 2026 21:11

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.script/build-rmcs (1)

28-32: 考虑添加 CMAKE_MODULE_LINKER_FLAGS 以保持一致性

当前设置了 CMAKE_EXE_LINKER_FLAGSCMAKE_SHARED_LINKER_FLAGS 使用 lld,但 CMake 项目如果生成模块(.so 作为插件加载),可能需要 CMAKE_MODULE_LINKER_FLAGS

♻️ 可选修复
 cmake_toolchain_args=(
"-DCMAKE_AR=$(command -v llvm-ar)"
"-DCMAKE_RANLIB=$(command -v llvm-ranlib)"
-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld
-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld
+ -DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.script/build-rmcs around lines 28 - 32, 当前 cmake_args 设置只包含
CMAKE_EXE_LINKER_FLAGS 和 CMAKE_SHARED_LINKER_FLAGS 使用 lld,但没有设置
CMAKE_MODULE_LINKER_FLAGS,导致生成作为插件或模块(.so)时可能不会使用 lld;在构造 cmake_args 时为
CMAKE_MODULE_LINKER_FLAGS 添加与 CMAKE_EXE_LINKER_FLAGS/CMAKE_SHARED_LINKER_FLAGS
相同的 lld 链接器标志(例如 -fuse-ld=lld 或项目中已有的变量值),确保 cmake_args
里一并传递该变量以保持可执行、共享库与模块的一致链接行为(参见变量名
cmake_args、CMAKE_MODULE_LINKER_FLAGS、CMAKE_EXE_LINKER_FLAGS、CMAKE_SHARED_LINKER_FLAGS)。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.script/build-rmcs:
- Around line 28-32: 当前 cmake_args 设置只包含 CMAKE_EXE_LINKER_FLAGS 和
CMAKE_SHARED_LINKER_FLAGS 使用 lld,但没有设置
CMAKE_MODULE_LINKER_FLAGS,导致生成作为插件或模块(.so)时可能不会使用 lld;在构造 cmake_args 时为
CMAKE_MODULE_LINKER_FLAGS 添加与 CMAKE_EXE_LINKER_FLAGS/CMAKE_SHARED_LINKER_FLAGS
相同的 lld 链接器标志(例如 -fuse-ld=lld 或项目中已有的变量值),确保 cmake_args
里一并传递该变量以保持可执行、共享库与模块的一致链接行为(参见变量名
cmake_args、CMAKE_MODULE_LINKER_FLAGS、CMAKE_EXE_LINKER_FLAGS、CMAKE_SHARED_LINKER_FLAGS)。

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 009c0a7 and a9e1cc5.

📒 Files selected for processing (2)
  • .script/build-rmcs
  • Dockerfile

@creeper5820
creeper5820force-pushed the build/improve-llvm-development branch from 79c3ca6 to 7e46a60CompareMarch 1, 2026 17:39

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.script/complete/_build-rmcs:
- Around line 45-48: The delegated completion function's exit code is being lost
because "${_comp_func}" "$@" is followed by restoring words and CURRENT which
overwrite the shell's last status; modify the flow in the scope around the call
to _comp_func so you capture its exit status (e.g., status=$?) immediately after
invoking "${_comp_func}" "$@", then restore the original variables
words=("${_orig_words[@]}") and CURRENT=${_orig_current}, and finally return or
exit with the saved status (e.g., return $status) so the caller sees the correct
exit code; look for the call site of _comp_func and the restoring assignments to
_orig_words/_orig_current to apply this change.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9e1cc5 and 7e46a60.

📒 Files selected for processing (2)
  • .script/build-rmcs
  • .script/complete/_build-rmcs
🚧 Files skipped from review as they are similar to previous changes (1)
  • .script/build-rmcs

Comment thread.script/complete/_build-rmcs
@creeper5820
creeper5820 requested a review from qzhhhiMarch 3, 2026 06:29
@creeper5820
creeper5820force-pushed the build/improve-llvm-development branch from 7e46a60 to d122efcCompareMarch 3, 2026 07:17

@qzhhhiqzhhhi 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.

LGTM

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.script/build-rmcs:
- Around line 15-19: The pre-check loop that populates missing_tools (the for
loop iterating over clang clang++ llvm-ar llvm-ranlib ld.lld) omits ninja,
causing a false pass even though CMake later forces the Ninja generator; add
"ninja" to that tool list so the check includes it and will append to
missing_tools if not found.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e46a60 and d122efc.

📒 Files selected for processing (2)
  • .script/build-rmcs
  • .script/complete/_build-rmcs

Comment thread.script/build-rmcs Outdated
@creeper5820
creeper5820force-pushed the build/improve-llvm-development branch from d122efc to 1105c5dCompareMarch 3, 2026 07:29
@creeper5820
creeper5820 merged commit cdb0af7 into mainMar 3, 2026
1 check passed
@github-project-automationgithub-project-automationBot moved this from In progress to Done in RMCSMar 3, 2026
@creeper5820
creeper5820 deleted the build/improve-llvm-development branch March 3, 2026 07:37
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants

@creeper5820@qzhhhi