Skip to content

docs: add Bazel build guide and bzlmod example - #3468

Open
zchuango wants to merge 1 commit into
apache:masterfrom
LinQuickDev:docs-bazel
Open

docs: add Bazel build guide and bzlmod example#3468
zchuango wants to merge 1 commit into
apache:masterfrom
LinQuickDev:docs-bazel

Conversation

@zchuango

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve #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 Brpc cannot link on Ubuntu LTS 16.04 #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:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands bRPC’s Bazel documentation with bzlmod-first guidance and updates the example/build_with_bazel_module example so it builds both an echo server and a new echo client target against a local bRPC checkout.

Changes:

  • Add Bazel build instructions to English/Chinese getting started docs and rewrite Bazel support docs with bzlmod-first setup and required registry guidance.
  • Extend example/build_with_bazel_module to include an echo_c++_client cc_binary and supporting client.cpp.
  • Add bzlmod single_version_override entries (leveldb/openssl) to support aarch64 builds in the bzlmod example.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
example/build_with_bazel_module/MODULE.bazel Adds bzlmod overrides for leveldb/openssl alongside local brpc checkout usage.
example/build_with_bazel_module/client.cpp Introduces a Bazel/bzlmod-built echo client example.
example/build_with_bazel_module/BUILD.bazel Adds a new echo_c++_client cc_binary target.
docs/en/getting_started.md Adds a “Compile brpc with Bazel” section pointing to the bzlmod example and Bazel docs.
docs/en/bazel_support.md Rewrites Bazel support docs to emphasize bzlmod usage and provides example MODULE.bazel snippets.
docs/cn/getting_started.md Adds a Bazel build section mirroring the English getting started guide.
docs/cn/bazel_support.md Rewrites Chinese Bazel support docs with bzlmod-first guidance and example snippets.
Suppressed comments (3)

docs/en/bazel_support.md:11

  • These bazel run commands imply the example is runnable out-of-the-box, but the server requires TLS cert/key files (cert.pem/key.pem). Consider limiting this snippet to build instructions (or add explicit steps to provide/generate the certs).
$ cd example/build_with_bazel_module
$ bazel build //:echo_c++_server //:echo_c++_client
$ bazel run //:echo_c++_server &
$ bazel run //:echo_c++_client

docs/cn/bazel_support.md:10

  • 这里的 bazel run 会让读者以为示例可以直接运行,但 server 需要 cert.pem/key.pem。建议这段只保留 build 命令,或补充如何准备证书文件。
$ cd example/build_with_bazel_module
$ bazel build //:echo_c++_server //:echo_c++_client
$ bazel run //:echo_c++_server &
$ bazel run //:echo_c++_client

example/build_with_bazel_module/client.cpp:74

  • Use nullptr (C++11+) instead of NULL for the done callback argument, matching other examples (e.g. example/echo_c++/client.cpp) and avoiding the macro’s ambiguous type.
        // Because `done'(last parameter) is NULL, this function waits until
        // the response comes back or error occurs(including timedout).
        stub.Echo(&cntl, &request, &response, NULL);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/en/bazel_support.md
Comment on lines +3 to +5
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:
Comment thread docs/cn/bazel_support.md
Comment on lines +3 to +4
推荐在 Bazel 项目中使用 bzlmod(`MODULE.bazel`)依赖本地 bRPC 源码。
`example/build_with_bazel_module` 中有一个包含 server 和 client 的可运行示例:
// 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

官方文档建议增加bazel的编译介绍,目前只有cmake和config_brpc.sh的步骤

3 participants