You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "zchuango (via GitHub)" <gi...@apache.org> on 2026/08/20 11:13:54 UTC

[PR] docs: add Bazel build guide and bzlmod example (brpc)

zchuango opened a new pull request, #3468:
URL: https://github.com/apache/brpc/pull/3468

   ### What problem does this PR solve?
   
   Issue Number: resolve apache/brpc#2991
   
   Problem Summary:
   
   The build documentation currently focuses on config_brpc.sh and CMake. It does not provide a clear Bazel/bzlmod build path for users who want to build bRPC or use bRPC as a Bazel dependency.
   
   ### What is changed and the side effects?
   
   Changed:
   - Add Bazel/bzlmod build instructions to the English and Chinese getting started docs.
   - Rewrite the English and Chinese Bazel support docs with bzlmod-first dependency guidance.
   - Document the required registries and root MODULE.bazel setup for using bRPC as a Bazel dependency.
   - Add an echo client target to example/build_with_bazel_module so the bzlmod example has both server and client targets.
   - Add required leveldb and openssl single_version_override entries for aarch64 bzlmod builds, and document that users must repeat these overrides in their own root MODULE.bazel.
   
   Side effects:
   - Performance effects: None. This PR only changes documentation and the Bazel example.
   
   - Breaking backward compatibility: None.
   
   Validation:
   - GitHub Actions passed on PR #13.
   - Linux x64: Bazel all-options jobs passed with both gcc and clang, including the external bzlmod example under `example/build_with_bazel_module`.
   - macOS ARM64: Bazel build passed.
   - Linux aarch64: manually verified with `cd example/build_with_bazel_module && bazel-7.2.1 $JVMARG build //:echo_c++_server //:echo_c++_client`.
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] docs: add Bazel build guide and bzlmod example (brpc)

Posted by "zchuango (via GitHub)" <gi...@apache.org>.
zchuango commented on code in PR #3468:
URL: https://github.com/apache/brpc/pull/3468#discussion_r3842089893


##########
example/build_with_bazel_module/MODULE.bazel:
##########
@@ -27,4 +27,15 @@ bazel_dep(name = 'brpc', version = '1.17.0', repo_name = 'apache_brpc')
 local_path_override(
     module_name = "brpc",
     path = "../..",
-)
\ No newline at end of file
+)
+
+single_version_override(

Review Comment:
   `single_version_override` is used here to ensure that the example uses the expected dependency versions during Bazel module resolution.
   
   Since `brpc-example` is the root module and `brpc` is only a dependency, the overrides defined in `brpc`'s own `MODULE.bazel` do not apply here. Without overriding these dependencies in the root module, Bazel may not be able to resolve the required versions from the available registries.
   
   For example, `leveldb 1.23` is only available from the `secretflow` registry, and `openssl 3.3.2` needs to be resolved as `3.3.2.bcr.1` from that registry. `single_version_override` allows us to explicitly select the required version for this example.
   
   I also added comments above these blocks to explain this behavior and noted that they should be kept in sync with the root `MODULE.bazel` configuration.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] docs: add Bazel build guide and bzlmod example (brpc)

Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on PR #3468:
URL: https://github.com/apache/brpc/pull/3468#issuecomment-5377839323

   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] docs: add Bazel build guide and bzlmod example (brpc)

Posted by "zchuango (via GitHub)" <gi...@apache.org>.
zchuango commented on code in PR #3468:
URL: https://github.com/apache/brpc/pull/3468#discussion_r3842089893


##########
example/build_with_bazel_module/MODULE.bazel:
##########
@@ -27,4 +27,15 @@ bazel_dep(name = 'brpc', version = '1.17.0', repo_name = 'apache_brpc')
 local_path_override(
     module_name = "brpc",
     path = "../..",
-)
\ No newline at end of file
+)
+
+single_version_override(

Review Comment:
   `single_version_override` is used here to ensure that this example uses the expected dependency versions during Bazel module resolution.
   
   When building this example, `brpc-example` is the root module and `brpc` is only a dependency, so the overrides defined in brpc's own MODULE.bazel do not apply here. Without overriding these dependencies in the root module, Bazel may not be able to resolve the required versions from the available registries.
   
   For example, leveldb 1.23 is only available from the secretflow registry, and openssl 3.3.2 is resolved there as 3.3.2.bcr.1. `single_version_override` allows us to explicitly select these required versions for this example.
   
   I also added comments above these blocks to explain this behavior and noted that they should be kept in sync with the root MODULE.bazel configuration.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] docs: add Bazel build guide and bzlmod example (brpc)

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3468:
URL: https://github.com/apache/brpc/pull/3468#discussion_r3821375438


##########
docs/en/bazel_support.md:
##########
@@ -1,20 +1,105 @@
 ## bRPC as a Bazel third-party dependency
-1. bRPC relies on a number of open source libraries that do not provide bazel support, so you will need to manually add some of these dependencies to your build project.
-2. Move the BUILD file /example/build_with_bazel/*.BUILD and brpc_workspace.bzl to the root of your project, and add the contents of 
-```c++
-    load("@//:brpc_workspace.bzl", "brpc_workspace")
-    brpc_workspace();
+
+The recommended way to depend on a local bRPC checkout from a Bazel project is
+to use bzlmod (`MODULE.bazel`). See `example/build_with_bazel_module` for a
+runnable example with both a server and a client:

Review Comment:
   The docs describe `example/build_with_bazel_module` as a runnable example, but the example server binary expects TLS files (`cert.pem` / `key.pem`) at runtime (see example/build_with_bazel_module/server.cpp:86-87). As written, the example is reliably buildable, but may not be runnable out-of-the-box.
   
   This issue also appears on line 8 of the same file.



##########
docs/cn/bazel_support.md:
##########
@@ -1,20 +1,100 @@
-## bRPC 作为Bazel第三方依赖
-1. bRPC 依赖于一些开源库, 但这些库并没有提供bazel支持, 所以需要你手动将一部分依赖加入到你的构建项目中.
-2. 将 /example/build_with_bazel/*.BUILD 和 brpc_workspace.bzl 该文件移动到你的项目根目录下, 将
-```c++
-    load("@//:brpc_workspace.bzl", "brpc_workspace")
-    brpc_workspace();
+## bRPC 作为 Bazel 第三方依赖
+
+推荐在 Bazel 项目中使用 bzlmod(`MODULE.bazel`)依赖本地 bRPC 源码。
+`example/build_with_bazel_module` 中有一个包含 server 和 client 的可运行示例:

Review Comment:
   这里写“可运行示例”可能会误导:当前示例里的 server 运行时依赖 `cert.pem`/`key.pem`(见 example/build_with_bazel_module/server.cpp:86-87),默认目录下并没有提供这些文件。建议改为“可编译/可构建示例”或补充证书生成/配置步骤。
   
   This issue also appears on line 7 of the same file.



##########
example/build_with_bazel_module/client.cpp:
##########
@@ -0,0 +1,89 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// A client sending requests to server every 1 second.
+
+#include <gflags/gflags.h>
+#include <butil/logging.h>
+#include <brpc/channel.h>
+#include "echo.pb.h"
+
+DEFINE_string(attachment, "", "Carry this along with requests");
+DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in src/brpc/options.proto");
+DEFINE_string(connection_type, "", "Connection type. Available values: single, pooled, short");
+DEFINE_string(server, "0.0.0.0:8002", "IP Address of server");
+DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
+DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
+DEFINE_int32(interval_ms, 1000, "Milliseconds between consecutive requests");
+
+int main(int argc, char* argv[]) {
+    // Parse gflags. We recommend you to use gflags as well.
+    GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
+
+    // A Channel represents a communication line to a Server. Notice that
+    // Channel is thread-safe and can be shared by all threads in your program.
+    brpc::Channel channel;
+
+    // Initialize the channel, NULL means using default options.

Review Comment:
   Use `nullptr` in C++ code/comments instead of `NULL` for consistency with the rest of the C++ examples and to avoid the macro’s ambiguous type.
   
   This issue also appears on line 72 of the same file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] docs: add Bazel build guide and bzlmod example (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #3468:
URL: https://github.com/apache/brpc/pull/3468#discussion_r3841595327


##########
example/build_with_bazel_module/MODULE.bazel:
##########
@@ -27,4 +27,15 @@ bazel_dep(name = 'brpc', version = '1.17.0', repo_name = 'apache_brpc')
 local_path_override(
     module_name = "brpc",
     path = "../..",
-)
\ No newline at end of file
+)
+
+single_version_override(

Review Comment:
   Why use single_version_override?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [PR] docs: add Bazel build guide and bzlmod example (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright merged PR #3468:
URL: https://github.com/apache/brpc/pull/3468


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org