From d56f48c57216d11ebb175c0367b2abf0329e23ae Mon Sep 17 00:00:00 2001 From: Dongsheng He Date: Wed, 27 Sep 2023 00:00:42 +0800 Subject: [PATCH 1/8] support boringssl --- CMakeLists.txt | 24 +- example/http_c++/CMakeLists.txt | 29 ++- example/http_c++/Makefile | 390 +++++++++++++++++++++++--------- src/brpc/details/ssl_helper.cpp | 31 +-- src/brpc/server.cpp | 3 +- src/brpc/server.h | 2 +- src/butil/iobuf.cpp | 33 ++- src/butil/ssl_compat.h | 4 +- test/CMakeLists.txt | 6 +- 9 files changed, 382 insertions(+), 140 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66cc015783..2c2c72fa0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,13 +127,13 @@ set(CMAKE_C_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing macro(use_cxx11) if(CMAKE_VERSION VERSION_LESS "3.1.3") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") endif() else() - set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() endmacro(use_cxx11) @@ -205,13 +205,18 @@ if(NOT PROTOC_LIB) message(FATAL_ERROR "Fail to find protoc lib") endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(OPENSSL_ROOT_DIR - "/usr/local/opt/openssl" # Homebrew installed OpenSSL - ) -endif() +#if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") +# set(OPENSSL_ROOT_DIR +# "/usr/local/opt/openssl" # Homebrew installed OpenSSL +# ) +#endif() + +#find_package(OpenSSL) -find_package(OpenSSL) +set(OPENSSL_INCLUDE_DIR /home/boringssl/include) +find_library(OPENSSL_CRYPTO_LIBRARY NAMES libcrypto.a HINTS /home/boringssl/build/crypto/) +find_library(OPENSSL_SSL_LIBRARY NAMES libssl.a HINTS /home/boringssl/build/ssl/) +message("----OPENSSL_CRYPTO_LIBRARY: ${OPENSSL_SSL_LIBRARY}") include_directories( ${GFLAGS_INCLUDE_PATH} @@ -241,6 +246,7 @@ if(WITH_RDMA) list(APPEND DYNAMIC_LIB ${RDMA_LIB}) endif() +message("----+++++ ${DYNAMIC_LIB}") set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz") if(WITH_GLOG) diff --git a/example/http_c++/CMakeLists.txt b/example/http_c++/CMakeLists.txt index 8d0507d2a5..4b56c80e78 100644 --- a/example/http_c++/CMakeLists.txt +++ b/example/http_c++/CMakeLists.txt @@ -40,9 +40,10 @@ if (NOT THRIFT_LIB) set(THRIFT_LIB "") endif() -find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h) -find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler) +find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h PATHS /home/gperftools/src) +find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler PATHS /home/gperftools/build) include_directories(${GPERFTOOLS_INCLUDE_DIR}) +message("---- ${GPERFTOOLS_LIBRARIES}") find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h) if(LINK_SO) @@ -87,13 +88,13 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER") if(CMAKE_VERSION VERSION_LESS "3.1.3") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") endif() else() - set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() @@ -104,13 +105,19 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB)) endif() include_directories(${LEVELDB_INCLUDE_PATH}) -if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(OPENSSL_ROOT_DIR - "/usr/local/opt/openssl" # Homebrew installed OpenSSL - ) -endif() +#if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") +# set(OPENSSL_ROOT_DIR +# "/usr/local/opt/openssl" # Homebrew installed OpenSSL +# ) +#endif() + +#find_package(OpenSSL) + + +set(OPENSSL_INCLUDE_DIR /home/boringssl/include) +find_library(OPENSSL_CRYPTO_LIBRARY NAMES libcrypto.a PATHS /home/boringssl/build/crypto) +find_library(OPENSSL_SSL_LIBRARY NAMES libssl.a PATHS /home/boringssl/build/ssl) -find_package(OpenSSL) include_directories(${OPENSSL_INCLUDE_DIR}) diff --git a/example/http_c++/Makefile b/example/http_c++/Makefile index 515456559b..8dd946da74 100644 --- a/example/http_c++/Makefile +++ b/example/http_c++/Makefile @@ -1,102 +1,290 @@ -# 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. - -NEED_GPERFTOOLS=1 -BRPC_PATH=../../ -include $(BRPC_PATH)/config.mk -# Notes on the flags: -# 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default -CXXFLAGS+=$(CPPFLAGS) -std=c++0x -DNDEBUG -O2 -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer -ifeq ($(NEED_GPERFTOOLS), 1) - CXXFLAGS+=-DBRPC_ENABLE_CPU_PROFILER -endif -HDRS+=$(BRPC_PATH)/output/include -LIBS+=$(BRPC_PATH)/output/lib -HDRPATHS = $(addprefix -I, $(HDRS)) -LIBPATHS = $(addprefix -L, $(LIBS)) -COMMA=, -SOPATHS=$(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS)) - -CLIENT_SOURCES = http_client.cpp -BENCHMARK_SOURCES = benchmark_http.cpp -SERVER_SOURCES = http_server.cpp -PROTOS = http.proto - -PROTO_OBJS = $(PROTOS:.proto=.pb.o) -PROTO_GENS = $(PROTOS:.proto=.pb.h) $(PROTOS:.proto=.pb.cc) -CLIENT_OBJS = $(addsuffix .o, $(basename $(CLIENT_SOURCES))) -BENCHMARK_OBJS = $(addsuffix .o, $(basename $(BENCHMARK_SOURCES))) -SERVER_OBJS = $(addsuffix .o, $(basename $(SERVER_SOURCES))) - -ifeq ($(SYSTEM),Darwin) - ifneq ("$(LINK_SO)", "") - STATIC_LINKINGS += -lbrpc - else - # *.a must be explicitly specified in clang - STATIC_LINKINGS += $(BRPC_PATH)/output/lib/libbrpc.a - endif - LINK_OPTIONS_SO = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) - LINK_OPTIONS = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -else ifeq ($(SYSTEM),Linux) - STATIC_LINKINGS += -lbrpc - LINK_OPTIONS_SO = -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) - LINK_OPTIONS = -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -endif - -.PHONY:all -all: http_client benchmark_http http_server - -.PHONY:clean +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.26 + +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + +# Disable VCS-based implicit rules. +% : %,v + +# Disable VCS-based implicit rules. +% : RCS/% + +# Disable VCS-based implicit rules. +% : RCS/%,v + +# Disable VCS-based implicit rules. +% : SCCS/s.% + +# Disable VCS-based implicit rules. +% : s.% + +.SUFFIXES: .hpux_make_needs_suffix_list + +# Command-line flag to silence nested $(MAKE). +$(VERBOSE)MAKESILENT = -s + +#Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E rm -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/brpc/example/http_c++ + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/brpc/example/http_c++ + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." + /usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/brpc/example/http_c++/CMakeFiles /home/brpc/example/http_c++//CMakeFiles/progress.marks + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/brpc/example/http_c++/CMakeFiles 0 +.PHONY : all + +# The main clean target clean: - @echo "> Cleaning" - rm -rf http_client benchmark_http http_server $(PROTO_GENS) $(PROTO_OBJS) $(CLIENT_OBJS) $(BENCHMARK_OBJS) $(SERVER_OBJS) - -http_client:$(CLIENT_OBJS) - @echo "> Linking $@" -ifneq ("$(LINK_SO)", "") - $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@ -else - $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@ -endif - -benchmark_http:$(BENCHMARK_OBJS) - @echo "> Linking $@" -ifneq ("$(LINK_SO)", "") - $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@ -else - $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@ -endif - -http_server:$(PROTO_OBJS) $(SERVER_OBJS) - @echo "> Linking $@" -ifneq ("$(LINK_SO)", "") - $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@ -else - $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@ -endif - -%.pb.cc %.pb.h:%.proto - @echo "> Generating $@" - $(PROTOC) --cpp_out=. --proto_path=. $< - -%.o:%.cpp - @echo "> Compiling $@" - $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ - -%.o:%.cc - @echo "> Compiling $@" - $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named http_client + +# Build rule for target. +http_client: cmake_check_build_system + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 http_client +.PHONY : http_client + +# fast build rule for target. +http_client/fast: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/build +.PHONY : http_client/fast + +#============================================================================= +# Target rules for targets named http_server + +# Build rule for target. +http_server: cmake_check_build_system + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 http_server +.PHONY : http_server + +# fast build rule for target. +http_server/fast: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/build +.PHONY : http_server/fast + +#============================================================================= +# Target rules for targets named benchmark_http + +# Build rule for target. +benchmark_http: cmake_check_build_system + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 benchmark_http +.PHONY : benchmark_http + +# fast build rule for target. +benchmark_http/fast: + $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/build +.PHONY : benchmark_http/fast + +benchmark_http.o: benchmark_http.cpp.o +.PHONY : benchmark_http.o + +# target to build an object file +benchmark_http.cpp.o: + $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/benchmark_http.cpp.o +.PHONY : benchmark_http.cpp.o + +benchmark_http.i: benchmark_http.cpp.i +.PHONY : benchmark_http.i + +# target to preprocess a source file +benchmark_http.cpp.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/benchmark_http.cpp.i +.PHONY : benchmark_http.cpp.i + +benchmark_http.s: benchmark_http.cpp.s +.PHONY : benchmark_http.s + +# target to generate assembly for a file +benchmark_http.cpp.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/benchmark_http.cpp.s +.PHONY : benchmark_http.cpp.s + +http.pb.o: http.pb.cc.o +.PHONY : http.pb.o + +# target to build an object file +http.pb.cc.o: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http.pb.cc.o +.PHONY : http.pb.cc.o + +http.pb.i: http.pb.cc.i +.PHONY : http.pb.i + +# target to preprocess a source file +http.pb.cc.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http.pb.cc.i +.PHONY : http.pb.cc.i + +http.pb.s: http.pb.cc.s +.PHONY : http.pb.s + +# target to generate assembly for a file +http.pb.cc.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http.pb.cc.s +.PHONY : http.pb.cc.s + +http_client.o: http_client.cpp.o +.PHONY : http_client.o + +# target to build an object file +http_client.cpp.o: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/http_client.cpp.o +.PHONY : http_client.cpp.o + +http_client.i: http_client.cpp.i +.PHONY : http_client.i + +# target to preprocess a source file +http_client.cpp.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/http_client.cpp.i +.PHONY : http_client.cpp.i + +http_client.s: http_client.cpp.s +.PHONY : http_client.s + +# target to generate assembly for a file +http_client.cpp.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/http_client.cpp.s +.PHONY : http_client.cpp.s + +http_server.o: http_server.cpp.o +.PHONY : http_server.o + +# target to build an object file +http_server.cpp.o: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http_server.cpp.o +.PHONY : http_server.cpp.o + +http_server.i: http_server.cpp.i +.PHONY : http_server.i + +# target to preprocess a source file +http_server.cpp.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http_server.cpp.i +.PHONY : http_server.cpp.i + +http_server.s: http_server.cpp.s +.PHONY : http_server.s + +# target to generate assembly for a file +http_server.cpp.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http_server.cpp.s +.PHONY : http_server.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... rebuild_cache" + @echo "... benchmark_http" + @echo "... http_client" + @echo "... http_server" + @echo "... benchmark_http.o" + @echo "... benchmark_http.i" + @echo "... benchmark_http.s" + @echo "... http.pb.o" + @echo "... http.pb.i" + @echo "... http.pb.s" + @echo "... http_client.o" + @echo "... http_client.i" + @echo "... http_client.s" + @echo "... http_server.o" + @echo "... http_server.i" + @echo "... http_server.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/src/brpc/details/ssl_helper.cpp b/src/brpc/details/ssl_helper.cpp index 81460aa99c..e02d7f9182 100644 --- a/src/brpc/details/ssl_helper.cpp +++ b/src/brpc/details/ssl_helper.cpp @@ -212,7 +212,7 @@ void ExtractHostnames(X509* x, std::vector* hostnames) { STACK_OF(GENERAL_NAME)* names = (STACK_OF(GENERAL_NAME)*) X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL); if (names) { - for (int i = 0; i < sk_GENERAL_NAME_num(names); i++) { + for (size_t i = 0; i < sk_GENERAL_NAME_num(names); i++) { char* str = NULL; GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i); if (name->type == GEN_DNS) { @@ -590,19 +590,24 @@ SSL* CreateSSLSession(SSL_CTX* ctx, SocketId id, int fd, bool server_mode) { return ssl; } +// void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { +// BIO* rbio = BIO_new(BIO_f_buffer()); +// BIO_set_buffer_size(rbio, bufsize); +// BIO* rfd = BIO_new(BIO_s_fd()); +// BIO_set_fd(rfd, fd, 0); +// rbio = BIO_push(rbio, rfd); + +// BIO* wbio = BIO_new(BIO_f_buffer()); +// BIO_set_buffer_size(wbio, bufsize); +// BIO* wfd = BIO_new(BIO_s_fd()); +// BIO_set_fd(wfd, fd, 0); +// wbio = BIO_push(wbio, wfd); +// SSL_set_bio(ssl, rbio, wbio); +// } + void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { - BIO* rbio = BIO_new(BIO_f_buffer()); - BIO_set_buffer_size(rbio, bufsize); - BIO* rfd = BIO_new(BIO_s_fd()); - BIO_set_fd(rfd, fd, 0); - rbio = BIO_push(rbio, rfd); - - BIO* wbio = BIO_new(BIO_f_buffer()); - BIO_set_buffer_size(wbio, bufsize); - BIO* wfd = BIO_new(BIO_s_fd()); - BIO_set_fd(wfd, fd, 0); - wbio = BIO_push(wbio, wfd); - SSL_set_bio(ssl, rbio, wbio); + BIO *bio = BIO_new_socket(fd, BIO_CLOSE); + SSL_set_bio(ssl, bio, bio); } SSLState DetectSSLState(int fd, int* error_code) { diff --git a/src/brpc/server.cpp b/src/brpc/server.cpp index c25cd5f001..99add51976 100644 --- a/src/brpc/server.cpp +++ b/src/brpc/server.cpp @@ -2246,8 +2246,9 @@ bool Server::AcceptRequest(Controller* cntl) const { #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME int Server::SSLSwitchCTXByHostname(struct ssl_st* ssl, - int* al, Server* server) { + int* al, void* se) { (void)al; + Server* server = reinterpret_cast(se); const char* hostname = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); bool strict_sni = server->_options.ssl_options().strict_sni; if (hostname == NULL) { diff --git a/src/brpc/server.h b/src/brpc/server.h index 982c6701f1..c2ba87d821 100644 --- a/src/brpc/server.h +++ b/src/brpc/server.h @@ -660,7 +660,7 @@ friend class Controller; void FreeSSLContexts(); static int SSLSwitchCTXByHostname(struct ssl_st* ssl, - int* al, Server* server); + int* al, void* se); static bool AddCertMapping(CertMaps& bg, const SSLContext& ssl_ctx); static bool RemoveCertMapping(CertMaps& bg, const SSLContext& ssl_ctx); diff --git a/src/butil/iobuf.cpp b/src/butil/iobuf.cpp index b585c92c8e..8c2fccffa9 100644 --- a/src/butil/iobuf.cpp +++ b/src/butil/iobuf.cpp @@ -37,10 +37,41 @@ #include "butil/logging.h" // CHECK, LOG #include "butil/fd_guard.h" // butil::fd_guard #include "butil/iobuf.h" - +static int BIO_fd_non_fatal_error(int err) { + if ( +#ifdef EWOULDBLOCK + err == EWOULDBLOCK || +#endif +#ifdef WSAEWOULDBLOCK + err == WSAEWOULDBLOCK || +#endif +#ifdef ENOTCONN + err == ENOTCONN || +#endif +#ifdef EINTR + err == EINTR || +#endif +#ifdef EAGAIN + err == EAGAIN || +#endif +#ifdef EPROTO + err == EPROTO || +#endif +#ifdef EINPROGRESS + err == EINPROGRESS || +#endif +#ifdef EALREADY + err == EALREADY || +#endif + 0) { + return 1; + } + return 0; +} namespace butil { namespace iobuf { + typedef ssize_t (*iov_function)(int fd, const struct iovec *vector, int count, off_t offset); diff --git a/src/butil/ssl_compat.h b/src/butil/ssl_compat.h index 370edb0294..8881bf3ae0 100644 --- a/src/butil/ssl_compat.h +++ b/src/butil/ssl_compat.h @@ -324,7 +324,7 @@ BRPC_INLINE int RSA_bits(const RSA *r) { #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */ -#if OPENSSL_VERSION_NUMBER < 0x0090801fL +#if OPENSSL_VERSION_NUMBER < 0x0090801fL || defined (BORINGSSL_API_VERSION) BRPC_INLINE BIGNUM* get_rfc2409_prime_1024(BIGNUM* bn) { static const unsigned char RFC2409_PRIME_1024[] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC9,0x0F,0xDA,0xA2, @@ -516,6 +516,6 @@ BRPC_INLINE int EVP_PKEY_base_id(const EVP_PKEY *pkey) { return EVP_PKEY_type(pkey->type); } -#endif /* OPENSSL_VERSION_NUMBER < 0x0090801fL */ +#endif /* OPENSSL_VERSION_NUMBER < 0x0090801fL || BORINGSSL_API_VERSION */ #endif /* BUTIL_SSL_COMPAT_H */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9720a0fabe..7dc4558adc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,7 +15,10 @@ # specific language governing permissions and limitations # under the License. -find_package(Gperftools) +find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h PATHS /home/gperftools/src) +find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler PATHS /home/gperftools/build) +include_directories(${GPERFTOOLS_INCLUDE_DIR}) + include_directories(${GPERFTOOLS_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) @@ -188,6 +191,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-Wl,-U,_bthread_key_create") endif() +message("---- ${DYNAMIC_LIB}") add_library(BUTIL_DEBUG_LIB OBJECT ${BUTIL_SOURCES}) add_library(SOURCES_DEBUG_LIB OBJECT ${SOURCES}) add_dependencies(SOURCES_DEBUG_LIB PROTO_LIB) From 6a59cdc32377a83f11d68314ea83f9dd81fe69e8 Mon Sep 17 00:00:00 2001 From: ehds Date: Wed, 27 Sep 2023 13:38:15 +0800 Subject: [PATCH 2/8] add CMakeLists --- CMakeLists.txt | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c2c72fa0d..92990cbc3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ project(brpc C CXX) option(WITH_GLOG "With glog" OFF) option(WITH_MESALINK "With MesaLink" OFF) +option(WITH_BORINGSSL "With BoringSSL" OFF) option(DEBUG "Print debug logs" OFF) option(WITH_DEBUG_SYMBOLS "With debug symbols" ON) option(WITH_THRIFT "With thrift framed protocol supported" OFF) @@ -205,24 +206,24 @@ if(NOT PROTOC_LIB) message(FATAL_ERROR "Fail to find protoc lib") endif() -#if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") -# set(OPENSSL_ROOT_DIR -# "/usr/local/opt/openssl" # Homebrew installed OpenSSL -# ) -#endif() - -#find_package(OpenSSL) +if(WITH_BORINGSSL) + find_package(BoringSSL) + include_directories(${BORINGSSL_INCLUDE_DIR}) +else() + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(OPENSSL_ROOT_DIR + "/usr/local/opt/openssl" # Homebrew installed OpenSSL + ) + endif() -set(OPENSSL_INCLUDE_DIR /home/boringssl/include) -find_library(OPENSSL_CRYPTO_LIBRARY NAMES libcrypto.a HINTS /home/boringssl/build/crypto/) -find_library(OPENSSL_SSL_LIBRARY NAMES libssl.a HINTS /home/boringssl/build/ssl/) -message("----OPENSSL_CRYPTO_LIBRARY: ${OPENSSL_SSL_LIBRARY}") + find_package(OpenSSL) + include_directories(${OPENSSL_INCLUDE_DIR}) +endif() include_directories( ${GFLAGS_INCLUDE_PATH} ${PROTOBUF_INCLUDE_DIRS} ${LEVELDB_INCLUDE_PATH} - ${OPENSSL_INCLUDE_DIR} ) set(DYNAMIC_LIB @@ -232,21 +233,27 @@ set(DYNAMIC_LIB ${PROTOC_LIB} ${CMAKE_THREAD_LIBS_INIT} ${THRIFT_LIB} - ${OPENSSL_CRYPTO_LIBRARY} dl z) -if(WITH_MESALINK) - list(APPEND DYNAMIC_LIB ${MESALINK_LIB}) +if(WITH_BORINGSSL) + list(APPEND DYNAMIC_LIB ${BORINGSSL_SSL_LIBRARY}) + list(APPEND DYNAMIC_LIB ${BORINGSSL_CRYPTO_LIBRARY}) else() - list(APPEND DYNAMIC_LIB ${OPENSSL_SSL_LIBRARY}) + list(APPEND DYNAMIC_LIB ${OPENSSL_CRYPTO_LIBRARY}) + + if(WITH_MESALINK) + list(APPEND DYNAMIC_LIB ${MESALINK_LIB}) + else() + list(APPEND DYNAMIC_LIB ${OPENSSL_SSL_LIBRARY}) + endif() endif() if(WITH_RDMA) list(APPEND DYNAMIC_LIB ${RDMA_LIB}) endif() -message("----+++++ ${DYNAMIC_LIB}") + set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz") if(WITH_GLOG) From 3fc765c21cac1897833e65c2a65570a15b020874 Mon Sep 17 00:00:00 2001 From: Dongsheng He Date: Wed, 27 Sep 2023 14:19:51 +0800 Subject: [PATCH 3/8] fix --- CMakeLists.txt | 1 - src/brpc/details/ssl_helper.cpp | 37 ++++++++++++++++--------------- src/butil/iobuf.cpp | 35 +++-------------------------- src/butil/ssl_compat.h | 39 ++++++++++++++++++++++++++++++--- test/CMakeLists.txt | 1 - 5 files changed, 58 insertions(+), 55 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92990cbc3e..f3fbaae860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -253,7 +253,6 @@ if(WITH_RDMA) list(APPEND DYNAMIC_LIB ${RDMA_LIB}) endif() - set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz") if(WITH_GLOG) diff --git a/src/brpc/details/ssl_helper.cpp b/src/brpc/details/ssl_helper.cpp index e02d7f9182..7373a024c6 100644 --- a/src/brpc/details/ssl_helper.cpp +++ b/src/brpc/details/ssl_helper.cpp @@ -17,6 +17,7 @@ +#include #ifndef USE_MESALINK #include // recv @@ -212,7 +213,7 @@ void ExtractHostnames(X509* x, std::vector* hostnames) { STACK_OF(GENERAL_NAME)* names = (STACK_OF(GENERAL_NAME)*) X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL); if (names) { - for (size_t i = 0; i < sk_GENERAL_NAME_num(names); i++) { + for (size_t i = 0; i < static_cast(sk_GENERAL_NAME_num(names)); i++) { char* str = NULL; GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i); if (name->type == GEN_DNS) { @@ -590,26 +591,26 @@ SSL* CreateSSLSession(SSL_CTX* ctx, SocketId id, int fd, bool server_mode) { return ssl; } -// void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { -// BIO* rbio = BIO_new(BIO_f_buffer()); -// BIO_set_buffer_size(rbio, bufsize); -// BIO* rfd = BIO_new(BIO_s_fd()); -// BIO_set_fd(rfd, fd, 0); -// rbio = BIO_push(rbio, rfd); - -// BIO* wbio = BIO_new(BIO_f_buffer()); -// BIO_set_buffer_size(wbio, bufsize); -// BIO* wfd = BIO_new(BIO_s_fd()); -// BIO_set_fd(wfd, fd, 0); -// wbio = BIO_push(wbio, wfd); -// SSL_set_bio(ssl, rbio, wbio); -// } - void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { - BIO *bio = BIO_new_socket(fd, BIO_CLOSE); - SSL_set_bio(ssl, bio, bio); + BIO* rbio = BIO_new(BIO_s_mem()); + //BIO_set_buffer_size(rbio, bufsize); + BIO* rfd = BIO_new(BIO_s_fd()); + BIO_set_fd(rfd, fd, 0); + rbio = BIO_push(rbio, rfd); + + BIO* wbio = BIO_new(BIO_s_mem()); + // BIO_set_buffer_size(wbio, bufsize); + BIO* wfd = BIO_new(BIO_s_fd()); + BIO_set_fd(wfd, fd, 0); + wbio = BIO_push(wbio, wfd); + SSL_set_bio(ssl, rbio, wbio); } +// void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { +// BIO *bio = BIO_new_socket(fd, BIO_CLOSE); +// SSL_set_bio(ssl, bio, bio); +// } + SSLState DetectSSLState(int fd, int* error_code) { // Peek the first few bytes inside socket to detect whether // it's an SSL connection. If it is, create an SSL session diff --git a/src/butil/iobuf.cpp b/src/butil/iobuf.cpp index 8c2fccffa9..06b1efbe67 100644 --- a/src/butil/iobuf.cpp +++ b/src/butil/iobuf.cpp @@ -37,41 +37,12 @@ #include "butil/logging.h" // CHECK, LOG #include "butil/fd_guard.h" // butil::fd_guard #include "butil/iobuf.h" -static int BIO_fd_non_fatal_error(int err) { - if ( -#ifdef EWOULDBLOCK - err == EWOULDBLOCK || -#endif -#ifdef WSAEWOULDBLOCK - err == WSAEWOULDBLOCK || -#endif -#ifdef ENOTCONN - err == ENOTCONN || -#endif -#ifdef EINTR - err == EINTR || -#endif -#ifdef EAGAIN - err == EAGAIN || -#endif -#ifdef EPROTO - err == EPROTO || -#endif -#ifdef EINPROGRESS - err == EINPROGRESS || -#endif -#ifdef EALREADY - err == EALREADY || -#endif - 0) { - return 1; - } - return 0; -} + +#include "butil/ssl_compat.h" // BIO_fd_non_fatal_error + namespace butil { namespace iobuf { - typedef ssize_t (*iov_function)(int fd, const struct iovec *vector, int count, off_t offset); diff --git a/src/butil/ssl_compat.h b/src/butil/ssl_compat.h index 8881bf3ae0..ce361a20b5 100644 --- a/src/butil/ssl_compat.h +++ b/src/butil/ssl_compat.h @@ -21,7 +21,7 @@ #include #include -/* Provide functions added in newer openssl but missing in older versions */ +/* Provide functions added in newer openssl but missing in older versions or boringssl */ #if defined(__cplusplus) || __STDC_VERSION__ >= 199901L/*C99*/ #define BRPC_INLINE inline @@ -324,7 +324,7 @@ BRPC_INLINE int RSA_bits(const RSA *r) { #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */ -#if OPENSSL_VERSION_NUMBER < 0x0090801fL || defined (BORINGSSL_API_VERSION) +#if OPENSSL_VERSION_NUMBER < 0x0090801fL || defined (OPENSSL_IS_BORINGSSL) BRPC_INLINE BIGNUM* get_rfc2409_prime_1024(BIGNUM* bn) { static const unsigned char RFC2409_PRIME_1024[] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC9,0x0F,0xDA,0xA2, @@ -516,6 +516,39 @@ BRPC_INLINE int EVP_PKEY_base_id(const EVP_PKEY *pkey) { return EVP_PKEY_type(pkey->type); } -#endif /* OPENSSL_VERSION_NUMBER < 0x0090801fL || BORINGSSL_API_VERSION */ +#endif /* OPENSSL_VERSION_NUMBER < 0x0090801fL || OPENSSL_IS_BORINGSSL */ +#if defined(OPENSSL_IS_BORINGSSL) +[[maybe_unused]] static int BIO_fd_non_fatal_error(int err) { + if ( +#ifdef EWOULDBLOCK + err == EWOULDBLOCK || +#endif +#ifdef WSAEWOULDBLOCK + err == WSAEWOULDBLOCK || +#endif +#ifdef ENOTCONN + err == ENOTCONN || +#endif +#ifdef EINTR + err == EINTR || +#endif +#ifdef EAGAIN + err == EAGAIN || +#endif +#ifdef EPROTO + err == EPROTO || +#endif +#ifdef EINPROGRESS + err == EINPROGRESS || +#endif +#ifdef EALREADY + err == EALREADY || +#endif + 0) { + return 1; + } + return 0; +} +#endif /*OPENSSL_IS_BORINGSSL*/ #endif /* BUTIL_SSL_COMPAT_H */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7dc4558adc..149541df9c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -191,7 +191,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-Wl,-U,_bthread_key_create") endif() -message("---- ${DYNAMIC_LIB}") add_library(BUTIL_DEBUG_LIB OBJECT ${BUTIL_SOURCES}) add_library(SOURCES_DEBUG_LIB OBJECT ${SOURCES}) add_dependencies(SOURCES_DEBUG_LIB PROTO_LIB) From 85ba921206710805734c335acbd78feb13fc92b9 Mon Sep 17 00:00:00 2001 From: Dongsheng He Date: Wed, 27 Sep 2023 23:51:48 +0800 Subject: [PATCH 4/8] suopport boring ssl bazel --- BUILD.bazel | 5 +++-- WORKSPACE | 9 ++++++++- bazel/config/BUILD.bazel | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 8848593a95..c2c82f9863 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -325,14 +325,15 @@ cc_library( "@com_github_gflags_gflags//:gflags", "@com_github_madler_zlib//:zlib", "@com_google_protobuf//:protobuf", - "@openssl//:crypto", - "@openssl//:ssl", ] + select({ "//bazel/config:brpc_with_glog": ["@com_github_google_glog//:glog"], "//conditions:default": [], }) + select({ "@bazel_tools//tools/osx:darwin": [":macos_lib"], "//conditions:default": [], + }) + select({ + "//bazel/config:brpc_with_boringssl": ["@boringssl//:ssl", "@boringssl//:crypto"], + "//conditions:default": ["@openssl//:ssl", "@openssl//:crypto"], }), ) diff --git a/WORKSPACE b/WORKSPACE index b6fda836d8..a107f0a52c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -18,6 +18,7 @@ workspace(name = "com_github_brpc_brpc") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") # # Constants @@ -252,7 +253,6 @@ Set-Content protobuf.bzl -Value $content -Encoding UTF8 urls = ["https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.19.1.tar.gz"], ) -# bRPC cannot use boringssl. Build openssl. http_archive( name = "openssl", # 2021-12-14T15:45:01Z build_file = "//bazel/third_party/openssl:openssl.BUILD", @@ -264,6 +264,13 @@ http_archive( ], ) +# https://github.com/google/boringssl/blob/master/INCORPORATING.md +git_repository( + name = "boringssl", # 2021-05-01T12:26:01Z + commit = "0e6b86549db4c888666512295c3ebd4fa2a402f5", # fips-20210429 + remote = "https://github.com/google/boringssl", +) + http_archive( name = "org_apache_thrift", # 2021-09-11T11:54:01Z build_file = "//bazel/third_party/thrift:thrift.BUILD", diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index 8b09826515..bed04d3b57 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -103,3 +103,9 @@ config_setting( define_values = {"BRPC_WITH_RDMA": "true"}, visibility = ["//visibility:public"], ) + +config_setting( + name = "brpc_with_boringssl", + define_values = {"BRPC_WITH_BORINGSSL": "true"}, + visibility = ["//visibility:public"], +) \ No newline at end of file From bdc662d13510ad279d55e944c1539ae8c5ac62c8 Mon Sep 17 00:00:00 2001 From: Dongsheng He Date: Thu, 28 Sep 2023 00:06:54 +0800 Subject: [PATCH 5/8] fix AddBioBuffer code --- example/http_c++/Makefile | 390 +++++++++----------------------- src/brpc/details/ssl_helper.cpp | 19 +- 2 files changed, 110 insertions(+), 299 deletions(-) diff --git a/example/http_c++/Makefile b/example/http_c++/Makefile index 8dd946da74..515456559b 100644 --- a/example/http_c++/Makefile +++ b/example/http_c++/Makefile @@ -1,290 +1,102 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.26 - -# Default target executed when no arguments are given to make. -default_target: all -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - -# Disable VCS-based implicit rules. -% : %,v - -# Disable VCS-based implicit rules. -% : RCS/% - -# Disable VCS-based implicit rules. -% : RCS/%,v - -# Disable VCS-based implicit rules. -% : SCCS/s.% - -# Disable VCS-based implicit rules. -% : s.% - -.SUFFIXES: .hpux_make_needs_suffix_list - -# Command-line flag to silence nested $(MAKE). -$(VERBOSE)MAKESILENT = -s - -#Suppress display of executed commands. -$(VERBOSE).SILENT: - -# A target that is always out of date. -cmake_force: -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /usr/bin/cmake - -# The command to remove a file. -RM = /usr/bin/cmake -E rm -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/brpc/example/http_c++ - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/brpc/example/http_c++ - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." - /usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache -.PHONY : edit_cache/fast - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache -.PHONY : rebuild_cache/fast - -# The main all target -all: cmake_check_build_system - $(CMAKE_COMMAND) -E cmake_progress_start /home/brpc/example/http_c++/CMakeFiles /home/brpc/example/http_c++//CMakeFiles/progress.marks - $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all - $(CMAKE_COMMAND) -E cmake_progress_start /home/brpc/example/http_c++/CMakeFiles 0 -.PHONY : all - -# The main clean target +# 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. + +NEED_GPERFTOOLS=1 +BRPC_PATH=../../ +include $(BRPC_PATH)/config.mk +# Notes on the flags: +# 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default +CXXFLAGS+=$(CPPFLAGS) -std=c++0x -DNDEBUG -O2 -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer +ifeq ($(NEED_GPERFTOOLS), 1) + CXXFLAGS+=-DBRPC_ENABLE_CPU_PROFILER +endif +HDRS+=$(BRPC_PATH)/output/include +LIBS+=$(BRPC_PATH)/output/lib +HDRPATHS = $(addprefix -I, $(HDRS)) +LIBPATHS = $(addprefix -L, $(LIBS)) +COMMA=, +SOPATHS=$(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS)) + +CLIENT_SOURCES = http_client.cpp +BENCHMARK_SOURCES = benchmark_http.cpp +SERVER_SOURCES = http_server.cpp +PROTOS = http.proto + +PROTO_OBJS = $(PROTOS:.proto=.pb.o) +PROTO_GENS = $(PROTOS:.proto=.pb.h) $(PROTOS:.proto=.pb.cc) +CLIENT_OBJS = $(addsuffix .o, $(basename $(CLIENT_SOURCES))) +BENCHMARK_OBJS = $(addsuffix .o, $(basename $(BENCHMARK_SOURCES))) +SERVER_OBJS = $(addsuffix .o, $(basename $(SERVER_SOURCES))) + +ifeq ($(SYSTEM),Darwin) + ifneq ("$(LINK_SO)", "") + STATIC_LINKINGS += -lbrpc + else + # *.a must be explicitly specified in clang + STATIC_LINKINGS += $(BRPC_PATH)/output/lib/libbrpc.a + endif + LINK_OPTIONS_SO = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) + LINK_OPTIONS = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) +else ifeq ($(SYSTEM),Linux) + STATIC_LINKINGS += -lbrpc + LINK_OPTIONS_SO = -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) + LINK_OPTIONS = -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) +endif + +.PHONY:all +all: http_client benchmark_http http_server + +.PHONY:clean clean: - $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean -.PHONY : clean - -# The main clean target -clean/fast: clean -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -#============================================================================= -# Target rules for targets named http_client - -# Build rule for target. -http_client: cmake_check_build_system - $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 http_client -.PHONY : http_client - -# fast build rule for target. -http_client/fast: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/build -.PHONY : http_client/fast - -#============================================================================= -# Target rules for targets named http_server - -# Build rule for target. -http_server: cmake_check_build_system - $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 http_server -.PHONY : http_server - -# fast build rule for target. -http_server/fast: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/build -.PHONY : http_server/fast - -#============================================================================= -# Target rules for targets named benchmark_http - -# Build rule for target. -benchmark_http: cmake_check_build_system - $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 benchmark_http -.PHONY : benchmark_http - -# fast build rule for target. -benchmark_http/fast: - $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/build -.PHONY : benchmark_http/fast - -benchmark_http.o: benchmark_http.cpp.o -.PHONY : benchmark_http.o - -# target to build an object file -benchmark_http.cpp.o: - $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/benchmark_http.cpp.o -.PHONY : benchmark_http.cpp.o - -benchmark_http.i: benchmark_http.cpp.i -.PHONY : benchmark_http.i - -# target to preprocess a source file -benchmark_http.cpp.i: - $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/benchmark_http.cpp.i -.PHONY : benchmark_http.cpp.i - -benchmark_http.s: benchmark_http.cpp.s -.PHONY : benchmark_http.s - -# target to generate assembly for a file -benchmark_http.cpp.s: - $(MAKE) $(MAKESILENT) -f CMakeFiles/benchmark_http.dir/build.make CMakeFiles/benchmark_http.dir/benchmark_http.cpp.s -.PHONY : benchmark_http.cpp.s - -http.pb.o: http.pb.cc.o -.PHONY : http.pb.o - -# target to build an object file -http.pb.cc.o: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http.pb.cc.o -.PHONY : http.pb.cc.o - -http.pb.i: http.pb.cc.i -.PHONY : http.pb.i - -# target to preprocess a source file -http.pb.cc.i: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http.pb.cc.i -.PHONY : http.pb.cc.i - -http.pb.s: http.pb.cc.s -.PHONY : http.pb.s - -# target to generate assembly for a file -http.pb.cc.s: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http.pb.cc.s -.PHONY : http.pb.cc.s - -http_client.o: http_client.cpp.o -.PHONY : http_client.o - -# target to build an object file -http_client.cpp.o: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/http_client.cpp.o -.PHONY : http_client.cpp.o - -http_client.i: http_client.cpp.i -.PHONY : http_client.i - -# target to preprocess a source file -http_client.cpp.i: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/http_client.cpp.i -.PHONY : http_client.cpp.i - -http_client.s: http_client.cpp.s -.PHONY : http_client.s - -# target to generate assembly for a file -http_client.cpp.s: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_client.dir/build.make CMakeFiles/http_client.dir/http_client.cpp.s -.PHONY : http_client.cpp.s - -http_server.o: http_server.cpp.o -.PHONY : http_server.o - -# target to build an object file -http_server.cpp.o: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http_server.cpp.o -.PHONY : http_server.cpp.o - -http_server.i: http_server.cpp.i -.PHONY : http_server.i - -# target to preprocess a source file -http_server.cpp.i: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http_server.cpp.i -.PHONY : http_server.cpp.i - -http_server.s: http_server.cpp.s -.PHONY : http_server.s - -# target to generate assembly for a file -http_server.cpp.s: - $(MAKE) $(MAKESILENT) -f CMakeFiles/http_server.dir/build.make CMakeFiles/http_server.dir/http_server.cpp.s -.PHONY : http_server.cpp.s - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... edit_cache" - @echo "... rebuild_cache" - @echo "... benchmark_http" - @echo "... http_client" - @echo "... http_server" - @echo "... benchmark_http.o" - @echo "... benchmark_http.i" - @echo "... benchmark_http.s" - @echo "... http.pb.o" - @echo "... http.pb.i" - @echo "... http.pb.s" - @echo "... http_client.o" - @echo "... http_client.i" - @echo "... http_client.s" - @echo "... http_server.o" - @echo "... http_server.i" - @echo "... http_server.s" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system - + @echo "> Cleaning" + rm -rf http_client benchmark_http http_server $(PROTO_GENS) $(PROTO_OBJS) $(CLIENT_OBJS) $(BENCHMARK_OBJS) $(SERVER_OBJS) + +http_client:$(CLIENT_OBJS) + @echo "> Linking $@" +ifneq ("$(LINK_SO)", "") + $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@ +else + $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@ +endif + +benchmark_http:$(BENCHMARK_OBJS) + @echo "> Linking $@" +ifneq ("$(LINK_SO)", "") + $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@ +else + $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@ +endif + +http_server:$(PROTO_OBJS) $(SERVER_OBJS) + @echo "> Linking $@" +ifneq ("$(LINK_SO)", "") + $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@ +else + $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@ +endif + +%.pb.cc %.pb.h:%.proto + @echo "> Generating $@" + $(PROTOC) --cpp_out=. --proto_path=. $< + +%.o:%.cpp + @echo "> Compiling $@" + $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ + +%.o:%.cc + @echo "> Compiling $@" + $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ diff --git a/src/brpc/details/ssl_helper.cpp b/src/brpc/details/ssl_helper.cpp index 7373a024c6..16e3ab67ce 100644 --- a/src/brpc/details/ssl_helper.cpp +++ b/src/brpc/details/ssl_helper.cpp @@ -592,25 +592,24 @@ SSL* CreateSSLSession(SSL_CTX* ctx, SocketId id, int fd, bool server_mode) { } void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { - BIO* rbio = BIO_new(BIO_s_mem()); - //BIO_set_buffer_size(rbio, bufsize); +#if OPENSSL_IS_BORINGSSL + BIO *rbio = BIO_new(BIO_s_mem()); + BIO *wbio = BIO_new(BIO_s_mem()); +#else + BIO *rbio = BIO_new(BIO_f_buffer()); + BIO_set_buffer_size(rbio, bufsize); + BIO *wbio = BIO_new(BIO_f_buffer()); + BIO_set_buffer_size(wbio, bufsize); +#endif BIO* rfd = BIO_new(BIO_s_fd()); BIO_set_fd(rfd, fd, 0); rbio = BIO_push(rbio, rfd); - - BIO* wbio = BIO_new(BIO_s_mem()); - // BIO_set_buffer_size(wbio, bufsize); BIO* wfd = BIO_new(BIO_s_fd()); BIO_set_fd(wfd, fd, 0); wbio = BIO_push(wbio, wfd); SSL_set_bio(ssl, rbio, wbio); } -// void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { -// BIO *bio = BIO_new_socket(fd, BIO_CLOSE); -// SSL_set_bio(ssl, bio, bio); -// } - SSLState DetectSSLState(int fd, int* error_code) { // Peek the first few bytes inside socket to detect whether // it's an SSL connection. If it is, create an SSL session From 20a619d768bfc47c2044e4a05e6f17433a87a201 Mon Sep 17 00:00:00 2001 From: Dongsheng He Date: Thu, 28 Sep 2023 00:38:29 +0800 Subject: [PATCH 6/8] fix compile --- CMakeLists.txt | 7 ++- cmake/FindBoringSSL.cmake | 75 +++++++++++++++++++++++++++++++++ example/http_c++/CMakeLists.txt | 29 +++++-------- src/brpc/details/ssl_helper.cpp | 2 +- src/butil/iobuf.cpp | 4 +- src/butil/ssl_compat.h | 2 +- test/CMakeLists.txt | 5 +-- 7 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 cmake/FindBoringSSL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f3fbaae860..5c06c9616b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,13 +128,13 @@ set(CMAKE_C_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing macro(use_cxx11) if(CMAKE_VERSION VERSION_LESS "3.1.3") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() else() - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() endmacro(use_cxx11) @@ -241,7 +241,6 @@ if(WITH_BORINGSSL) list(APPEND DYNAMIC_LIB ${BORINGSSL_CRYPTO_LIBRARY}) else() list(APPEND DYNAMIC_LIB ${OPENSSL_CRYPTO_LIBRARY}) - if(WITH_MESALINK) list(APPEND DYNAMIC_LIB ${MESALINK_LIB}) else() diff --git a/cmake/FindBoringSSL.cmake b/cmake/FindBoringSSL.cmake new file mode 100644 index 0000000000..26ce19a62b --- /dev/null +++ b/cmake/FindBoringSSL.cmake @@ -0,0 +1,75 @@ +# 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. + +# Usage of this module as follows: +# +# find_package(BORINGSSL) +# +# Variables used by this module, they can change the default behaviour and need +# to be set before calling find_package: +# +# BORINGSSL_ROOT_DIR Set this variable to the root installation of +# boringssl if the module has problems finding the +# proper installation path. +# +# Variables defined by this module: +# +# BORINGSSL_FOUND System has boringssl, include and library dirs found +# BORINGSSL_INCLUDE_DIR The boringssl include directories. +# BORINGSSL_LIBRARIES The boringssl libraries. +# BORINGSSL_CRYPTO_LIBRARY The boringssl crypto library. +# BORINGSSL_SSL_LIBRARY The boringssl ssl library. +# BORING_USE_STATIC_LIBS Whether use static library. + +if(BORING_USE_STATIC_LIBS) + set(_boringssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(MSVC) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + endif() +endif() + +find_path(BORINGSSL_ROOT_DIR + NAMES include/openssl/ssl.h include/openssl/base.h include/openssl/hkdf.h + HINTS ${BORINGSSL_ROOT_DIR}) + +find_path(BORINGSSL_INCLUDE_DIR + NAMES openssl/ssl.h openssl/base.h openssl/hkdf.h + HINTS ${BORINGSSL_ROOT_DIR}/include) + +find_library(BORINGSSL_SSL_LIBRARY + NAMES ssl + HINTS ${BORINGSSL_ROOT_DIR}/lib) + +find_library(BORINGSSL_CRYPTO_LIBRARY + NAMES crypto + HINTS ${BORINGSSL_ROOT_DIR}/lib) + +set(BORINGSSL_LIBRARIES ${BORINGSSL_SSL_LIBRARY} ${BORINGSSL_CRYPTO_LIBRARY} + CACHE STRING "BoringSSL SSL and crypto libraries" FORCE) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(BoringSSL DEFAULT_MSG + BORINGSSL_LIBRARIES + BORINGSSL_INCLUDE_DIR) + +mark_as_advanced( + BORINGSSL_ROOT_DIR + BORINGSSL_INCLUDE_DIR + BORINGSSL_LIBRARIES + BORINGSSL_CRYPTO_LIBRARY + BORINGSSL_SSL_LIBRARY +) \ No newline at end of file diff --git a/example/http_c++/CMakeLists.txt b/example/http_c++/CMakeLists.txt index 4b56c80e78..8d0507d2a5 100644 --- a/example/http_c++/CMakeLists.txt +++ b/example/http_c++/CMakeLists.txt @@ -40,10 +40,9 @@ if (NOT THRIFT_LIB) set(THRIFT_LIB "") endif() -find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h PATHS /home/gperftools/src) -find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler PATHS /home/gperftools/build) +find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h) +find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler) include_directories(${GPERFTOOLS_INCLUDE_DIR}) -message("---- ${GPERFTOOLS_LIBRARIES}") find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h) if(LINK_SO) @@ -88,13 +87,13 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER") if(CMAKE_VERSION VERSION_LESS "3.1.3") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() else() - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() @@ -105,19 +104,13 @@ if ((NOT LEVELDB_INCLUDE_PATH) OR (NOT LEVELDB_LIB)) endif() include_directories(${LEVELDB_INCLUDE_PATH}) -#if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") -# set(OPENSSL_ROOT_DIR -# "/usr/local/opt/openssl" # Homebrew installed OpenSSL -# ) -#endif() - -#find_package(OpenSSL) - - -set(OPENSSL_INCLUDE_DIR /home/boringssl/include) -find_library(OPENSSL_CRYPTO_LIBRARY NAMES libcrypto.a PATHS /home/boringssl/build/crypto) -find_library(OPENSSL_SSL_LIBRARY NAMES libssl.a PATHS /home/boringssl/build/ssl) +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(OPENSSL_ROOT_DIR + "/usr/local/opt/openssl" # Homebrew installed OpenSSL + ) +endif() +find_package(OpenSSL) include_directories(${OPENSSL_INCLUDE_DIR}) diff --git a/src/brpc/details/ssl_helper.cpp b/src/brpc/details/ssl_helper.cpp index 16e3ab67ce..a02752614c 100644 --- a/src/brpc/details/ssl_helper.cpp +++ b/src/brpc/details/ssl_helper.cpp @@ -592,7 +592,7 @@ SSL* CreateSSLSession(SSL_CTX* ctx, SocketId id, int fd, bool server_mode) { } void AddBIOBuffer(SSL* ssl, int fd, int bufsize) { -#if OPENSSL_IS_BORINGSSL +#if defined(OPENSSL_IS_BORINGSSL) BIO *rbio = BIO_new(BIO_s_mem()); BIO *wbio = BIO_new(BIO_s_mem()); #else diff --git a/src/butil/iobuf.cpp b/src/butil/iobuf.cpp index 06b1efbe67..e439526606 100644 --- a/src/butil/iobuf.cpp +++ b/src/butil/iobuf.cpp @@ -38,7 +38,9 @@ #include "butil/fd_guard.h" // butil::fd_guard #include "butil/iobuf.h" +#if defined (OPENSSL_IS_BORINGSSL) #include "butil/ssl_compat.h" // BIO_fd_non_fatal_error +#endif namespace butil { namespace iobuf { @@ -2153,7 +2155,7 @@ bool IOBufBytesIterator::forward_one_block(const void** data, size_t* size) { return true; } -} // namespace butil +} // namespace butil void* fast_memcpy(void *__restrict dest, const void *__restrict src, size_t n) { return butil::iobuf::cp(dest, src, n); diff --git a/src/butil/ssl_compat.h b/src/butil/ssl_compat.h index ce361a20b5..a42c0b4ee2 100644 --- a/src/butil/ssl_compat.h +++ b/src/butil/ssl_compat.h @@ -519,7 +519,7 @@ BRPC_INLINE int EVP_PKEY_base_id(const EVP_PKEY *pkey) { #endif /* OPENSSL_VERSION_NUMBER < 0x0090801fL || OPENSSL_IS_BORINGSSL */ #if defined(OPENSSL_IS_BORINGSSL) -[[maybe_unused]] static int BIO_fd_non_fatal_error(int err) { +BRPC_INLINE int BIO_fd_non_fatal_error(int err) { if ( #ifdef EWOULDBLOCK err == EWOULDBLOCK || diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 149541df9c..9720a0fabe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,10 +15,7 @@ # specific language governing permissions and limitations # under the License. -find_path(GPERFTOOLS_INCLUDE_DIR NAMES gperftools/heap-profiler.h PATHS /home/gperftools/src) -find_library(GPERFTOOLS_LIBRARIES NAMES tcmalloc_and_profiler PATHS /home/gperftools/build) -include_directories(${GPERFTOOLS_INCLUDE_DIR}) - +find_package(Gperftools) include_directories(${GPERFTOOLS_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) From 56a90adaa423e2f6278cf3259d674e5d24332054 Mon Sep 17 00:00:00 2001 From: Dongsheng He Date: Thu, 28 Sep 2023 10:16:33 +0800 Subject: [PATCH 7/8] add boringssl compile bazel ci --- .github/workflows/ci-linux.yml | 7 ++++++- cmake/FindBoringSSL.cmake | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 09f0d3cbf8..56297d993b 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -95,7 +95,9 @@ jobs: run: | export CC=gcc && export CXX=g++ bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //... - + - name: compile-with-boringssl + run: | + bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... clang-compile-with-make: runs-on: ubuntu-20.04 @@ -178,6 +180,9 @@ jobs: run: | export CC=clang && export CXX=clang++ bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //... + - name: compile-with-boringssl + run: | + bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... clang-unittest: runs-on: ubuntu-20.04 diff --git a/cmake/FindBoringSSL.cmake b/cmake/FindBoringSSL.cmake index 26ce19a62b..b475f0aa5d 100644 --- a/cmake/FindBoringSSL.cmake +++ b/cmake/FindBoringSSL.cmake @@ -72,4 +72,6 @@ mark_as_advanced( BORINGSSL_LIBRARIES BORINGSSL_CRYPTO_LIBRARY BORINGSSL_SSL_LIBRARY -) \ No newline at end of file +) + +set(CMAKE_FIND_LIBRARY_SUFFIXES ${_boringssl_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) From dfbabb1286c65e3fab9fa665aa1f9bd7e330f9bb Mon Sep 17 00:00:00 2001 From: ehds Date: Fri, 13 Oct 2023 15:37:18 +0800 Subject: [PATCH 8/8] set compile with boringssl as a dependent job --- .github/workflows/ci-linux.yml | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 56297d993b..9ad90c5204 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -54,6 +54,18 @@ jobs: run: | export CC=gcc && export CXX=g++ bazel build -j ${{env.proc_num}} -c opt --copt -DHAVE_ZLIB=1 //... + + gcc-compile-with-boringssl: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: install dependences + run: | + sudo apt-get update + sudo apt-get install libibverbs-dev + - name: compile-with-boringssl + run: | + bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... gcc-compile-with-make-all-options: runs-on: ubuntu-20.04 @@ -95,9 +107,6 @@ jobs: run: | export CC=gcc && export CXX=g++ bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //... - - name: compile-with-boringssl - run: | - bazel build -j 12 -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... clang-compile-with-make: runs-on: ubuntu-20.04 @@ -140,6 +149,18 @@ jobs: export CC=clang && export CXX=clang++ bazel build -j ${{env.proc_num}} -c opt --copt -DHAVE_ZLIB=1 //... + clang-compile-with-boringssl: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: install dependences + run: | + sudo apt-get update + sudo apt-get install libibverbs-dev + - name: compile + run: | + bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... + clang-compile-with-make-all-options: runs-on: ubuntu-20.04 steps: @@ -180,9 +201,6 @@ jobs: run: | export CC=clang && export CXX=clang++ bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --copt -DHAVE_ZLIB=1 //... - - name: compile-with-boringssl - run: | - bazel build -j ${{env.proc_num}} -c opt --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true --copt -DHAVE_ZLIB=1 //... clang-unittest: runs-on: ubuntu-20.04