Skip to content

Use Google CRC32C for RPC checksums - #3787

Open
yanglimingcn wants to merge 1 commit into
apache:masterfrom
yanglimingcn:feature/use_google_checksum
Open

yanglimingcn wants to merge 1 commit into
apache:masterfrom
yanglimingcn:feature/use_google_checksum

Conversation

@yanglimingcn

@yanglimingcn yanglimingcn commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

Enable Google CRC32C by default in Bazel and add opt-in support for CMake and Make. Preserve the checksum wire format and cover fragmented payloads with a known-vector test.

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

Comment thread example/cmake/BrpcExample.cmake Outdated
find_library(CRC32C_LIB NAMES crc32c)
if(NOT CRC32C_LIB)
set(CRC32C_LIB "")
endif()

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.

example/ubring_performance does not call this helper macro. It selects libbrpc.a by default, but its own DYNAMIC_LIB list does not include CRC32C. When the Google backend is enabled, the global registration in Channel::Init pulls in the checksum object, and the final link fails because crc32c::Extend is missing. Please apply the static dependency handling to this standalone example as well.

Comment thread src/brpc/CMakeLists.txt Outdated
target_compile_definitions(brpc_crc32c INTERFACE BRPC_WITH_GOOGLE_CRC32C)
target_link_libraries(brpc_crc32c INTERFACE ${CRC32C_LIB})
list(APPEND brpc_libraries ${CRC32C_LIB})
string(APPEND brpc_private_libs " -lcrc32c")

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.

Simplifying ${CRC32C_LIB} to -lcrc32c here loses the directory found by find_library. If CRC32C is supplied through a separate CMAKE_PREFIX_PATH, bRPC builds successfully, but downstream consumers using only pkg-config --static --libs brpc cannot find the library. Please retain the required library search path in the private link metadata.

Comment thread BUILD.bazel Outdated
"//bazel/config:brpc_with_urma_use_real": ["-lurma"],
"//conditions:default": [],
}),
local_defines = ["BRPC_WITH_GOOGLE_CRC32C"],

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.

This unconditional local_defines causes RISC-V builds with Zbc/Zvbc enabled to lose their existing RPC CRC32C hardware path. butil recognizes both extensions, while Google 1.1.2 goes straight to ExtendPortable on RISC-V. Please retain the built-in backend for these targets, or provide a Bazel configuration that allows it to be selected again.

Comment thread example/cmake/BrpcExample.cmake Outdated
protobuf::libprotobuf
${_protobuf_absl_targets}
${LEVELDB_LIB}
${CRC32C_LIB}

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.

This adds any libcrc32c.so that happens to be installed on the build machine to all examples. Even when bRPC uses the built-in backend, --no-as-needed records it as a runtime dependency, preventing the examples from starting on deployment machines without that library. Please decide whether to include CRC32C based on the actual link requirements of the selected bRPC artifact.

Enable Google CRC32C by default in Bazel and add opt-in support for CMake and Make. Preserve the checksum wire format and cover fragmented payloads with a known-vector test.
@yanglimingcn
yanglimingcn force-pushed the feature/use_google_checksum branch from 2a7c06e to f61591f Compare December 3, 2026 08:33
@yanglimingcn
yanglimingcn requested review from chenBright and a balanced review from Copilot December 3, 2026 08:33

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.

🟢 Approval recommended

No active review issues remain for the Google CRC32C backend integration.

No open issues 🎉

What changed in this PR

Adds Google CRC32C as an RPC checksum backend while preserving the existing wire format.

Changes:

  • Enables Google CRC32C by default in Bazel, with opt-out and RISC-V fallback.
  • Adds opt-in CMake and Make support, including example dependency handling.
  • Adds fragmented-payload checksum and dependency-link checks.
File Description
test/​CMakeLists.txt Applies CRC32C configuration to test objects.
test/​cmake_link_dependencies/​CMakeLists.txt Passes CRC32C settings to link checks.
test/​cmake_link_dependencies/​check_pkgconfig.cmake Checks dependency metadata and archive detection.
test/​brpc_checksum_unittest.cpp Tests a known checksum across fragmented payloads.
src/​brpc/​policy/​crc32c_checksum.cpp Selects the backend while retaining wire encoding.
src/​brpc/​CMakeLists.txt Configures CRC32C compilation and linking.
MODULE.bazel Adds the Google CRC32C dependency.
example/​ubring_performance/​CMakeLists.txt Links CRC32C when required by static bRPC.
example/​cmake/​BrpcExample.cmake Detects static archives requiring CRC32C.
config_brpc.sh Adds the Make configuration switch.
CMakeLists.txt Adds the CMake opt-in option.
BUILD.bazel Selects CRC32C definitions and dependencies.
bazel/​config/​BUILD.bazel Defines opt-out and RISC-V fallback conditions.

Review effort: Balanced

@wasphin wasphin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Keep the default behavior consistent across Bazel, CMake, and config_brpc.sh
    Currently, Bazel enables Google CRC32C by default (opt-out via --define=BRPC_WITH_GOOGLE_CRC32C=false), while CMake (WITH_GOOGLE_CRC32C=OFF) and config_brpc.sh (--with-google-crc32c) are both opt-in.

    • All existing BRPC_WITH_* options in bazel/config/BUILD.bazel (BRPC_WITH_GLOG, BRPC_WITH_THRIFT, BRPC_WITH_FLATBUFFERS, BRPC_WITH_RDMA, BRPC_WITH_URMA, BRPC_WITH_UBRING, BRPC_WITH_MESALINK, BRPC_WITH_BORINGSSL) default to OFF and are enabled with =true, matching CMake and Make.
    • Making Bazel opt-in as well (config_setting(name = "brpc_with_google_crc32c", define_values = {"BRPC_WITH_GOOGLE_CRC32C": "true"})) keeps the option semantics consistent across all three build systems, avoids breaking downstream WORKSPACE consumers that do not declare @com_github_google_crc32c, and avoids needing the riscv64 special-case fallback (since RISC-V naturally stays on butil's Zbc/Zvbc path by default).
    • To keep the Google CRC32C path covered in CI once opt-in, we can enable --define=BRPC_WITH_GOOGLE_CRC32C=true (e.g., in the Bazel all-options/test job) and -DWITH_GOOGLE_CRC32C=ON in a CMake CI job if libcrc32c-dev is installed.
  2. Handle static Google CRC32C linking in example/benchmark_fb/CMakeLists.txt
    Like example/ubring_performance/CMakeLists.txt, example/benchmark_fb/CMakeLists.txt does not use brpc_example_find_common_deps and defaults to linking libbrpc.a (LINK_SO=OFF). When bRPC is built with -DWITH_FLATBUFFERS=ON -DWITH_GOOGLE_CRC32C=ON, example/benchmark_fb will fail to link crc32c::Extend unless BRPC_EXTRA_LIBRARIES is passed manually. Including ../cmake/BrpcExample.cmake and calling brpc_example_find_crc32c("${_BRPC_LIBRARY}" ...) there would keep all CMake examples consistent.

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.

4 participants