Skip to content

Commit

Permalink
Add rules for extracting bazel compile commands
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaNikolaenko committed Jul 18, 2022
1 parent ac77dd2 commit 9b4058f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# If there are too many errors, clangd, by default, does not show them, but instead
# emits the error [clang: fatal_too_many_errors].
# It's not helpful at all, so the following option disables this behaviour
# and forces clangd to continue running.
# https://github.com/clangd/coc-clangd/issues/255
CompileFlags:
Add: -ferror-limit=0
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
.vscode
.DS_Store
user.bazelrc
.dazel_run
bazel-*
*~

# Runtime file for Dazel.
.dazel_run

### Added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
# The external link: Differs on Windows vs macOS/Linux, so we can't check it in. The pattern needs to not have a trailing / because it's a symlink on macOS/Linux.
/external
# Bazel output symlinks: Same reasoning as /external. You need the * because people can change the name of the directory your repository is cloned into, changing the bazel-<workspace_name> symlink.
/bazel-*
# Compiled output -> don't check in
/compile_commands.json
# Directory where clangd puts its indexing work
/.cache/
46 changes: 46 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")

########################################################################

# TODO(alexmc): Remove this alias.
alias(
name = "eventuals",
Expand All @@ -13,3 +17,45 @@ alias(
deprecation = "Prefer //eventuals/grpc",
visibility = ["//visibility:public"],
)

########################################################################

# Hedron's Compile Commands Extractor for Bazel.
# Follow the link to learn how to set it up for your code editor:
# https://github.com/hedronvision/bazel-compile-commands-extractor
# NOTE: This rule is crucial for clangd and clang-tidy to work.
# Its output is used by clangd and clang-tidy to understand the build process.
# TODO(folming): find a cleaner way to make it automatic depending on the platform.
# select() doesn't work, produces the error: "unhashable type: 'select'".
# TODO(folming): move the rules to a separate bazel file.

refresh_compile_commands(
name = "refresh_cc_windows",
# Add additional targets in here if needed.
# The value for keys is meant for additional bazel build arguments, e.g.
# "//test:eventuals": "--compilation_mode=dbg".
targets = {
"//test:eventuals": "",
},
)

refresh_compile_commands(
name = "refresh_cc_default",
# Add additional targets in here if needed.
# The value for keys is meant for additional bazel build arguments, e.g.
# "//test:eventuals": "--compilation_mode=dbg".
targets = {
"//test:eventuals": "",
"//test/grpc:grpc": "",
},
)

alias(
name = "refresh_cc", # refresh_compile_commands
actual = select({
"@bazel_tools//src/conditions:windows": "refresh_cc_windows",
"//conditions:default": "refresh_cc_default",
}),
)

########################################################################
20 changes: 20 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()

########################################################################

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

# Hedron's Compile Commands Extractor for Bazel.
# Latest version available on 2022/07/18.
# Follow the link to learn how to set it up for your code editor:
# https://github.com/hedronvision/bazel-compile-commands-extractor
# TODO(folming): move the rules to a separate bazel file.
git_repository(
name = "hedron_compile_commands",
commit = "05610f52a2ea3cda6ac27133b96f71c36358adf9",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor",
shallow_since = "1657677319 -0700",
)

load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")

hedron_compile_commands_setup()

########################################################################

0 comments on commit 9b4058f

Please sign in to comment.