Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,235
    • Issues 3,235
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 14
    • Merge Requests 14
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #21092

Closed
Open
Opened Aug 14, 2020 by Christian Ledergerber@ledergec

Speeding up builds with clang-tidy, clang-analyzer and iwyu

for our builds currently clang-tidy is currently the limiting factor in terms of speed.

There is one utility out there which tries to cache the output of clang-tidy, however it seems to be stale: https://github.com/ejfitzgerald/clang-tidy-cache

Yet, we have the impression that our case is much simpler:

We use clang-tidy with the warnings-as errors flag. Hence, the compiler is only ever started if there are no clang-tidy warnings. IMHO this implies that there can only be a ccache hit, if clang-tidy generated no output and hence the output of clang-tidy does not need to be cached. This assumes that cmake does not launch clang-tidy and clang in parallel but only launches clang/the compiler if clang-tidy passed successfully.

The overall problem was already discussed with Joel Rosdahl from ccache in this thread: https://www.mail-archive.com/ccache@lists.samba.org/msg01496.html

For a good implementation the following should work for compiling a given Class.o file:

  1. Create a Class.clang-tidy file next to Class.o using clang-tidy --dump-config (available as of which version?)
  2. Add Class.clang-tidy to configuration of extra_files_to_hash of ccache using the command line syntax: --add-extra-files=Class.clang-tidy
  3. try to use ccache directly, providing the --fail-on-cache-miss flag which causes ccache to exit if there is a cache miss
  4. if ccache failed: 4.1. launch clang-tidy 4.2. launch clang

The user should be able to select whether clang-tidy is run on a cash miss or not by setting: CMAKE_CLANG_TIDY_ON_CCACHE_HIT=OFF which by default is ON for backwards compatibility.

This approach could later be applied to any linting / static analysis tool for C++:

  • use the tool with warnings-as-errors
  • add the configuration of the tool (and the tool itself??) to the ccache extra files
  • run it only if ccache has no hit
  • run the compiler only if all static analysis passed and cache the result using ccache

Limitations / problems:

  • This will only work if the proper version of ccache is installed, since the two necessary flags in ccache do yet need to be implemented.
  • The user could in theory manually run ccache --add-extra-files=Class.clang-tidy which will circumnavigate the mechanism. However this seems hard to get right even if you really want to do so.

What do you think of this approach? Anything which was missed / needs to be considered?

Edited Aug 19, 2020 by Christian Ledergerber
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: cmake/cmake#21092