Skip to content

Commit

Permalink
[Core] Add bazel run :refresh_compile_commands for clangd (ray-projec…
Browse files Browse the repository at this point in the history
…t#47964)

Gives clangd the ability to fully index ray's c++ code after you run
```bazel run :refresh_compile_commands```. Gives you lsp support +
clang-tidy linting in ide to catch bad cpp practices in files based on
rules already setup in .clang-tidy.
https://github.com/ray-project/ray/blob/master/.clang-tidy A lot of
these don't seem to be followed though and seem contrary to some of the
style of existing code, but some are critical for not giving up
performance gains off of small things. Trimming down to more important
lints could be helpful.

Signed-off-by: dayshah <dhyey2019@gmail.com>
Co-authored-by: Ruiyang Wang <56065503+rynewang@users.noreply.github.com>
  • Loading branch information
dayshah and rynewang authored Oct 30, 2024
1 parent 500b3b6 commit 7d912d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 22 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ load("@com_github_grpc_grpc//bazel:cython_library.bzl", "pyx_library")
load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
load("//bazel:ray.bzl", "COPTS", "PYX_COPTS", "PYX_SRCS", "copy_to_workspace", "ray_cc_binary", "ray_cc_library", "ray_cc_test")
load("@python3_9//:defs.bzl", python39 = "interpreter")
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")

package(
default_visibility = ["//visibility:public"],
Expand Down Expand Up @@ -85,6 +86,27 @@ config_setting(
flag_values = {":jemalloc_flag": "true"},
)

# bazel run :refresh_compile_commands for compile_commands generation for clangd
# https://github.com/hedronvision/bazel-compile-commands-extractor?tab=readme-ov-file#vscode - directions for clangd config
refresh_compile_commands(
name = "refresh_compile_commands",
# Specify the targets of interest.
# For example, specify a dict of targets and any flags required to build.
targets = {
"//:ray_pkg": "",
},
exclude_external_sources = True, # removed below to have lsp index external cc files at the cost of 2x index time
# No need to add flags already in .bazelrc. They're automatically picked up.
)

# bazel run :refresh_compile_commands_external_sources for generation with external source files (cc files)
refresh_compile_commands(
name = "refresh_compile_commands_external_sources",
targets = {
"//:ray_pkg": "",
},
)

# === Begin of rpc definitions ===
# GRPC common lib.
ray_cc_library(
Expand Down
2 changes: 0 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ versions.check(
minimum_bazel_version = "6.5.0",
)

# Tools to generate `compile_commands.json` to enable awesome tooling of the C language family.
# Just run `bazel run @hedron_compile_commands//:refresh_all`
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")

hedron_compile_commands_setup()
Expand Down

0 comments on commit 7d912d6

Please sign in to comment.