Repository navigation
Use Google CRC32C for RPC checksums - #3787
yanglimingcn wants to merge 1 commit into
Conversation
| find_library(CRC32C_LIB NAMES crc32c) | ||
| if(NOT CRC32C_LIB) | ||
| set(CRC32C_LIB "") | ||
| endif() |
There was a problem hiding this comment.
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.
| 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") |
There was a problem hiding this comment.
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.
| "//bazel/config:brpc_with_urma_use_real": ["-lurma"], | ||
| "//conditions:default": [], | ||
| }), | ||
| local_defines = ["BRPC_WITH_GOOGLE_CRC32C"], |
There was a problem hiding this comment.
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.
| protobuf::libprotobuf | ||
| ${_protobuf_absl_targets} | ||
| ${LEVELDB_LIB} | ||
| ${CRC32C_LIB} |
There was a problem hiding this comment.
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.
2a7c06e to
f61591f
Compare
There was a problem hiding this comment.
🟢 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
left a comment
There was a problem hiding this comment.
-
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) andconfig_brpc.sh(--with-google-crc32c) are both opt-in.- All existing
BRPC_WITH_*options inbazel/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 downstreamWORKSPACEconsumers that do not declare@com_github_google_crc32c, and avoids needing theriscv64special-case fallback (since RISC-V naturally stays onbutil'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=ONin a CMake CI job iflibcrc32c-devis installed.
- All existing
-
Handle static Google CRC32C linking in
example/benchmark_fb/CMakeLists.txt
Likeexample/ubring_performance/CMakeLists.txt,example/benchmark_fb/CMakeLists.txtdoes not usebrpc_example_find_common_depsand defaults to linkinglibbrpc.a(LINK_SO=OFF). When bRPC is built with-DWITH_FLATBUFFERS=ON -DWITH_GOOGLE_CRC32C=ON,example/benchmark_fbwill fail to linkcrc32c::ExtendunlessBRPC_EXTRA_LIBRARIESis passed manually. Including../cmake/BrpcExample.cmakeand callingbrpc_example_find_crc32c("${_BRPC_LIBRARY}" ...)there would keep all CMake examples consistent.
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: