Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: option to specify clang version to install #276

Open
scpeters opened this issue Sep 18, 2020 · 2 comments
Open

Feature request: option to specify clang version to install #276

scpeters opened this issue Sep 18, 2020 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@scpeters
Copy link

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.

@scpeters scpeters added the enhancement New feature or request label Sep 18, 2020
@emersonknapp emersonknapp added enhancement New feature or request and removed enhancement New feature or request labels Nov 6, 2020
@Karsten1987
Copy link

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

@christophebedard
Copy link
Member

christophebedard commented Apr 27, 2021

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"
              ]
            }
          }

@emersonknapp emersonknapp added the help wanted Extra attention is needed label Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants