All Projects → erenon → bazel_clang_tidy

erenon / bazel_clang_tidy

Licence: MIT license
Run clang-tidy on Bazel C++ targets directly, efficiently, with caching enabled

Programming Languages

Starlark
911 projects
shell
77523 projects
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to bazel clang tidy

bazel-compile-commands-extractor
Goal: Enable awesome tooling for Bazel users of the C language family.
Stars: ✭ 295 (+368.25%)
Mutual labels:  bazel, clang-tidy
Bazel bin
Bazel's pre-built binaries for armv7l / aarch64 / x86_64.
Stars: ✭ 23 (-63.49%)
Mutual labels:  bazel
Rules apple
Bazel rules to build apps for Apple platforms.
Stars: ✭ 217 (+244.44%)
Mutual labels:  bazel
rules openapi
🍃 bazel rules for generating code from openapi specifications
Stars: ✭ 49 (-22.22%)
Mutual labels:  bazel
Rules python
Experimental Bazel Python Rules
Stars: ✭ 233 (+269.84%)
Mutual labels:  bazel
bazel-stack-vscode
VSCode Extension for Bazel
Stars: ✭ 50 (-20.63%)
Mutual labels:  bazel
Trunk
Make bazel an out of box solution for C++/Java developers
Stars: ✭ 203 (+222.22%)
Mutual labels:  bazel
android-projects
Android benchmark projects for Bazel and Gradle
Stars: ✭ 29 (-53.97%)
Mutual labels:  bazel
rules proto grpc
Bazel rules for building Protobuf and gRPC code and libraries from proto_library targets
Stars: ✭ 201 (+219.05%)
Mutual labels:  bazel
Bazel Watcher
Tools for building Bazel targets when source files change.
Stars: ✭ 245 (+288.89%)
Mutual labels:  bazel
Rules rust
Rust rules for Bazel
Stars: ✭ 241 (+282.54%)
Mutual labels:  bazel
Rules kotlin
Bazel rules for Kotlin
Stars: ✭ 235 (+273.02%)
Mutual labels:  bazel
bazel-maven-proxy
A local (read-only) proxy for Bazel to access Maven resources behind a secure repository or from the local Maven repository
Stars: ✭ 22 (-65.08%)
Mutual labels:  bazel
Rules k8s
This repository contains rules for interacting with Kubernetes configurations / clusters.
Stars: ✭ 222 (+252.38%)
Mutual labels:  bazel
bazel-action
A GitHub action to run @bazelbuild commands
Stars: ✭ 18 (-71.43%)
Mutual labels:  bazel
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (+226.98%)
Mutual labels:  bazel
Index Import
Tool to import swiftc and clang index-store files into Xcode
Stars: ✭ 240 (+280.95%)
Mutual labels:  bazel
bazel-boost
A bazel workspace for using boost
Stars: ✭ 12 (-80.95%)
Mutual labels:  bazel
rules antlr
ANTLR rules for Bazel
Stars: ✭ 24 (-61.9%)
Mutual labels:  bazel
rules ocaml
A Bazel Language Support Package for OCaml
Stars: ✭ 24 (-61.9%)
Mutual labels:  bazel

bazel_clang_tidy

Run clang-tidy on Bazel C++ targets directly, without generating a compile commands database, and take advantage of Bazels powerful cache mechanism.

Usage:

# //:WORKSPACE
load(
    "@bazel_tools//tools/build_defs/repo:git.bzl",
    "git_repository",
)

git_repository(
       name = "bazel_clang_tidy",
       commit = "69aa13e6d7cf102df70921c66be15d4592251e56",
       remote = "https://github.com/erenon/bazel_clang_tidy.git",
)

You can now compile using the default clang tidy configuration provided using the following command;

bazel build //... \
  --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect \
  --output_groups=report

If you would like to override the default clang tidy configuration then you can reconfigure the default target from the command line. To do this you must first make a filegroup target that has the .clang-tidy config file as a data dependency.

# //:BUILD
filegroup(
       name = "clang_tidy_config",
       srcs = [".clang-tidy"],
       visibility = ["//visibility:public"],
)

Now you can override the default config file in this repository using a command line flag;

bazel build //... \
  --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect \
  --output_groups=report \
  --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config

the config-file will not be forced by adding it to the clang-tidy command line. Therefore it must be in one of the parents of all source files. It is recommended to put it in the root directly besides the WORKSPACE file.

Now if you don't want to type this out every time, it is recommended that you add a config in your .bazelrc that matches this command line;

# Required for bazel_clang_tidy to operate as expected
build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
build:clang-tidy --output_groups=report

# Optionally override the .clang-tidy config file target
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config

Now from the command line this is a lot nicer to use;

bazel build //... --config clang-tidy

use a non-system clang-tidy

by default, bazel_clang_tidy uses the system provided clang-tidy. If you have a hermetic build, you can use your own clang-tidy target like this:

build:clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=@local_config_cc//:clangtidy_bin

Features

  • Run clang-tidy on any C++ target
  • Run clang-tidy without also building the target
  • Use Bazel to cache clang-tidy reports: recompute stale reports only

Install

Copy .clang-tidy, BUILD and clang_tidy dir to your workspace. Edit .clang-tidy as needed.

Example

To see the tool in action:

  1. Clone the repository

  2. Run clang-tidy:

    bazel build //example --aspects clang_tidy/clang_tidy.bzl%clang_tidy_aspect --output_groups=report
    
  3. Check the error:

    lib.cpp:4:43: error: the parameter 'name' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param,-warnings-as-errors] std::string lib_get_greet_for(std::string name)
    Aspect //clang_tidy:clang_tidy.bzl%clang_tidy_aspect of //example:app failed to build
    
  4. Fix the error by changing lib.cpp only.

  5. Re-run clang-tidy with the same command. Observe that it does not run clang-tidy for app.cpp: the cached report is re-used.

Requirements

  • Bazel 4.0 or newer (might work with older versions)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].