Skip to content

Commit

Permalink
add compile_commands support to simplify development (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
wbpcode authored Dec 12, 2023
1 parent c2bb8b4 commit 9b7e772
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ user.bazelrc
compile_commands.json

coverage_report

### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
# 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.
/external
# 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.
/bazel-*
# 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.
/compile_commands.json
# Ignore the directory in which `clangd` stores its local index.
/.cache/
13 changes: 13 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")

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 = {
"//cpp2sky/...": "",
"//source/...": "",
"//test/...": "",
},
)
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ cc_binary(
],
)
```

#### Cmake

You can compile this project, according to the following steps:
```
step 01: git clone [email protected]:SkyAPM/cpp2sky.git
Expand All @@ -41,7 +43,7 @@ step 04: cmake -S ./grpc -B ./grpc/build && cmake --build ./grpc/build --paralle
step 05: cmake -S . -B ./build && cmake --build ./build
```

You can also use find_package to get target libary in your project. Like this:
You can also use find_package to get target libary in your project. Like this:
```
find_package(cpp2sky CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} cpp2sky::cpp2sky proto_lib)
Expand All @@ -52,9 +54,14 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(CPP2SKY_PKG REQUIRED cpp2sky)
```

Note:
Note:
- If you want to build this project over c11, you must update grpc version(current version:v1.46.6).
- Only test cmake using Centos and Ubuntu.

#### Develop

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!

#### Docs

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.
Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ grpc_deps()
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")

grpc_extra_deps()

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

hedron_compile_commands_setup()
11 changes: 11 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def cpp2sky_dependencies():
com_github_fmtlib_fmt()
com_google_abseil()
com_github_gabime_spdlog()
hedron_compile_commands()

def skywalking_data_collect_protocol():
http_archive(
Expand Down Expand Up @@ -89,3 +90,13 @@ def com_google_abseil():
strip_prefix = "abseil-cpp-6f43f5bb398b6685575b36874e36cf1695734df1",
urls = ["https://github.com/abseil/abseil-cpp/archive/6f43f5bb398b6685575b36874e36cf1695734df1.tar.gz"],
)

def hedron_compile_commands():
# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
http_archive(
name = "hedron_compile_commands",
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/dc36e462a2468bd79843fe5176542883b8ce4abe.tar.gz",
sha256 = "d63c1573eb1daa4580155a1f0445992878f4aa8c34eb165936b69504a8407662",
strip_prefix = "bazel-compile-commands-extractor-dc36e462a2468bd79843fe5176542883b8ce4abe",
)

0 comments on commit 9b7e772

Please sign in to comment.