From 71ea6e647fe0479c761efe6e8e4a5d9be0807c7a Mon Sep 17 00:00:00 2001 From: wangbaiping Date: Tue, 12 Dec 2023 21:33:38 +0800 Subject: [PATCH] add compile_commands support to simplify development Signed-off-by: wangbaiping --- .gitignore | 10 ++++++++++ BUILD | 13 +++++++++++++ README.md | 11 +++++++++-- WORKSPACE | 4 ++++ bazel/repositories.bzl | 11 +++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 BUILD diff --git a/.gitignore b/.gitignore index 7c0087b..5fd9477 100644 --- a/.gitignore +++ b/.gitignore @@ -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-` 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/ diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..7f60adb --- /dev/null +++ b/BUILD @@ -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/...": "", + }, +) diff --git a/README.md b/README.md index ef4d931..d82f46b 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,9 @@ cc_binary( ], ) ``` + #### Cmake + You can compile this project, according to the following steps: ``` step 01: git clone git@github.com:SkyAPM/cpp2sky.git @@ -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) @@ -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. diff --git a/WORKSPACE b/WORKSPACE index 731bad6..c6c86a3 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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() diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 9dabd4f..9bbb35f 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -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( @@ -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", + )