Skip to content

Add some util for neovim developing, and switch default compile toolchain#47

Merged
creeper5820 merged 2 commits intomainfrom
feat/new-toolchain
Feb 18, 2026
Merged

Add some util for neovim developing, and switch default compile toolchain#47
creeper5820 merged 2 commits intomainfrom
feat/new-toolchain

Conversation

@creeper5820
Copy link
Contributor

@creeper5820 creeper5820 commented Feb 14, 2026

Switch toolchain to clang with Ninja for supporting cxx module

摘要

此PR切换了构建系统的默认工具链为 Clang + Ninja,并添加了 Neovim 开发相关的实用工具脚本。

主要变更

构建系统优化

  • 构建脚本升级 (.script/build-rmcs):
    • 修复了 Shebang 格式规范(#! /bin/bash#!/bin/bash
    • 添加了 CMake 二进制文件检查,若存在则将 /opt/cmake/bin 加入 PATH
    • 实现了编译器自动选择:当系统中存在 clangclang++ 时,自动设置 CC=clangCXX=clang++
    • 更新了构建命令以支持 Ninja 生成器:colcon build 现在使用 --cmake-args -G Ninja
    • 增强了错误处理:工作目录切换失败时立即退出

Neovim 开发工具

  • 新增容器管理脚本 (.script/host/rmcs):
    • 提供 rmcs_zsh 命令:启动 Docker 容器并打开 zsh shell
    • 提供 rmcs_nvim 命令:启动容器内的无头 Neovim 实例,自动检测可用端口,通过 Neovide 客户端连接
    • 支持项目目录参数化配置
    • 内置容器生命周期管理和网络连接验证

配置调整

  • 环境变量重构 (.env):移除 HOST_NVIM_DIR 变量
  • Docker 构成更新 (docker-compose.yml):修改卷挂载策略,从指定的环境变量路径改为用户主目录下的 .config 目录(~/.config/:${CONTAINER_HOME}/.config/

影响范围

此变更影响开发工作流程,特别是本地开发环境的构建配置和 Neovim 集成体验。新增的脚本提供了便捷的容器化开发环境管理方案。

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

概览

该改动调整开发环境配置,删除了环境变量中的 Neovim 目录,更新了 Docker Compose 挂载点,优化了构建脚本,并添加了新的容器管理脚本用于快速启动开发环境和 Neovim 编辑器。

变更

文件/文件组 摘要
环境配置
.env, docker-compose.yml
移除 HOST_NVIM_DIR 环境变量,将 Docker 卷挂载从环境变量路径改为用户主目录路径 ~/.config/
构建脚本改进
.script/build-rmcs
修复 Shebang 格式,添加 CMake 二进制检查和路径配置,实现编译器自动选择(Clang),更新构建命令以使用 Ninja 生成器,增强目录切换的错误处理。
容器管理工具
.script/host/rmcs
新增 Bash 脚本,提供 rmcs_zshrmcs_nvim 两个主要命令,支持快速启动开发容器的 Zsh 环境或 Neovim/Neovide 编辑环境,包含端口自动探测和超时管理机制。

序列图

sequenceDiagram
    participant User
    participant rmcs_nvim as rmcs (nvim)
    participant Docker as Docker Compose
    participant Container
    participant Neovim
    participant Neovide

    User->>rmcs_nvim: 执行 rmcs nvim 命令
    rmcs_nvim->>Docker: 启动容器服务
    Docker->>Container: 容器启动
    rmcs_nvim->>rmcs_nvim: 从基础端口开始扫描可用端口
    loop 端口探测
        rmcs_nvim->>Container: 尝试连接端口
    end
    rmcs_nvim->>Container: 在可用端口启动 Neovim (headless)
    Container->>Neovim: Neovim 启动并监听端口
    rmcs_nvim->>rmcs_nvim: 等待端口就绪 (最长10秒)
    rmcs_nvim->>Neovide: 连接到 Neovim 端口
    Neovide->>User: 显示 Neovim UI
Loading

代码审查工作量评估

🎯 3 (中等) | ⏱️ ~20 分钟

建议审查人员

  • qzhhhi

🐰 一条兔兔来报喜,
环境配置更清晰,
构建脚本添新功,
容器管理显身手,
Neovim 编辑任你驰!✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确地反映了主要变更:切换编译工具链到clang/Ninja,以及添加Neovim开发工具。
Docstring Coverage ✅ Passed No 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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/new-toolchain

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.

Copy link

@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: 2

🤖 Fix all issues with AI agents
In @.script/launch/rmcs:
- Around line 35-38: 当前从 NVIM_PORT 起循环探测端口(在 while nc -z "$NVIM_HOST" "$port"
... 中)没有上限,会在连续被占用时无限循环;为修复,添加一个上限检查(例如 MAX_PORT 或 MAX_ATTEMPTS)并在每次循环判断 port <=
MAX_PORT 或尝试次数未超出,若超出则打印错误(包括试图的起始端口和最大尝试数)并退出非零;修改涉及的标识符为 NVIM_PORT / NVIM_HOST
/ port / while nc -z 循环及相应的退出处理逻辑。

In `@docker-compose.yml`:
- Line 9: The docker-compose volume currently mounts the entire host ~/.config/
into the container via the line "~/.config/:${CONTAINER_HOME}/.config/:bind",
which is too broad and exposes sensitive host configs; replace that broad mount
with explicit per-app mounts (e.g., use the existing ${HOST_NVIM_DIR} for Neovim
-> "${HOST_NVIM_DIR}:${CONTAINER_HOME}/.config/nvim:bind") and add other
specific mounts only as needed (for example lazygit config) instead of mounting
~/.config/ wholesale; update the volume entry that contains
"~/.config/:${CONTAINER_HOME}/.config/:bind" to the targeted mounts.
🧹 Nitpick comments (3)
.script/build-rmcs (1)

1-16: 整体改进合理,脚本更加健壮。 👍

路径引用、条件编译器检测、Ninja 生成器切换都处理得当。

一个小建议:CCCXX 是独立检测的,理论上可能出现只有其中一个可用的情况,导致混合编译器配置。可以考虑将两者作为一组来设置:

♻️ 可选改进
-command -v clang &>/dev/null &&
-    export CC=clang
-
-command -v clang++ &>/dev/null &&
-    export CXX=clang++
+if command -v clang &>/dev/null && command -v clang++ &>/dev/null; then
+    export CC=clang
+    export CXX=clang++
+fi
.script/launch/rmcs (2)

41-42: Neovim headless 监听地址建议使用 0.0.0.0 或确认 host 网络模式。

当前脚本在容器内让 Neovim 监听 localhost:$port。这依赖于 docker-compose.ymlnetwork_mode: host 的配置才能从宿主机连接。如果将来网络模式改变,宿主机上的 neovide 将无法连接到容器内的 Neovim。建议在脚本中添加注释说明此依赖关系,或考虑监听 0.0.0.0


18-23: rmcs_zsh 在退出 zsh 后容器仍在后台运行。

docker compose up -d 启动容器后,用户退出 zsh 后容器不会自动停止。如果这是有意为之(允许多个会话连接),建议在帮助信息中说明如何手动停止容器。

@creeper5820 creeper5820 changed the title Add some util for neovim developing, and switch default compile Add some util for neovim developing, and switch default compile toolchain Feb 14, 2026
@creeper5820 creeper5820 requested a review from qzhhhi February 14, 2026 08:38
@creeper5820
Copy link
Contributor Author

@qzhhhi REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW

Copy link
Member

@qzhhhi qzhhhi left a comment

Choose a reason for hiding this comment

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

neovim 的相关代码和切换默认工具链不应该在单个 commit 里一起提交。
拆成两个 commit。

另:用一下约定式提交吧,可以参考 librmcs

Copy link
Member

@qzhhhi qzhhhi left a comment

Choose a reason for hiding this comment

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

neovim 的相关代码和切换默认工具链不应该在单个 commit 里一起提交。
拆成两个 commit。 <<< 这个还没做

另外,.script/launch/rmcs 这个文件的位置很尴尬,对于使用者来说,launch-rmcs 和 launch/rmcs 是两个看不出区别的指令。

Copy link

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

🧹 Nitpick comments (4)
.script/host/rmcs (2)

18-23: rmcs_zsh 未指定 -u 用户,与 rmcs_nvim 行为不一致。

rmcs_nvim(Line 41)使用了 -u "$DEVELOPER_NAME"ubuntu 用户执行命令,但 rmcs_zsh 中的 docker compose exec 没有指定用户,将以容器默认用户(通常是 root)进入 shell。如果这是有意为之可以忽略,否则建议统一:

♻️ 建议修改
 function rmcs_zsh() {
     local service="$1"
     echo "Starting and entering container..."
     docker compose up -d
-    docker compose exec "$service" zsh
+    docker compose exec -u "$DEVELOPER_NAME" "$service" zsh
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.script/host/rmcs around lines 18 - 23, The rmcs_zsh function starts and
enters the container without specifying a user, unlike rmcs_nvim which uses -u
"$DEVELOPER_NAME"; update rmcs_zsh to pass -u "$DEVELOPER_NAME" to docker
compose exec so the shell runs as the same developer user (reference functions
rmcs_zsh and rmcs_nvim and the DEVELOPER_NAME variable).

63-78: main 函数参数解析和目录校验逻辑清晰。

通过 -d 判断首参是否为目录来区分路径参数和命令参数,并校验 docker-compose.yml 存在性,逻辑合理。

不过 Line 76 只检查了 docker-compose.yml,如果项目使用的是 compose.yaml(Docker Compose V2 同样支持的文件名),则会误报。视项目实际情况可忽略。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.script/host/rmcs around lines 63 - 78, The script's main function currently
only checks for "docker-compose.yml" which fails for projects using alternate
Compose filenames; update the existence check in main to consider all common
Compose filenames (e.g., "docker-compose.yml", "docker-compose.yaml",
"compose.yml", "compose.yaml") and proceed if any one exists, otherwise print
the same error and exit; adjust the test referencing docker-compose.yml so
functions/classes/logic around main and the directory validation use the
combined check.
.script/build-rmcs (2)

16-16: "$@" 放在 --cmake-args 之前,用户传入的 cmake 参数可能被拆分。

当前 "$@" 位于 --cmake-args 前面。如果用户调用时传入 --cmake-args -DFOO=bar,colcon 会将其视为独立的一组 cmake 参数,与脚本末尾的 -G Ninja 分开累积,行为上可以工作。但如果用户期望直接追加额外参数到 --cmake-args 后面(如 -DCMAKE_BUILD_TYPE=Release),则需要在调用时显式加上 --cmake-args 前缀。

考虑将 "$@" 移到命令末尾以获得更直观的行为:

♻️ 建议修改
-colcon build --symlink-install --merge-install "$@" --cmake-args -G Ninja
+colcon build --symlink-install --merge-install --cmake-args -G Ninja "$@"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.script/build-rmcs at line 16, The colcon invocation puts "$@" before
--cmake-args which prevents user-supplied CMake flags from being appended to the
script's --cmake-args list; update the command in the .script/build-rmcs file
(the colcon build invocation) to place "$@" at the end of the argument list so
that user-provided flags are appended after --cmake-args -G Ninja (preserve
quoting of "$@" when moving it).

10-14: CCCXX 独立检测可能导致编译器不匹配。

如果系统中只安装了 clang 而没有 clang++(或反之),会导致 C 和 C++ 编译器不配对(例如 CC=clang + CXX=g++),可能引发难以排查的构建问题。建议将两者作为一组进行检测:

♻️ 建议修改
-command -v clang &>/dev/null &&
-    export CC=clang
-
-command -v clang++ &>/dev/null &&
-    export CXX=clang++
+if command -v clang &>/dev/null && command -v clang++ &>/dev/null; then
+    export CC=clang
+    export CXX=clang++
+fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.script/build-rmcs around lines 10 - 14, The script currently checks clang
and clang++ independently which can leave CC and CXX mismatched; update the
detection so you probe pairs and set both together: if both `clang` and
`clang++` exist, export `CC=clang` and `CXX=clang++`; else if both `gcc` and
`g++` exist, export `CC=gcc` and `CXX=g++`; otherwise fall back to a single-tool
check that warns or exits. Modify the logic around the `CC`/`CXX` exports in the
existing block that currently calls `command -v clang` and `command -v clang++`
so the pairwise check replaces the independent checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In @.script/host/rmcs:
- Around line 35-38: 循环使用 nc -z 检查端口的 while loop 没有上限保护,可能导致无限循环; add a maximum
guard by introducing a MAX_PORT (or MAX_ATTEMPTS) and an attempts counter, then
change the loop condition to while nc -z "$NVIM_HOST" "$port" 2>/dev/null && [
"$port" -le "$MAX_PORT" ] (or increment attempts and check attempts -lt
MAX_ATTEMPTS), and when the limit is reached emit a clear error message and exit
non‑zero instead of continuing; update references to port, the while loop, and
the exit path accordingly.

---

Nitpick comments:
In @.script/build-rmcs:
- Line 16: The colcon invocation puts "$@" before --cmake-args which prevents
user-supplied CMake flags from being appended to the script's --cmake-args list;
update the command in the .script/build-rmcs file (the colcon build invocation)
to place "$@" at the end of the argument list so that user-provided flags are
appended after --cmake-args -G Ninja (preserve quoting of "$@" when moving it).
- Around line 10-14: The script currently checks clang and clang++ independently
which can leave CC and CXX mismatched; update the detection so you probe pairs
and set both together: if both `clang` and `clang++` exist, export `CC=clang`
and `CXX=clang++`; else if both `gcc` and `g++` exist, export `CC=gcc` and
`CXX=g++`; otherwise fall back to a single-tool check that warns or exits.
Modify the logic around the `CC`/`CXX` exports in the existing block that
currently calls `command -v clang` and `command -v clang++` so the pairwise
check replaces the independent checks.

In @.script/host/rmcs:
- Around line 18-23: The rmcs_zsh function starts and enters the container
without specifying a user, unlike rmcs_nvim which uses -u "$DEVELOPER_NAME";
update rmcs_zsh to pass -u "$DEVELOPER_NAME" to docker compose exec so the shell
runs as the same developer user (reference functions rmcs_zsh and rmcs_nvim and
the DEVELOPER_NAME variable).
- Around line 63-78: The script's main function currently only checks for
"docker-compose.yml" which fails for projects using alternate Compose filenames;
update the existence check in main to consider all common Compose filenames
(e.g., "docker-compose.yml", "docker-compose.yaml", "compose.yml",
"compose.yaml") and proceed if any one exists, otherwise print the same error
and exit; adjust the test referencing docker-compose.yml so
functions/classes/logic around main and the directory validation use the
combined check.

Copy link
Member

@qzhhhi qzhhhi left a comment

Choose a reason for hiding this comment

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

LGTM

@creeper5820 creeper5820 merged commit 5663ef2 into main Feb 18, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Todo to Done in RMCS Feb 18, 2026
@creeper5820 creeper5820 deleted the feat/new-toolchain branch February 18, 2026 12:04
Sign up for free to 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

Comments