ros-tooling/setup-ros

Feature request: option to specify clang version to install

Opened this issue · 2 comments

Description

The setup-ros2 action installs the default version of clang, which is very helpful, but we have some software that requires a newer version of clang, so it would be nice if we could pass the major version of clang as a parameter to the setup-ros2 action.

Related Issues

N/A

Completion Criteria

Expose an parameter that takes an integer and attempts to install clang packages that match that major version and calls update-alternatives to ensure that those versions are called with unversioned commands like clang and clang++.

Implementation Notes / Suggestions

The bash code we currently use for this is given below:

#######################################
# Installs clang suite packages.
# Arguments:
#   Version of the clang suite package.
# Returns:
#   0 if no error was detected, non-zero otherwise.
#######################################
function install_clang_suite() {
  local version=$1

  apt install -y \
              clang-${version} \
              lldb-${version} \
              lld-${version} \
              clang-format-${version} \
              clang-tidy-${version} \
              libc++-${version}-dev \
              libc++abi-${version}-dev
}

#######################################
# Setups alternatives for clang suite.
# Arguments:
#   Version of the clang suite package.
# Returns:
#   0 if no error was detected, 2 otherwise.
#######################################
function update_clang_suite_alternatives() {
  local version=$1
  local priority=$2

  update-alternatives \
    --install /usr/bin/clang                 clang                 /usr/bin/clang-${version}  ${priority}\
    --slave   /usr/bin/clang++               clang++               /usr/bin/clang++-${version}  \
    --slave   /usr/bin/asan_symbolize        asan_symbolize        /usr/bin/asan_symbolize-${version} \
    --slave   /usr/bin/c-index-test          c-index-test          /usr/bin/c-index-test-${version} \
    --slave   /usr/bin/clang-check           clang-check           /usr/bin/clang-check-${version} \
    --slave   /usr/bin/clang-cl              clang-cl              /usr/bin/clang-cl-${version} \
    --slave   /usr/bin/clang-cpp             clang-cpp             /usr/bin/clang-cpp-${version} \
    --slave   /usr/bin/clang-format          clang-format          /usr/bin/clang-format-${version} \
    --slave   /usr/bin/clang-format-diff     clang-format-diff     /usr/bin/clang-format-diff-${version} \
    --slave   /usr/bin/clang-import-test     clang-import-test     /usr/bin/clang-import-test-${version} \
    --slave   /usr/bin/clang-include-fixer   clang-include-fixer   /usr/bin/clang-include-fixer-${version} \
    --slave   /usr/bin/clang-offload-bundler clang-offload-bundler /usr/bin/clang-offload-bundler-${version} \
    --slave   /usr/bin/clang-query           clang-query           /usr/bin/clang-query-${version} \
    --slave   /usr/bin/clang-rename          clang-rename          /usr/bin/clang-rename-${version} \
    --slave   /usr/bin/clang-reorder-fields  clang-reorder-fields  /usr/bin/clang-reorder-fields-${version} \
    --slave   /usr/bin/clang-tidy            clang-tidy            /usr/bin/clang-tidy-${version} \
    --slave   /usr/bin/lldb                  lldb                  /usr/bin/lldb-${version} \
    --slave   /usr/bin/lldb-server           lldb-server           /usr/bin/lldb-server-${version}
}
# example for using these bash functions to install clang8:
CLANG_SUITE_VERSION=8
CLANG_SUITE_ALTERNATIVE_PRIORITY=10
apt update
install_clang_suite ${CLANG_SUITE_VERSION}
update_clang_suite_alternatives ${CLANG_SUITE_VERSION} ${CLANG_SUITE_ALTERNATIVE_PRIORITY}

Testing Notes / Suggestions

Run the action with different values of the clang version and evaluate the output of clang --version, clang++ --version, etc. to confirm that the correct version has been installed.

on a related note, how do I force action-ros-ci to use Clang as a default compiler over gcc?

on a related note, how do I force action-ros-ci to use Clang as a default compiler over gcc?

I've never tried, but you should be able to do that with the clang-libcxx mixin (https://github.com/colcon/colcon-mixin-repository/blob/1ddb69bedfd1f04c2f000e95452f7c24a4d6176b/clang-libcxx.mixin), e.g. using the colcon-defaults input:

        colcon-defaults: |
          {
            "build": {
              "mixin": [
                  "clang-libcxx"
              ]
            }
          }