diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index dbceac1a51..053a01b6df 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -15,192 +15,14 @@ env: # https://github.com/actions/runner-images jobs: - compile-with-make: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-all-dependencies - - - name: gcc with default options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=gcc --cxx=g++ --werror - - - name: gcc with all options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=gcc --cxx=g++ --werror --with-thrift --with-glog --with-rdma --with-debug-bthread-sche-safety --with-debug-lock --with-bthread-tracer --with-asan - - - name: clang with default options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=clang --cxx=clang++ --werror - - - name: clang with all options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=clang --cxx=clang++ --werror --with-thrift --with-glog --with-rdma --with-debug-bthread-sche-safety --with-debug-lock --with-bthread-tracer --with-asan - - compile-with-cmake: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-all-dependencies - - - name: gcc with default options - run: | - export CC=gcc && export CXX=g++ - mkdir gcc_build && cd gcc_build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - - name: gcc with all options - run: | - export CC=gcc && export CXX=g++ - mkdir gcc_build_all && cd gcc_build_all - cmake -DWITH_MESALINK=OFF -DWITH_GLOG=ON -DWITH_THRIFT=ON -DWITH_RDMA=ON -DWITH_DEBUG_BTHREAD_SCHE_SAFETY=ON -DWITH_DEBUG_LOCK=ON -DWITH_BTHREAD_TRACER=ON -DWITH_ASAN=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - - name: clang with default options - run: | - export CC=clang && export CXX=clang++ - mkdir clang_build && cd clang_build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - - name: clang with all options - run: | - export CC=clang && export CXX=clang++ - mkdir clang_build_all && cd clang_build_all - cmake -DWITH_MESALINK=OFF -DWITH_GLOG=ON -DWITH_THRIFT=ON -DWITH_RDMA=ON -DWITH_DEBUG_BTHREAD_SCHE_SAFETY=ON -DWITH_DEBUG_LOCK=ON -DWITH_BTHREAD_TRACER=ON -DWITH_ASAN=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - gcc-compile-with-make-protobuf: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-essential-dependencies - - - name: protobuf 3.5.1 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.5.1 - protobuf-cpp-version: 3.5.1 - protobuf-install-dir: /protobuf-3.5.1 - config-brpc-options: --cc=gcc --cxx=g++ --werror - - - name: protobuf 3.12.4 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.12.4 - protobuf-cpp-version: 3.12.4 - protobuf-install-dir: /protobuf-3.12.4 - config-brpc-options: --cc=gcc --cxx=g++ --werror - - - name: protobuf 21.12 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 21.12 - protobuf-cpp-version: 3.21.12 - protobuf-install-dir: /protobuf-3.21.12 - config-brpc-options: --cc=gcc --cxx=g++ --werror - gcc-compile-with-bazel: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - run: bazel build --verbose_failures -- //... -//example/... - gcc-compile-with-boringssl: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... - - gcc-compile-with-bazel-all-options: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true --define with_debug_bthread_sche_safety=true --define with_debug_lock=true --define with_asan=true -- //... -//example/... - - clang-compile-with-make-protobuf: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-essential-dependencies - - - name: protobuf 3.5.1 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.5.1 - protobuf-cpp-version: 3.5.1 - protobuf-install-dir: /protobuf-3.5.1 - config-brpc-options: --cc=clang --cxx=clang++ --werror - - - name: protobuf 3.12.4 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.12.4 - protobuf-cpp-version: 3.12.4 - protobuf-install-dir: /protobuf-3.12.4 - config-brpc-options: --cc=clang --cxx=clang++ --werror - - - name: protobuf 21.12 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 21.12 - protobuf-cpp-version: 3.21.12 - protobuf-install-dir: /protobuf-3.21.12 - config-brpc-options: --cc=clang --cxx=clang++ --werror - clang-compile-with-bazel: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - run: bazel build --verbose_failures --action_env=CC=clang -- //... -//example/... - - clang-compile-with-boringssl: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... - - clang-compile-with-bazel-all-options: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define with_debug_bthread_sche_safety=true --define with_debug_lock=true --define with_asan=true -- //... -//example/... - - clang-unittest: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-essential-dependencies - - uses: ./.github/actions/init-ut-make-config - with: - options: --cc=clang-12 --cxx=clang++-12 --with-bthread-tracer - - name: compile tests - run: | - cat config.mk - cd test - make -j ${{env.proc_num}} - - name: run tests - run: | - cd test - sh ./run_tests.sh - - clang-unittest-asan: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-essential-dependencies - - uses: ./.github/actions/init-ut-make-config - with: - options: --cc=clang-12 --cxx=clang++-12 --with-bthread-tracer --with-asan - - name: compile tests - run: | - cat config.mk - cd test - make NEED_GPERFTOOLS=0 -j ${{env.proc_num}} - - name: run tests - run: | - cd test - sh ./run_tests.sh diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml deleted file mode 100644 index 014850f694..0000000000 --- a/.github/workflows/ci-macos.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Build on Macos - -on: - push: - branches: [ master ] - paths-ignore: - - '**.md' - pull_request: - branches: [ master ] - paths-ignore: - - '**.md' - -env: - proc_num: $(sysctl -n hw.logicalcpu) - -jobs: - compile: - runs-on: macos-latest # https://github.com/actions/runner-images - - steps: - - uses: actions/checkout@v2 - - - name: install dependences - run: | - brew install ./homebrew-formula/protobuf.rb - brew install openssl gnu-getopt coreutils gflags leveldb - - - name: compile with make - run: | - GETOPT_PATH=$(brew --prefix gnu-getopt)/bin - export PATH=$GETOPT_PATH:$PATH - ./config_brpc.sh --header="$(brew --prefix)/include" --libs="$(brew --prefix)/lib" - make -j ${{env.proc_num}} && make clean - - - name: compile with cmake - run: | - mkdir build && cd build && cmake .. - make -j ${{env.proc_num}} && make clean - - compile-with-make-protobuf23: - runs-on: macos-latest # https://github.com/actions/runner-images - - steps: - - uses: actions/checkout@v2 - - - name: install dependences - run: | - brew install openssl gnu-getopt coreutils gflags leveldb - # abseil 20230125.3 - curl -o abseil.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/b85b8dbf23ad509f163677a88ac72268f31e9c4a/Formula/abseil.rb - # protobuf 23.3 - curl -o protobuf.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/b85b8dbf23ad509f163677a88ac72268f31e9c4a/Formula/protobuf.rb - HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install --formula --ignore-dependencies ./abseil.rb ./protobuf.rb - - - name: compile with make - run: | - GETOPT_PATH=$(brew --prefix gnu-getopt)/bin - export PATH=$GETOPT_PATH:$PATH - ./config_brpc.sh --header="$(brew --prefix)/include" --libs="$(brew --prefix)/lib" - make -j ${{env.proc_num}} && make clean - - - name: compile with make - run: | - mkdir build && cd build && cmake .. - make -j ${{env.proc_num}} && make clean diff --git a/MODULE.bazel b/MODULE.bazel index b947415672..bb14bb6877 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,7 +8,7 @@ module( bazel_dep(name = 'abseil-cpp', version = '20210324.2', repo_name = 'com_google_absl') bazel_dep(name = 'bazel_skylib', version = '1.0.3') bazel_dep(name = 'boringssl', version = '0.0.0-20211025-d4f1ab9') -bazel_dep(name = 'protobuf', version = '27.3', repo_name = 'com_google_protobuf') +bazel_dep(name = 'protobuf', version = '31.0', repo_name = 'com_google_protobuf') bazel_dep(name = 'gflags', version = '2.2.2', repo_name = 'com_github_gflags_gflags') bazel_dep(name = 'glog', version = '0.5.0', repo_name = 'com_github_google_glog') bazel_dep(name = 'platforms', version = '0.0.4') diff --git a/src/butil/iobuf.cpp b/src/butil/iobuf.cpp index 59ad61a21b..02edda7bb7 100644 --- a/src/butil/iobuf.cpp +++ b/src/butil/iobuf.cpp @@ -2145,7 +2145,7 @@ void IOBufAsZeroCopyOutputStream::BackUp(int count) { LOG_IF(FATAL, count != 0) << "BackUp an empty IOBuf"; } -google::protobuf::int64 IOBufAsZeroCopyOutputStream::ByteCount() const { +int64_t IOBufAsZeroCopyOutputStream::ByteCount() const { return _byte_count; } diff --git a/src/butil/iobuf.h b/src/butil/iobuf.h index 3682f61ecc..2f1c3243ff 100644 --- a/src/butil/iobuf.h +++ b/src/butil/iobuf.h @@ -593,7 +593,7 @@ class IOBufAsZeroCopyOutputStream bool Next(void** data, int* size) override; void BackUp(int count) override; // `count' can be as long as ByteCount() - google::protobuf::int64 ByteCount() const override; + int64_t ByteCount() const override; private: void _release_block(); diff --git a/src/json2pb/json_to_pb.cpp b/src/json2pb/json_to_pb.cpp index 82327cd6d3..8300681ad7 100644 --- a/src/json2pb/json_to_pb.cpp +++ b/src/json2pb/json_to_pb.cpp @@ -52,8 +52,10 @@ perr->append(", ", 2); \ } \ butil::string_appendf(perr, fmt, ##__VA_ARGS__); \ - if ((pb) != nullptr) { \ - butil::string_appendf(perr, " [%s]", (pb)->GetDescriptor()->name().c_str()); \ + if ((pb) != nullptr) { \ + perr->append("["); \ + perr->append((pb)->GetDescriptor()->name()); \ + perr->append("]"); \ } \ } else { } @@ -572,7 +574,7 @@ bool JsonValueToProtoMessage(const BUTIL_RAPIDJSON_NAMESPACE::Value& json_value, for (size_t i = 0; i < fields.size(); ++i) { const google::protobuf::FieldDescriptor* field = fields[i]; - const std::string& orig_name = field->name(); + const std::string orig_name = field->name(); bool res = decode_name(orig_name, field_name_str_temp); const std::string& field_name_str = (res ? field_name_str_temp : orig_name); @@ -719,6 +721,14 @@ bool ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json, google::protobuf::Message* message, const ProtoJson2PbOptions& options, std::string* error) { +#if GOOGLE_PROTOBUF_VERSION >= 6031000 + auto st = google::protobuf::json::JsonStreamToMessage(json, message, options); + bool ok = st.ok(); + if (!ok && NULL != error) { + *error = st.ToString(); + } + return st.ok(); +#else TypeResolverUniqueptr type_resolver = GetTypeResolver(*message); std::string type_url = GetTypeUrl(*message); butil::IOBuf buf; @@ -739,6 +749,7 @@ bool ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json, *error = "Fail to ParseFromCodedStream"; } return ok; +#endif // GOOGLE_PROTOBUF_VERSION >= 6031000 } bool ProtoJsonToProtoMessage(const std::string& json, google::protobuf::Message* message, diff --git a/src/json2pb/pb_to_json.cpp b/src/json2pb/pb_to_json.cpp index 9671979cc0..32885a3b02 100644 --- a/src/json2pb/pb_to_json.cpp +++ b/src/json2pb/pb_to_json.cpp @@ -352,6 +352,14 @@ bool ProtoMessageToJson(const google::protobuf::Message& message, bool ProtoMessageToProtoJson(const google::protobuf::Message& message, google::protobuf::io::ZeroCopyOutputStream* json, const Pb2ProtoJsonOptions& options, std::string* error) { +#if GOOGLE_PROTOBUF_VERSION >= 6031000 + auto st = google::protobuf::util::MessageToJson(message, json, options); + bool ok = st.ok(); + if (!ok && NULL != error) { + *error = st.ToString(); + } + return st.ok(); +#else butil::IOBuf buf; butil::IOBufAsZeroCopyOutputStream output_stream(&buf); if (!message.SerializeToZeroCopyStream(&output_stream)) { @@ -368,6 +376,7 @@ bool ProtoMessageToProtoJson(const google::protobuf::Message& message, *error = st.ToString(); } return ok; +#endif // GOOGLE_PROTOBUF_VERSION >= 6031000 } bool ProtoMessageToProtoJson(const google::protobuf::Message& message, std::string* json, diff --git a/src/json2pb/protobuf_map.cpp b/src/json2pb/protobuf_map.cpp index f552bf6279..7553523482 100644 --- a/src/json2pb/protobuf_map.cpp +++ b/src/json2pb/protobuf_map.cpp @@ -38,12 +38,12 @@ bool IsProtobufMap(const FieldDescriptor* field) { if (NULL == key_desc || key_desc->is_repeated() || key_desc->cpp_type() != FieldDescriptor::CPPTYPE_STRING - || strcmp(KEY_NAME, key_desc->name().c_str()) != 0) { + || key_desc->name() != KEY_NAME) { return false; } const FieldDescriptor* value_desc = entry_desc->field(VALUE_INDEX); if (NULL == value_desc - || strcmp(VALUE_NAME, value_desc->name().c_str()) != 0) { + || value_desc->name() != VALUE_NAME) { return false; } return true; diff --git a/src/json2pb/protobuf_type_resolver.h b/src/json2pb/protobuf_type_resolver.h index a73a42315e..7414350de5 100644 --- a/src/json2pb/protobuf_type_resolver.h +++ b/src/json2pb/protobuf_type_resolver.h @@ -31,8 +31,9 @@ namespace json2pb { #define PROTOBUF_TYPE_URL_PREFIX "type.googleapis.com" inline std::string GetTypeUrl(const google::protobuf::Message& message) { - return butil::string_printf(PROTOBUF_TYPE_URL_PREFIX"/%s", - message.GetDescriptor()->full_name().c_str()); + std::string type_url = PROTOBUF_TYPE_URL_PREFIX; + type_url.append(message.GetDescriptor()->full_name()); + return type_url; } // unique_ptr deleter for TypeResolver only deletes the object