简体   繁体   English

是否可以使用 ccache 或类似方法来加速 clang-tidy?

[英]Is it possible to accelerate clang-tidy using ccache or similar?

Since employing ccache on our CI server, we find that the bottleneck in terms of build time is now our static analysis pass, that uses clang-tidy , among other tools.由于在我们的 CI 服务器上使用ccache ,我们发现构建时间方面的瓶颈现在是我们的静态分析通道,它使用了clang-tidy等工具。 Does anyone know of a way to accelerate clang-tidy in a similar way to how ccache does so with a regular compiler?有没有人知道一种以类似于ccache使用常规编译器的方式加速clang-tidy的方法?

clang-tidy-cache虽然我不知道它是如何与 ccache 一起工作的。

I found another important detail here:我在这里发现了另一个重要细节:

https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1791/diffs https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1791/diffs

which is used here:在这里使用:

https://reviews.bitcoinabc.org/D5150?id=15995 https://reviews.bitcoinabc.org/D5150?id=15995

So in order to be able to cache the output of the compiler when integrating clang-tidy using the : set(CMAKE_CXX_CLANG_TIDY ...因此,为了能够在使用以下命令集成 clang-tidy 时缓存编译器的输出: set(CMAKE_CXX_CLANG_TIDY ...

method you need to use the COMPILER_LAUNCHER method to configure ccache方法需要使用COMPILER_LAUNCHER方法来配置ccache

find_program(CCACHE ccache)
if(CCACHE)
    set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
    set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
endif(CCACHE)

and NOT the launcher rule method:而不是启动器规则方法:

find_program(CCACHE ccache)
if(CCACHE)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
endif(CCACHE)

Finally, I have found a solution for this: it's switching the build system to bazel .最后,我找到了一个解决方案:它将构建系统切换到bazel bazel is a build system which is very generic and defines an action graph. bazel 是一个非常通用的构建系统,它定义了一个动作图。 Essentially every action has a set of inputs and outputs.基本上每个动作都有一组输入和输出。 Based on the inputs the outputs can be cached.基于输入,可以缓存输出。 Hence, bazel solves the problem at it's root.因此,bazel 从根本上解决了问题。

The necessary rules for integrating clang-tidy in a cachable way can be found here: https://github.com/erenon/bazel_clang_tidy可以在此处找到以可缓存方式集成 clang-tidy 的必要规则: https : //github.com/erenon/bazel_clang_tidy

In order to make use of caching you need to setup a remote cache .为了使用缓存,您需要设置一个远程缓存 This can be done using a docker-compose script.这可以使用 docker-compose 脚本来完成。 The necessary docker container already exists.必要的 docker 容器已经存在。 The command to get it running can be found here: https://github.com/buchgr/bazel-remote/可以在这里找到让它运行的命令: https : //github.com/buchgr/bazel-remote/

Finally, bazel also solves the problem of caching the result of the linking phase.最后,bazel 还解决了链接阶段结果的缓存问题。

Not only that but bazel also allows building other languages like java.不仅如此,bazel 还允许构建其他语言,如 java。 Hence, in complex projects it allows to replace all other build system with a single one.因此,在复杂的项目中,它允许用一个单独的构建系统替换所有其他构建系统。

Finally, bazel also allows parallelizing your build on a cluster.最后,bazel 还允许在集群上并行构建。

Last but not least you can define several platforms and toolchains .最后但并非最不重要的是,您可以定义多个平台工具链 All in all this allows to do cross-platform builds.总而言之,这允许进行跨平台构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM