From e0cbf1ccccb3efcfe131acf346464cff55422dfa Mon Sep 17 00:00:00 2001 From: creeper5820 Date: Wed, 25 Feb 2026 01:19:46 +0800 Subject: [PATCH 1/3] build: Tune build-rmcs logging behavior --- .script/build-rmcs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.script/build-rmcs b/.script/build-rmcs index 68f90d730..1519d7e1b 100755 --- a/.script/build-rmcs +++ b/.script/build-rmcs @@ -13,4 +13,7 @@ command -v clang &>/dev/null && command -v clang++ &>/dev/null && export CXX=clang++ -colcon build --symlink-install --merge-install "$@" --cmake-args -G Ninja +colcon_args="--event-handlers console_cohesion+ --symlink-install --merge-install" +cmake_args="-G Ninja -DCMAKE_MESSAGE_LOG_LEVEL=ERROR" + +CLICOLOR_FORCE=1 NINJA_STATUS="" colcon build ${colcon_args} "$@" --cmake-args ${cmake_args} From a9e1cc57a558617fedad780d8d01997c4c628c1b Mon Sep 17 00:00:00 2001 From: creeper5820 Date: Thu, 26 Feb 2026 11:35:40 +0800 Subject: [PATCH 2/3] build: Improve LLVM toolchain setup with full linker and archiver support - 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 --- .script/build-rmcs | 25 +++++++++++++++++++------ Dockerfile | 21 ++++++++++++++------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/.script/build-rmcs b/.script/build-rmcs index 1519d7e1b..3f9e2a7f8 100755 --- a/.script/build-rmcs +++ b/.script/build-rmcs @@ -7,13 +7,26 @@ cd "${RMCS_PATH}"/rmcs_ws || exit [[ -x /opt/cmake/bin/cmake ]] && export PATH="/opt/cmake/bin:$PATH" -command -v clang &>/dev/null && - export CC=clang +cmake_toolchain_args=() -command -v clang++ &>/dev/null && +if [[ "${RMCS_USE_GCC}" != "ON" ]] && + command -v clang &>/dev/null && + command -v clang++ &>/dev/null && + command -v llvm-ar &>/dev/null && + command -v llvm-ranlib &>/dev/null && + command -v ld.lld &>/dev/null; then + export CC=clang export CXX=clang++ + 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 + ) +fi -colcon_args="--event-handlers console_cohesion+ --symlink-install --merge-install" -cmake_args="-G Ninja -DCMAKE_MESSAGE_LOG_LEVEL=ERROR" +colcon_args=(--event-handlers console_cohesion+ --symlink-install --merge-install) +cmake_args=(-G Ninja -DCMAKE_MESSAGE_LOG_LEVEL=ERROR "${cmake_toolchain_args[@]}") -CLICOLOR_FORCE=1 NINJA_STATUS="" colcon build ${colcon_args} "$@" --cmake-args ${cmake_args} +CLICOLOR_FORCE=1 NINJA_STATUS="" \ + colcon build "${colcon_args[@]}" "$@" --cmake-args "${cmake_args[@]}" diff --git a/Dockerfile b/Dockerfile index 3ea8bddf7..4d5c1f848 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,17 +88,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ rm -rf /var/lib/apt/lists/* /tmp/* # Install latest stable llvm-toolchain +ARG LLVM_VERSION=22 RUN mkdir -p /etc/apt/keyrings && \ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | gpg -o /etc/apt/keyrings/llvm-snapshot.gpg --dearmor && \ - echo "deb [signed-by=/etc/apt/keyrings/llvm-snapshot.gpg] https://mirrors.tuna.tsinghua.edu.cn/llvm-apt/noble/ llvm-toolchain-noble-22 main" \ + echo "deb [signed-by=/etc/apt/keyrings/llvm-snapshot.gpg] https://mirrors.tuna.tsinghua.edu.cn/llvm-apt/noble/ llvm-toolchain-noble-${LLVM_VERSION} main" \ | tee /etc/apt/sources.list.d/llvm.list && \ apt-get update && \ - apt-get install -y --no-install-recommends clang-22 clangd-22 clang-format-22 lldb-22 && \ - update-alternatives --install /usr/bin/clang clang /usr/bin/clang-22 100 && \ - update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-22 100 && \ - update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-22 100 && \ - update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-22 100 && \ - update-alternatives --install /usr/bin/lldb lldb /usr/bin/lldb-22 100 && \ + apt-get install -y --no-install-recommends \ + 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 --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 && \ + update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${LLVM_VERSION} 100 && \ + update-alternatives --install /usr/bin/lldb lldb /usr/bin/lldb-${LLVM_VERSION} 100 && \ + update-alternatives --install /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-${LLVM_VERSION} 100 && \ + update-alternatives --install /usr/bin/llvm-ranlib llvm-ranlib /usr/bin/llvm-ranlib-${LLVM_VERSION} 100 && \ + update-alternatives --install /usr/bin/ld.lld ld.lld /usr/bin/ld.lld-${LLVM_VERSION} 100 && \ apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* # Generate/load ssh key and setup unison From 1105c5d586522d9ab109336a773509995ff0d8bb Mon Sep 17 00:00:00 2001 From: creeper5820 Date: Mon, 2 Mar 2026 01:38:23 +0800 Subject: [PATCH 3/3] build: Enforce LLVM toolchain checks and add zsh completion --- .script/build-rmcs | 45 ++++++++++++++++++++++--------- .script/complete/_build-rmcs | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 .script/complete/_build-rmcs diff --git a/.script/build-rmcs b/.script/build-rmcs index 3f9e2a7f8..9c1801a17 100755 --- a/.script/build-rmcs +++ b/.script/build-rmcs @@ -8,25 +8,46 @@ cd "${RMCS_PATH}"/rmcs_ws || exit export PATH="/opt/cmake/bin:$PATH" cmake_toolchain_args=() +event_handlers_args=() -if [[ "${RMCS_USE_GCC}" != "ON" ]] && - command -v clang &>/dev/null && - command -v clang++ &>/dev/null && - command -v llvm-ar &>/dev/null && - command -v llvm-ranlib &>/dev/null && - command -v ld.lld &>/dev/null; then +if [[ "${RMCS_USE_LLVM}" == "ON" ]]; then + missing_tools=() + for tool in clang clang++ llvm-ar llvm-ranlib ld.lld ninja; do + if ! command -v "${tool}" &>/dev/null; then + missing_tools+=("${tool}") + fi + done + + if ((${#missing_tools[@]} > 0)); then + echo "> ERROR: LLVM toolchain is required when RMCS_USE_GCC is not ON." + echo "> Missing tools: ${missing_tools[*]}" + echo "> Install the missing tools, or set RMCS_USE_GCC=ON to build with GCC." + exit 1 + fi + + echo "> Compiling With LLVM ToolChain" export CC=clang export CXX=clang++ 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 + "-G Ninja" + "-D CMAKE_MESSAGE_LOG_LEVEL=ERROR" + "-D CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld" + "-D CMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld" + "-D CMAKE_AR=$(command -v llvm-ar)" + "-D CMAKE_RANLIB=$(command -v llvm-ranlib)" + ) + event_handlers_args=( + --event-handlers console_cohesion+ ) fi -colcon_args=(--event-handlers console_cohesion+ --symlink-install --merge-install) -cmake_args=(-G Ninja -DCMAKE_MESSAGE_LOG_LEVEL=ERROR "${cmake_toolchain_args[@]}") +colcon_args=( + --symlink-install --merge-install + "${event_handlers_args[@]}" +) +cmake_args=( + "${cmake_toolchain_args[@]}" +) CLICOLOR_FORCE=1 NINJA_STATUS="" \ colcon build "${colcon_args[@]}" "$@" --cmake-args "${cmake_args[@]}" diff --git a/.script/complete/_build-rmcs b/.script/complete/_build-rmcs new file mode 100644 index 000000000..1b5b5894b --- /dev/null +++ b/.script/complete/_build-rmcs @@ -0,0 +1,51 @@ +#compdef build-rmcs + +local _comp_func="${_comps[colcon]}" + +if [[ -z "${_comp_func}" ]]; then + if (( $+functions[_python_argcomplete] )); then + _comp_func="_python_argcomplete" + elif (( $+functions[_colcon] )); then + _comp_func="_colcon" + else + _message "colcon completion not found. Please source colcon completion setup." + return 1 + fi +fi + +if [[ "${_comp_func}" == "_python_argcomplete" ]]; then + local IFS=$'\013' + local -a completions + local _comp_line _comp_point + + _comp_line="colcon build${BUFFER#build-rmcs}" + _comp_point=$((CURSOR + 2)) + + completions=($(IFS="$IFS" \ + COMP_LINE="${_comp_line}" \ + COMP_POINT="${_comp_point}" \ + _ARGCOMPLETE=1 \ + _ARGCOMPLETE_SHELL="zsh" \ + _ARGCOMPLETE_SUPPRESS_SPACE=1 \ + __python_argcomplete_run colcon)) + + _describe colcon completions -o nosort + return 0 +fi + +local -a _orig_words +local _orig_current + +_orig_words=("${words[@]}") +_orig_current=${CURRENT} + +words=(colcon build "${_orig_words[@]:1}") +CURRENT=$((_orig_current + 1)) + +"${_comp_func}" "$@" +local status=$? + +words=("${_orig_words[@]}") +CURRENT=${_orig_current} + +return $status