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
28 changes: 28 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ DEFINES = [
}) + select({
"//bazel/config:brpc_with_rdma": ["BRPC_WITH_RDMA=1"],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_iouring": ["BRPC_WITH_IOURING=1"],
"//conditions:default": ["BRPC_WITH_IOURING=0"],
}) + select({
"//bazel/config:brpc_with_debug_bthread_sche_safety": ["BRPC_DEBUG_BTHREAD_SCHE_SAFETY=1"],
"//conditions:default": ["BRPC_DEBUG_BTHREAD_SCHE_SAFETY=0"],
Expand Down Expand Up @@ -94,6 +97,11 @@ LINKOPTS = [
"-libverbs",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_iouring": [
"-luring",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_asan": ["-fsanitize=address"],
"//conditions:default": [],
Expand Down Expand Up @@ -530,18 +538,33 @@ cc_library(
"src/brpc/policy/thrift_protocol.cpp",
"src/brpc/event_dispatcher_epoll.cpp",
"src/brpc/event_dispatcher_kqueue.cpp",
"src/brpc/iouring/*.cpp",
# Exclude pre-generated .pb.cc files; Bazel regenerates them via
# brpc_internal_cc_proto / brpc_idl_options_cc_proto using protoc 27.x.
"src/brpc/*.pb.cc",
"src/brpc/**/*.pb.cc",
]) + select({
"//bazel/config:brpc_with_thrift": glob([
"src/brpc/thrift*.cpp",
"src/brpc/**/thrift*.cpp",
]),
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_iouring": glob([
"src/brpc/iouring/*.cpp",
]),
"//conditions:default": [],
Comment on lines +552 to +556
}),
hdrs = glob([
"src/brpc/*.h",
"src/brpc/**/*.h",
"src/brpc/event_dispatcher_epoll.cpp",
"src/brpc/event_dispatcher_kqueue.cpp",
], exclude = [
# Exclude pre-generated .pb.h files; Bazel uses the ones regenerated by
# brpc_internal_cc_proto / brpc_idl_options_cc_proto (protoc 27.x).
"src/brpc/*.pb.h",
"src/brpc/**/*.pb.h",
]),
copts = COPTS,
includes = [
Expand All @@ -562,6 +585,11 @@ cc_library(
"@org_apache_thrift//:thrift",
],
"//conditions:default": [],
}) + select({
"//bazel/config:brpc_with_iouring": [
"@com_github_axboe_liburing//:liburing",
],
"//conditions:default": [],
}),
)

Expand Down
48 changes: 47 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(WITH_THRIFT "With thrift framed protocol supported" OFF)
option(WITH_BTHREAD_TRACER "With bthread tracer supported" OFF)
option(WITH_SNAPPY "With snappy" OFF)
option(WITH_RDMA "With RDMA" OFF)
option(WITH_IOURING "With io_uring" OFF)
option(WITH_DEBUG_BTHREAD_SCHE_SAFETY "With debugging bthread sche safety" OFF)
option(WITH_DEBUG_LOCK "With debugging lock" OFF)
option(WITH_ASAN "With AddressSanitizer" OFF)
Expand Down Expand Up @@ -104,6 +105,11 @@ if(WITH_RDMA)
set(WITH_RDMA_VAL "1")
endif()

set(WITH_IOURING_VAL "0")
if(WITH_IOURING)
set(WITH_IOURING_VAL "1")
endif()

set(WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL "0")
if(WITH_DEBUG_BTHREAD_SCHE_SAFETY)
set(WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL "1")
Expand Down Expand Up @@ -136,7 +142,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -Wno-deprecated-declarations -Wno-inconsistent-missing-override")
endif()

set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEFINE_CLOCK_GETTIME} -DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DBRPC_WITH_RDMA=${WITH_RDMA_VAL} -DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=${WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL} -DBRPC_DEBUG_LOCK=${WITH_DEBUG_LOCK_VAL}")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEFINE_CLOCK_GETTIME} -DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DBRPC_WITH_RDMA=${WITH_RDMA_VAL} -DBRPC_WITH_IOURING=${WITH_IOURING_VAL} -DBRPC_DEBUG_BTHREAD_SCHE_SAFETY=${WITH_DEBUG_BTHREAD_SCHE_SAFETY_VAL} -DBRPC_DEBUG_LOCK=${WITH_DEBUG_LOCK_VAL}")
if (WITH_ASAN)
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -fsanitize=address")
set(CMAKE_C_FLAGS "${CMAKE_CPP_FLAGS} -fsanitize=address")
Expand Down Expand Up @@ -277,6 +283,41 @@ if(WITH_RDMA)
endif()
endif()

if(WITH_IOURING)
message("brpc compile with io_uring")
# Search for the header in standard paths and common source-tree locations.
find_path(IOURING_INCLUDE_PATH NAMES liburing.h
PATHS
/usr/include
/usr/local/include
/docker/root/projects/liburing/src/include
NO_DEFAULT_PATH)
if(NOT IOURING_INCLUDE_PATH)
find_path(IOURING_INCLUDE_PATH NAMES liburing.h)
endif()

find_library(IOURING_LIB NAMES uring liburing.a
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/docker/root/projects/liburing/src
NO_DEFAULT_PATH)
if(NOT IOURING_LIB)
find_library(IOURING_LIB NAMES uring)
endif()

if((NOT IOURING_INCLUDE_PATH) OR (NOT IOURING_LIB))
message(FATAL_ERROR "Fail to find liburing. "
"Please install liburing-dev / liburing-devel, or "
"build from source at https://github.com/axboe/liburing "
"and set CMAKE_PREFIX_PATH accordingly.")
endif()
include_directories(${IOURING_INCLUDE_PATH})
message(STATUS "Found liburing: include=${IOURING_INCLUDE_PATH} lib=${IOURING_LIB}")
endif()

find_library(PROTOC_LIB NAMES protoc)
if(NOT PROTOC_LIB)
message(FATAL_ERROR "Fail to find protoc lib")
Expand Down Expand Up @@ -329,6 +370,11 @@ if(WITH_RDMA)
list(APPEND DYNAMIC_LIB ${RDMA_LIB})
endif()

if(WITH_IOURING)
list(APPEND DYNAMIC_LIB ${IOURING_LIB})
set(BRPC_PRIVATE_LIBS "${BRPC_PRIVATE_LIBS} -luring")
endif()

set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz")
Comment on lines +373 to 378

if(WITH_GLOG)
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bazel_dep(name = 'platforms', version = '0.0.4')
bazel_dep(name = "apple_support", version = "1.17.1")
bazel_dep(name = 'rules_cc', version = '0.0.1')
bazel_dep(name = 'rules_proto', version = '4.0.0')
bazel_dep(name = 'rules_foreign_cc', version = '0.12.0')
bazel_dep(name = 'zlib', version = '1.3.1.bcr.5', repo_name = 'com_github_madler_zlib')
bazel_dep(name = 'babylon', version = '1.4.4')
# --registry=https://raw.githubusercontent.com/apache/brpc/master/registry
Expand Down
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ http_archive(
urls = ["https://archive.apache.org/dist/thrift/0.15.0/thrift-0.15.0.tar.gz"],
)

# io_uring support. Enable with: --define=BRPC_WITH_IOURING=true
http_archive(
name = "com_github_axboe_liburing",
build_file = "//bazel/third_party/liburing:liburing.BUILD",
sha256 = "5f80964108981c6ad979c735f0b4877d5f49914c2a062f8e88282f26bf61de0c",
strip_prefix = "liburing-liburing-2.14",
urls = ["https://github.com/axboe/liburing/archive/refs/tags/liburing-2.14.tar.gz"],
)

#
# Perl Dependencies
#
Expand Down
19 changes: 19 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# In Bzlmod mode (MODULE.bazel), Bazel reads this file instead of WORKSPACE
# for any legacy http_archive / new_local_repository declarations that are not
# yet available in a Bazel registry.
#
# rules_foreign_cc is declared in MODULE.bazel (bazel_dep) and is available
# as @rules_foreign_cc in Bzlmod mode -- no need to re-declare it here.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# io_uring support. Enable with: --define=BRPC_WITH_IOURING=true
# liburing is built from source via configure+make (compat.h is generated by
# configure and is not present in the tarball).
http_archive(
name = "com_github_axboe_liburing",
build_file = "//bazel/third_party/liburing:liburing.BUILD",
sha256 = "5f80964108981c6ad979c735f0b4877d5f49914c2a062f8e88282f26bf61de0c",
strip_prefix = "liburing-liburing-2.14",
urls = ["https://github.com/axboe/liburing/archive/refs/tags/liburing-2.14.tar.gz"],
)
6 changes: 6 additions & 0 deletions bazel/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ config_setting(
visibility = ["//visibility:public"],
)

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

config_setting(
name = "brpc_with_boringssl",
define_values = {"BRPC_WITH_BORINGSSL": "true"},
Expand Down
2 changes: 2 additions & 0 deletions bazel/third_party/liburing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This package exists solely to expose liburing.BUILD as a build_file label
# for the com_github_axboe_liburing http_archive rule.
39 changes: 39 additions & 0 deletions bazel/third_party/liburing/liburing.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.

# BUILD file for liburing (io_uring userspace library).
# Uses rules_foreign_cc to run liburing's ./configure + make, which is required
# because compat.h (providing __kernel_timespec on older kernels) is generated
# by the configure script and is not present in the source tarball.

load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

licenses(["notice"]) # MIT / GPL-2.0-only (dual-licensed)

filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)

configure_make(
name = "liburing",
configure_command = "configure",
configure_in_place = True,
lib_source = ":all_srcs",
# Build only the library (skip test/ and examples/) then install.
targets = ["library", "install"],
out_static_libs = ["liburing.a"],
visibility = ["//visibility:public"],
)
Loading