Skip to content

Clang tidy separate ci job #1801

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

bavulapati
Copy link
Contributor

@bavulapati bavulapati commented Jul 2, 2025

We use a CMAKE flag to decide if we want to run clang-tidy.
We can run the clang-tidy checks locally using the flag SOURCEMETA_CORE_CLANG_TIDY.

Tested this locally on Mac too. We just need to make sure we are using llvm instead of apple clang++.
Clang-tidy is friendly with clang++ but not with gcc or apple clang++.

This PR makes sure that it runs on a single machine, as we can't have clang used on all the machines.
Choosing ubuntu as its availability and cost on CI might be less(subject to correction).

We are using a single .clang-tidy configuration file. And the configuration file path is explicitly specified.

We are enabling the clang-tidy checks only for sourcemeta source targets. Disabling it for vendor, tests, etc.,

New CI Job installs the llvm package.

Using modernize-use-nodiscard check to demonstrate the proper clang-tidy working.

jviotti and others added 16 commits July 2, 2025 18:21
See: sourcemeta/blaze#429
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
@bavulapati bavulapati force-pushed the clang-tidy-separate-ci-job branch from 89ec116 to bdac96c Compare July 2, 2025 12:53
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
@bavulapati
Copy link
Contributor Author

@jviotti it's ready for your review.

@bavulapati
Copy link
Contributor Author

This supersedes #1754

@bavulapati
Copy link
Contributor Author

Also supersedes #1640

@bavulapati
Copy link
Contributor Author

Also supersedes #1702

@bavulapati
Copy link
Contributor Author

@jviotti PTAL

- uses: actions/checkout@v4
- run: cmake --version
- name: Install llvm
run: sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? I thought we tweaked the CMake scripts to conveniently download ClangTidy binaries when configuring?

OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
message(STATUS "Installed `clang-tidy` pre-built binary to ${CLANG_TIDY_BINARY_OUTPUT}")
function(sourcemeta_enable_clang_tidy)
find_program(CLANG_TIDY_BIN NAMES clang-tidy)
Copy link
Member

Choose a reason for hiding this comment

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

We could still download ClangTidy on demand and set CMAKE_CXX_CLANG_TIDY to the downloaded files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having clang-tidy without rest of the llvm is causing trouble

Copy link
Member

Choose a reason for hiding this comment

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

Also keep in mind that this find_program invocation succeeds even if clang-tidy was not found. Maybe worth putting REQUIRED? Otherwise you might end up setting a non-sense CMAKE_CXX_CLANG_TIDY?

Copy link
Member

Choose a reason for hiding this comment

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

Having clang-tidy without rest of the llvm is causing trouble

@bavulapati Even when installing clang-tidy from the Ubuntu packages? Because in theory Ubuntu consumes upstream LLVM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can try that

message(STATUS "Installed `clang-tidy` pre-built binary to ${CLANG_TIDY_BINARY_OUTPUT}")
function(sourcemeta_enable_clang_tidy)
find_program(CLANG_TIDY_BIN NAMES clang-tidy)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy;-header-filter=${CMAKE_CURRENT_SOURCE_DIR}/src/*" PARENT_SCOPE)
Copy link
Member

Choose a reason for hiding this comment

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

It's probably fine for all projects right now, but maybe worth taking the -header-filter as an option to the CMake function? At least so that it is generic enough out of the box for all possible uses?

endif()

sourcemeta_disable_clang_tidy()
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. Disabling looks a bit weird though. Now that I see this I wonder if it is possible to set CMAKE_CXX_CLANG_TIDY on a per-target level. If so, we could have a CLANG_TIDY option when declaring a library with sourcemeta_library (or executable with sourcemeta_executable). Then we don't have to worry about unsetting it, as we literally opt into it for specific things we are about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can do it at the target level

message(STATUS "Installed `clang-tidy` pre-built binary to ${CLANG_TIDY_BINARY_OUTPUT}")
function(sourcemeta_enable_clang_tidy)
find_program(CLANG_TIDY_BIN NAMES clang-tidy)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy;-header-filter=${CMAKE_CURRENT_SOURCE_DIR}/src/*" PARENT_SCOPE)
Copy link
Member

Choose a reason for hiding this comment

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

Also, does this work across compilers? i.e. can I enable this if I have ClangTidy available even if using MSVC? Or does it also require the Clang compiler? If so, it might be worth checking for this, so that nobody can accidentally enable it

@jviotti
Copy link
Member

jviotti commented Jul 3, 2025

We just need to make sure we are using llvm instead of apple clang++.Clang-tidy is friendly with clang++ but not with gcc or apple clang++.

It seems to work fine for me with AppleClang. Can you confirm it fails with non-Clang compilers? If so, we should have a check in the CMake function to error out if somebody tries to enable it with an incompatible compiler

@bavulapati
Copy link
Contributor Author

It works but misses the required context like std headers location etc.,

bavulapati and others added 5 commits July 4, 2025 16:00
Co-authored-by: Juan Cruz Viotti <jv@jviotti.com>
Signed-off-by: Balakrishna Avulapati <bavulapati@gmail.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
@bavulapati
Copy link
Contributor Author

@jviotti Addressed critical review comments.
Focusing on the critical parts and keeping the following list of optimisations, let me know if there's any other critical parts.

  1. passing header-filter as parameter to cmake function
  2. enabling clang-tidy at target level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants