Skip to content

Commit 7d912d6

Browse files
dayshahrynewang
andauthored
[Core] Add bazel run :refresh_compile_commands for clangd (ray-project#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 <[email protected]> Co-authored-by: Ruiyang Wang <[email protected]>
1 parent 500b3b6 commit 7d912d6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

BUILD.bazel

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ load("@com_github_grpc_grpc//bazel:cython_library.bzl", "pyx_library")
1515
load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
1616
load("//bazel:ray.bzl", "COPTS", "PYX_COPTS", "PYX_SRCS", "copy_to_workspace", "ray_cc_binary", "ray_cc_library", "ray_cc_test")
1717
load("@python3_9//:defs.bzl", python39 = "interpreter")
18+
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")
1819

1920
package(
2021
default_visibility = ["//visibility:public"],
@@ -85,6 +86,27 @@ config_setting(
8586
flag_values = {":jemalloc_flag": "true"},
8687
)
8788

89+
# bazel run :refresh_compile_commands for compile_commands generation for clangd
90+
# https://github.com/hedronvision/bazel-compile-commands-extractor?tab=readme-ov-file#vscode - directions for clangd config
91+
refresh_compile_commands(
92+
name = "refresh_compile_commands",
93+
# Specify the targets of interest.
94+
# For example, specify a dict of targets and any flags required to build.
95+
targets = {
96+
"//:ray_pkg": "",
97+
},
98+
exclude_external_sources = True, # removed below to have lsp index external cc files at the cost of 2x index time
99+
# No need to add flags already in .bazelrc. They're automatically picked up.
100+
)
101+
102+
# bazel run :refresh_compile_commands_external_sources for generation with external source files (cc files)
103+
refresh_compile_commands(
104+
name = "refresh_compile_commands_external_sources",
105+
targets = {
106+
"//:ray_pkg": "",
107+
},
108+
)
109+
88110
# === Begin of rpc definitions ===
89111
# GRPC common lib.
90112
ray_cc_library(

WORKSPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ versions.check(
3333
minimum_bazel_version = "6.5.0",
3434
)
3535

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

4038
hedron_compile_commands_setup()

0 commit comments

Comments
 (0)