Skip to content

Commit 9b7e772

Browse files
authored
add compile_commands support to simplify development (#127)
1 parent c2bb8b4 commit 9b7e772

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,13 @@ user.bazelrc
4747
compile_commands.json
4848

4949
coverage_report
50+
51+
### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
52+
# Ignore the `external` link (that is added by `bazel-compile-commands-extractor`). The link differs between macOS/Linux and Windows, so it shouldn't be checked in. The pattern must not end with a trailing `/` because it's a symlink on macOS/Linux.
53+
/external
54+
# Ignore links to Bazel's output. The pattern needs the `*` because people can change the name of the directory into which your repository is cloned (changing the `bazel-<workspace_name>` symlink), and must not end with a trailing `/` because it's a symlink on macOS/Linux.
55+
/bazel-*
56+
# Ignore generated output. Although valuable (after all, the primary purpose of `bazel-compile-commands-extractor` is to produce `compile_commands.json`!), it should not be checked in.
57+
/compile_commands.json
58+
# Ignore the directory in which `clangd` stores its local index.
59+
/.cache/

BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")
2+
3+
refresh_compile_commands(
4+
name = "refresh_compile_commands",
5+
6+
# Specify the targets of interest.
7+
# For example, specify a dict of targets and any flags required to build.
8+
targets = {
9+
"//cpp2sky/...": "",
10+
"//source/...": "",
11+
"//test/...": "",
12+
},
13+
)

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ cc_binary(
3131
],
3232
)
3333
```
34+
3435
#### Cmake
36+
3537
You can compile this project, according to the following steps:
3638
```
3739
step 01: git clone [email protected]:SkyAPM/cpp2sky.git
@@ -41,7 +43,7 @@ step 04: cmake -S ./grpc -B ./grpc/build && cmake --build ./grpc/build --paralle
4143
step 05: cmake -S . -B ./build && cmake --build ./build
4244
```
4345

44-
You can also use find_package to get target libary in your project. Like this:
46+
You can also use find_package to get target libary in your project. Like this:
4547
```
4648
find_package(cpp2sky CONFIG REQUIRED)
4749
target_link_libraries(${PROJECT_NAME} cpp2sky::cpp2sky proto_lib)
@@ -52,9 +54,14 @@ find_package(PkgConfig REQUIRED)
5254
pkg_check_modules(CPP2SKY_PKG REQUIRED cpp2sky)
5355
```
5456

55-
Note:
57+
Note:
5658
- If you want to build this project over c11, you must update grpc version(current version:v1.46.6).
5759
- Only test cmake using Centos and Ubuntu.
60+
61+
#### Develop
62+
63+
Generate `compile_commands.json` for this repo by `bazel run :refresh_compile_commands`. Thank https://github.com/hedronvision/bazel-compile-commands-extractor for it provide the great script/tool to make this so easy!
64+
5865
#### Docs
5966

6067
cpp2sky configration is based on protobuf, and docs are generated by [protodoc](https://github.com/etcd-io/protodoc). If you have any API change, you should run below.

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ grpc_deps()
1717
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
1818

1919
grpc_extra_deps()
20+
21+
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
22+
23+
hedron_compile_commands_setup()

bazel/repositories.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def cpp2sky_dependencies():
1010
com_github_fmtlib_fmt()
1111
com_google_abseil()
1212
com_github_gabime_spdlog()
13+
hedron_compile_commands()
1314

1415
def skywalking_data_collect_protocol():
1516
http_archive(
@@ -89,3 +90,13 @@ def com_google_abseil():
8990
strip_prefix = "abseil-cpp-6f43f5bb398b6685575b36874e36cf1695734df1",
9091
urls = ["https://github.com/abseil/abseil-cpp/archive/6f43f5bb398b6685575b36874e36cf1695734df1.tar.gz"],
9192
)
93+
94+
def hedron_compile_commands():
95+
# Hedron's Compile Commands Extractor for Bazel
96+
# https://github.com/hedronvision/bazel-compile-commands-extractor
97+
http_archive(
98+
name = "hedron_compile_commands",
99+
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/dc36e462a2468bd79843fe5176542883b8ce4abe.tar.gz",
100+
sha256 = "d63c1573eb1daa4580155a1f0445992878f4aa8c34eb165936b69504a8407662",
101+
strip_prefix = "bazel-compile-commands-extractor-dc36e462a2468bd79843fe5176542883b8ce4abe",
102+
)

0 commit comments

Comments
 (0)