Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,42 @@ concurrency:

# https://github.com/actions/runner-images
jobs:
flatbuffers-codegen:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
cxx: [g++-11, clang++-14]
steps:
- uses: actions/checkout@v7.0.1
- name: Install codegen dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake g++-11 clang-14 \
libprotobuf-dev libprotoc-dev protobuf-compiler \
libgflags-dev libleveldb-dev libssl-dev zlib1g-dev
- name: Build isolated Gperftools
env:
CXX: ${{ matrix.cxx }}
run: |
archive="$RUNNER_TEMP/gperftools-2.16.tar.gz"
curl --fail --location --retry 3 \
https://github.com/gperftools/gperftools/releases/download/gperftools-2.16/gperftools-2.16.tar.gz \
--output "$archive"
printf '%s %s\n' f12624af5c5987f2cc830ee534f754c3c5961eec08004c26a8b80de015cf056f "$archive" | sha256sum --check
tar -xzf "$archive" -C "$RUNNER_TEMP"
cd "$RUNNER_TEMP/gperftools-2.16"
./configure --prefix="$RUNNER_TEMP/gperftools-install" \
--enable-frame-pointers --disable-libunwind
make -j2
make install
printf 'CMAKE_PREFIX_PATH=%s\n' "$RUNNER_TEMP/gperftools-install" >> "$GITHUB_ENV"
- name: Verify FlatBuffers generation and runtime
env:
CXX: ${{ matrix.cxx }}
JOBS: 2
run: bash tools/flatbuffers/verify.sh "$RUNNER_TEMP/flatbuffers-codegen"

compile-with-make:
name: compile-with-make (${{ matrix.name }})
runs-on: ubuntu-22.04
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
flatbuffers-codegen:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
protobuf: [protobuf@21, protobuf@29]
steps:
- uses: actions/checkout@v7.0.1
- name: Install codegen dependencies
run: brew install cmake openssl gflags leveldb snappy gperftools ${{ matrix.protobuf }}
- name: Verify FlatBuffers generation and runtime
env:
CXX: clang++
JOBS: 2
run: |
export CMAKE_PREFIX_PATH="$(brew --prefix ${{ matrix.protobuf }});$(brew --prefix)"
export OPENSSL_ROOT_DIR="$(brew --prefix openssl)"
bash tools/flatbuffers/verify.sh "$RUNNER_TEMP/flatbuffers-codegen"

compile-with-make-cmake-protobuf21:
runs-on: macos-latest # https://github.com/actions/runner-images

Expand Down
27 changes: 26 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ licenses(["notice"]) # Apache v2

exports_files(["LICENSE"])

config_setting(
name = "brpc_with_flatbuffers",
define_values = {"BRPC_WITH_FLATBUFFERS": "true"},
visibility = ["//visibility:public"],
)

COPTS = [
"-fno-omit-frame-pointer",
] + select({
Expand All @@ -45,6 +51,9 @@ DEFINES = [
}) + select({
"//bazel/config:brpc_with_thrift": ["ENABLE_THRIFT_FRAMED_PROTOCOL=1"],
"//conditions:default": [],
}) + select({
":brpc_with_flatbuffers": ["BRPC_WITH_FLATBUFFERS=1"],
"//conditions:default": ["BRPC_WITH_FLATBUFFERS=0"],
}) + select({
"//bazel/config:brpc_with_thrift_legacy_version": [],
"//conditions:default": ["THRIFT_STDCXX=std"],
Expand Down Expand Up @@ -125,6 +134,14 @@ genrule(
"//conditions:default": "0",
}) +
"""
#ifdef BRPC_WITH_FLATBUFFERS
#undef BRPC_WITH_FLATBUFFERS
#endif
#define BRPC_WITH_FLATBUFFERS """ + select({
":brpc_with_flatbuffers": "1",
"//conditions:default": "0",
}) +
"""
#ifdef BUTIL_USE_CPU_FREQUENCY
#undef BUTIL_USE_CPU_FREQUENCY
#endif
Expand Down Expand Up @@ -539,6 +556,8 @@ brpc_proto_library(
visibility = ["//visibility:public"],
)

FLATBUFFERS_SRC_PATTERNS = ["src/brpc/flatbuffers/*.cpp"]

URMA_SRC_PATTERNS = [
"src/brpc/urma/*.cpp",
"src/brpc/urma/**/*.cpp",
Expand All @@ -562,7 +581,7 @@ BRPC_BASE_SRCS = glob(
"src/brpc/policy/thrift_protocol.cpp",
"src/brpc/event_dispatcher_epoll.cpp",
"src/brpc/event_dispatcher_kqueue.cpp",
] + URMA_SRC_PATTERNS,
] + URMA_SRC_PATTERNS + FLATBUFFERS_SRC_PATTERNS,
)

cc_library(
Expand All @@ -573,6 +592,9 @@ cc_library(
"src/brpc/**/thrift*.cpp",
]),
"//conditions:default": [],
}) + select({
":brpc_with_flatbuffers": glob(FLATBUFFERS_SRC_PATTERNS),
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_urma_use_real": URMA_SRCS,
"//bazel/config:brpc_with_urma": URMA_SRCS + [
Expand Down Expand Up @@ -612,6 +634,9 @@ cc_library(
"@org_apache_thrift//:thrift",
],
"//conditions:default": [],
}) + select({
":brpc_with_flatbuffers": ["@com_github_google_flatbuffers//:runtime_cc"],
"//conditions:default": [],
}),
)

Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ option(WITH_MESALINK "With MesaLink" OFF)
option(WITH_BORINGSSL "With BoringSSL" OFF)
option(WITH_DEBUG_SYMBOLS "With debug symbols" ON)
option(WITH_THRIFT "With thrift framed protocol supported" OFF)
option(WITH_FLATBUFFERS "With FlatBuffers message support (headers only)" OFF)
option(WITH_BTHREAD_TRACER "With bthread tracer supported" OFF)
option(WITH_SNAPPY "With snappy" OFF)
option(WITH_RDMA "With RDMA" OFF)
Expand Down Expand Up @@ -82,6 +83,17 @@ if(WITH_GLOG)
set(BRPC_WITH_GLOG 1)
endif()

set(WITH_FLATBUFFERS_VAL "0")
if(WITH_FLATBUFFERS)
find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h)

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.

[replied by brpc-oncall robot] WITH_FLATBUFFERS is validated only by the existence of flatbuffers/flatbuffers.h, but the runtime does not use FlatBuffers purely through its public API: src/brpc/flatbuffers/message.cpp reaches into builder internals (buf_, buf_.swap_allocator(), scratch_push_small(), string_pool, minalign_), and SlabAllocator asserts on the exact allocate()/reallocate_downward() size bookkeeping (only one live allocation, old_size == _capacity). Bazel pins 25.2.10 while CMake and config_brpc.sh accept any installed version, so with a different FlatBuffers an unsupported version fails deep in compilation or aborts inside the allocator. Please add a compile-time guard in src/brpc/flatbuffers/message.h (e.g. #if !defined(FLATBUFFERS_VERSION_MAJOR) || FLATBUFFERS_VERSION_MAJOR < X -> #error) and document the supported range, so users get a clear diagnostic instead of an obscure failure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this makes sense. The implementation depends on FlatBuffers builder internals, so accepting an arbitrary installed FlatBuffers version is too loose. I will add an explicit compile-time version guard in the public FlatBuffers message header and document the supported/tested version range in both docs. The goal is to fail early with a clear diagnostic instead of relying on an internal-layout compile error or allocator abort.

if(NOT FLATBUFFERS_INCLUDE_DIR)
message(FATAL_ERROR
"WITH_FLATBUFFERS requires FlatBuffers headers; set FLATBUFFERS_INCLUDE_DIR.")
endif()
set(WITH_FLATBUFFERS_VAL "1")
list(APPEND BRPC_COMMON_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR})
endif()

set(WITH_CPU_FREQUENCY_VAL "0")
if(WITH_CPU_FREQUENCY)
set(WITH_CPU_FREQUENCY_VAL "1")
Expand Down Expand Up @@ -177,6 +189,7 @@ endif()

list(APPEND BRPC_COMMON_DEFINITIONS
BRPC_WITH_GLOG=${WITH_GLOG_VAL}
BRPC_WITH_FLATBUFFERS=${WITH_FLATBUFFERS_VAL}
BRPC_WITH_RDMA=${WITH_RDMA_VAL}
BRPC_WITH_URMA=${WITH_URMA_VAL}
BRPC_WITH_UBRING=${WITH_UBRING_VAL}
Expand Down Expand Up @@ -670,6 +683,9 @@ file(GLOB_RECURSE BTHREAD_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/b
file(GLOB_RECURSE JSON2PB_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/json2pb/*.cpp")
file(GLOB_RECURSE BRPC_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/brpc/*.cpp")
file(GLOB_RECURSE THRIFT_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/brpc/thrift*.cpp")
if(NOT WITH_FLATBUFFERS)
list(FILTER BRPC_SOURCES EXCLUDE REGEX "/brpc/flatbuffers/.*\\.cpp$")
endif()
file(GLOB_RECURSE EXCLUDE_SOURCES CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/brpc/event_dispatcher_*.cpp")

# When building with the real liburma, exclude the link-time mock so its urma_*
Expand Down
16 changes: 16 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ git_repository(
remote = 'https://atomgit.com/openeuler/umdk.git',
commit = '564ee727a55523d4351a8fb3c94292b388ebb924', # v26.06.0_CAM
)

# Do not use `bazel_dep(name = 'flatbuffers', version = '25.2.10')` here.
# The BCR module pulls gRPC and JS/Go/Swift rule dependencies for FlatBuffers'
# full upstream build. bRPC only needs runtime_cc and flatc, and gRPC would
# otherwise introduce another BoringSSL version even when BRPC_WITH_FLATBUFFERS
# is false. Keep this archive and checksum in sync with WORKSPACE.
flatbuffers_http_archive = use_repo_rule(
'@bazel_tools//tools/build_defs/repo:http.bzl',
'http_archive',
)
flatbuffers_http_archive(
name = 'com_github_google_flatbuffers',
sha256 = 'b9c2df49707c57a48fc0923d52b8c73beb72d675f9d44b2211e4569be40a7421',
strip_prefix = 'flatbuffers-25.2.10',
urls = ['https://github.com/google/flatbuffers/archive/refs/tags/v25.2.10.tar.gz'],
)
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ JSON2PB_SOURCES = $(foreach d,$(JSON2PB_DIRS),$(wildcard $(addprefix $(d)/*,$(SR
JSON2PB_OBJS = $(addsuffix .o, $(basename $(JSON2PB_SOURCES)))

BRPC_DIRS = src/brpc src/brpc/details src/brpc/builtin src/brpc/policy src/brpc/policy/mysql src/brpc/rdma
ifeq ($(WITH_FLATBUFFERS),1)
BRPC_DIRS += src/brpc/flatbuffers
endif
ifeq ($(WITH_URMA),1)
BRPC_DIRS += src/brpc/urma
endif
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ http_archive(
urls = ["https://github.com/google/crc32c/archive/1.1.2.tar.gz"],
)

# Optional FlatBuffers support uses runtime_cc; keep this version in sync with MODULE.bazel.
http_archive(
name = "com_github_google_flatbuffers",
integrity = "sha256-ucLfSXB8V6SPwJI9UrjHO+ty1nX51EsiEeRWm+QKdCE=",
strip_prefix = "flatbuffers-25.2.10",
urls = ["https://github.com/google/flatbuffers/archive/refs/tags/v25.2.10.tar.gz"],
)

http_archive(
name = "com_github_google_glog", # 2021-05-07T23:06:39Z
patch_args = ["-p1"],
Expand Down
5 changes: 5 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#endif
#cmakedefine BRPC_WITH_GLOG @WITH_GLOG_VAL@

#ifdef BRPC_WITH_FLATBUFFERS
#undef BRPC_WITH_FLATBUFFERS
#endif
#define BRPC_WITH_FLATBUFFERS @WITH_FLATBUFFERS_VAL@

#ifdef BUTIL_USE_CPU_FREQUENCY
#undef BUTIL_USE_CPU_FREQUENCY
#endif
Expand Down
19 changes: 17 additions & 2 deletions config_brpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ else
LDD=ldd
fi

TEMP=`getopt -o v: --long headers:,libs:,cc:,cxx:,with-glog,with-thrift,with-rdma,with-urma,with-urma-mock,without-urma-mock,with-mesalink,with-bthread-tracer,with-debug-bthread-sche-safety,with-debug-lock,with-asan,with-riscv-zvbc,with-riscv-zbc,with-cpu-frequency,nodebugsymbols,werror -n 'config_brpc' -- "$@"`
TEMP=`getopt -o v: --long headers:,libs:,cc:,cxx:,with-glog,with-thrift,with-flatbuffers,with-rdma,with-urma,with-urma-mock,without-urma-mock,with-mesalink,with-bthread-tracer,with-debug-bthread-sche-safety,with-debug-lock,with-asan,with-riscv-zvbc,with-riscv-zbc,with-cpu-frequency,nodebugsymbols,werror -n 'config_brpc' -- "$@"`
WITH_GLOG=0
WITH_THRIFT=0
WITH_FLATBUFFERS=0
WITH_RDMA=0
WITH_URMA=0
URMA_MOCK_MODE=auto
Expand Down Expand Up @@ -91,6 +92,7 @@ while true; do
--cxx ) CXX=$2; shift 2 ;;
--with-glog ) WITH_GLOG=1; shift 1 ;;
--with-thrift) WITH_THRIFT=1; shift 1 ;;
--with-flatbuffers) WITH_FLATBUFFERS=1; shift 1 ;;
--with-rdma) WITH_RDMA=1; shift 1 ;;
--with-urma) WITH_URMA=1; shift 1 ;;
--with-urma-mock) URMA_MOCK_MODE=on; shift 1 ;;
Expand Down Expand Up @@ -479,14 +481,15 @@ append_to_output "HDRS=$($ECHO $HDRS)"
append_to_output "LIBS=$($ECHO $LIBS)"
append_to_output "PROTOC=$PROTOC"
append_to_output "PROTOBUF_HDR=$PROTOBUF_HDR"
append_to_output "WITH_FLATBUFFERS=$WITH_FLATBUFFERS"
append_to_output "CC=$CC"
append_to_output "CXX=$CXX"
append_to_output "GCC_VERSION=$GCC_VERSION"
append_to_output "STATIC_LINKINGS=$STATIC_LINKINGS"
append_to_output "DYNAMIC_LINKINGS=$DYNAMIC_LINKINGS"

# CPP means C PreProcessing, not C PlusPlus
CPPFLAGS="${CPPFLAGS} -DBRPC_WITH_GLOG=$WITH_GLOG -DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=$BRPC_DEBUG_BTHREAD_SCHE_SAFETY -DBRPC_DEBUG_LOCK=$BRPC_DEBUG_LOCK -DBUTIL_USE_CPU_FREQUENCY=$WITH_CPU_FREQUENCY"
CPPFLAGS="${CPPFLAGS} -DBRPC_WITH_GLOG=$WITH_GLOG -DBRPC_WITH_FLATBUFFERS=$WITH_FLATBUFFERS -DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=$BRPC_DEBUG_BTHREAD_SCHE_SAFETY -DBRPC_DEBUG_LOCK=$BRPC_DEBUG_LOCK -DBUTIL_USE_CPU_FREQUENCY=$WITH_CPU_FREQUENCY"

# Avoid over-optimizations of TLS variables by GCC>=4.8
# See: https://github.com/apache/brpc/issues/1693
Expand All @@ -506,6 +509,12 @@ if [ "$SYSTEM" = "Darwin" ]; then
fi
fi

if [ $WITH_FLATBUFFERS != 0 ]; then
FLATBUFFERS_HDR=$(find_dir_of_header_or_die flatbuffers/flatbuffers.h) || exit 1
append_to_output_headers "$FLATBUFFERS_HDR"
print_success "Found FlatBuffers headers: $FLATBUFFERS_HDR"
fi

if [ $WITH_THRIFT != 0 ]; then
THRIFT_LIB=$(find_dir_of_lib_or_die thriftnb)
THRIFT_HDR=$(find_dir_of_header_or_die thrift/Thrift.h)
Expand Down Expand Up @@ -692,6 +701,11 @@ cat << EOF > src/butil/config.h
#endif
#define BRPC_WITH_GLOG $WITH_GLOG

#ifdef BRPC_WITH_FLATBUFFERS
#undef BRPC_WITH_FLATBUFFERS
#endif
#define BRPC_WITH_FLATBUFFERS $WITH_FLATBUFFERS

#ifdef BUTIL_USE_CPU_FREQUENCY
#undef BUTIL_USE_CPU_FREQUENCY
#endif
Expand All @@ -714,6 +728,7 @@ print_info "C++ std: $CXXFLAGS"
print_info "System: $SYSTEM"
if [ $WITH_GLOG -ne 0 ]; then print_info "With glog: yes"; fi
if [ $WITH_THRIFT -ne 0 ]; then print_info "With thrift: yes"; fi
if [ $WITH_FLATBUFFERS -ne 0 ]; then print_info "With FlatBuffers: yes (headers only)"; fi
if [ $WITH_RDMA -ne 0 ]; then print_info "With RDMA: yes"; fi
if [ $WITH_URMA -ne 0 ]; then print_info "With URMA: yes"; fi
if [ $WITH_MESALINK -ne 0 ]; then print_info "With MesaLink: yes"; fi
Expand Down
Loading
Loading