Skip to content

Commit

Permalink
Depend on grpc-ecosystem/proto-converter (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
TAOXUY authored Jun 7, 2023
1 parent 332ba75 commit ff41eb3
Show file tree
Hide file tree
Showing 43 changed files with 218 additions and 205 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
build --action_env=CC=clang-10
build --action_env=CXX=clang++-10

build --cxxopt=-std=c++14
build --host_cxxopt=-std=c++14

# The ASAN configuration suitable for C++ unit tests.
build:asan --copt=-fsanitize=address
build:asan --linkopt=-fsanitize=address
Expand Down
17 changes: 9 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ load(
"io_bazel_rules_docker",
"nlohmannjson_repositories",
"protobuf_repositories",
"protoconverter_repositories",
)

# See
Expand All @@ -39,6 +40,8 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.3.2.zip"],
)

absl_repositories()

load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")

rules_fuzzing_dependencies()
Expand All @@ -47,10 +50,14 @@ load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init")

rules_fuzzing_init()

absl_repositories()

protobuf_repositories()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

protoconverter_repositories()

googletest_repositories()

googleapis_repositories()
Expand Down Expand Up @@ -79,14 +86,8 @@ load(
_cc_image_repos()
# END io_bazel_rules_docker

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()

load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
Expand Down
15 changes: 9 additions & 6 deletions perf_benchmark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cc_proto_library(

proto_library(
name = "benchmark_proto",
srcs = ["benchmark.proto"],
testonly = 1,
srcs = ["benchmark.proto"],
deps = [
"@com_google_googleapis//google/api:annotations_proto",
"@com_google_protobuf//:struct_proto",
Expand All @@ -43,11 +43,11 @@ proto_library(

cc_binary(
name = "benchmark_main",
testonly = 1,
srcs = ["benchmark_main.cc"],
data = [
"benchmark_service.textproto",
],
testonly = 1,
deps = [
"benchmark_cc_proto",
":benchmark_input_stream",
Expand All @@ -72,8 +72,8 @@ cc_binary(
# Please make sure if you're building from Debian 11 system as well.
cc_image(
name = "benchmark_main_image",
binary = ":benchmark_main",
testonly = 1,
binary = ":benchmark_main",
)

# Example run command:
Expand All @@ -83,19 +83,19 @@ cc_image(
# --define=PUSH_TAG=latest
container_push(
name = "benchmark_main_image_push",
testonly = 1,
format = "Docker",
image = ":benchmark_main_image",
testonly = 1,
registry = "$(PUSH_REGISTRY)",
repository = "$(PUSH_PROJECT)/grpc-httpjson-transcoding-benchmark",
tag = "$(PUSH_TAG)",
)

cc_library(
name = "utils",
testonly = 1,
srcs = ["utils.cc"],
hdrs = ["utils.h"],
testonly = 1,
deps = [
"benchmark_cc_proto",
"//src:type_helper",
Expand All @@ -112,11 +112,13 @@ cc_library(

cc_library(
name = "benchmark_input_stream",
testonly = 1,
srcs = ["benchmark_input_stream.cc"],
hdrs = ["benchmark_input_stream.h"],
testonly = 1,
deps = [
"//src:transcoder_input_stream",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/strings",
"@com_google_protobuf//:protobuf",
],
Expand Down Expand Up @@ -166,6 +168,7 @@ cc_test(
"//src:response_to_json_translator",
"//src:type_helper",
"@com_github_nlohmann_json//:json",
"@com_google_absl//absl/log:absl_check",
"@com_google_googleapis//google/api:service_cc_proto",
"@com_google_googletest//:gtest_main",
],
Expand Down
6 changes: 3 additions & 3 deletions perf_benchmark/benchmark_input_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//

#include "perf_benchmark/benchmark_input_stream.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/log/absl_check.h"

namespace google {
namespace grpc {
Expand All @@ -29,7 +29,7 @@ BenchmarkZeroCopyInputStream::BenchmarkZeroCopyInputStream(
msg_(std::move(json_data)),
chunk_size_(msg_.size() / num_checks),
pos_(0) {
GOOGLE_CHECK(num_checks <= msg_.size());
ABSL_CHECK(num_checks <= msg_.size());
}

int64_t BenchmarkZeroCopyInputStream::BytesAvailable() const {
Expand Down Expand Up @@ -74,7 +74,7 @@ uint64_t BenchmarkZeroCopyInputStream::TotalBytes() const {
}

void BenchmarkZeroCopyInputStream::BackUp(int count) {
GOOGLE_CHECK(count <= pos_);
ABSL_CHECK(count <= pos_);
pos_ -= count;
finished_ = false;
}
Expand Down
4 changes: 2 additions & 2 deletions perf_benchmark/benchmark_input_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define PERF_BENCHMARK_BENCHMARK_INPUT_STREAM_H_

#include "absl/strings/string_view.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/log/absl_log.h"
#include "grpc_transcoding/transcoder_input_stream.h"

namespace google {
Expand Down Expand Up @@ -55,7 +55,7 @@ class BenchmarkZeroCopyInputStream : public TranscoderInputStream {
bool Next(const void** data, int* size) override;
void BackUp(int count) override;
bool Skip(int count) override {
GOOGLE_LOG(FATAL) << "Not implemented";
ABSL_LOG(FATAL) << "Not implemented";
return false;
};
int64_t ByteCount() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "perf_benchmark/benchmark_input_stream.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_format.h"
#include "absl/log/absl_check.h"
#include "google/api/service.pb.h"
#include "google/protobuf/text_format.h"
#include "grpc_transcoding/json_request_translator.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ constexpr absl::string_view kServiceConfigTextProtoFile =
// unnecessary heap allocations and create minor performance concerns.
// For a small benchmark script, this is okay.
auto* service = new google::api::Service();
GOOGLE_CHECK_OK(
ABSL_CHECK_OK(
LoadService(std::string(kServiceConfigTextProtoFile), service));

// Create a TypeHelper based on the service config.
Expand Down
3 changes: 2 additions & 1 deletion perf_benchmark/benchmark_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "absl/strings/escaping.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/log/absl_check.h"
#include "google/api/service.pb.h"
#include "google/protobuf/text_format.h"
#include "grpc_transcoding/json_request_translator.h"
Expand Down Expand Up @@ -85,7 +86,7 @@ constexpr absl::string_view kMultiStringFieldPrefix = "f";
// unnecessary heap allocations and create minor performance concerns.
// For a small benchmark script, this is okay.
auto* service = new google::api::Service();
GOOGLE_CHECK_OK(
ABSL_CHECK_OK(
LoadService(std::string(kServiceConfigTextProtoFile), service));

// Create a TypeHelper based on the service config.
Expand Down
2 changes: 1 addition & 1 deletion perf_benchmark/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "google/api/service.pb.h"
#include "google/protobuf/util/internal/type_info.h"
#include "google/protobuf/util/converter/type_info.h"
#include "perf_benchmark/benchmark.pb.h"
#include "src/include/grpc_transcoding/type_helper.h"

Expand Down
37 changes: 16 additions & 21 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
################################################################################
#
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

ABSEIL_COMMIT = "99477fa9f1e89a7d8253c8aeee331864710d080c"
ABSEIL_SHA256 = "495e8e1c481018126b2a84bfe36e273907ce282b135e7d161e138e463d295f3d"
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

def absl_repositories(bind = True):
http_archive(
name = "com_google_absl",
strip_prefix = "abseil-cpp-" + ABSEIL_COMMIT,
url = "https://github.com/abseil/abseil-cpp/archive/" + ABSEIL_COMMIT + ".tar.gz",
sha256 = ABSEIL_SHA256,
sha256 = "ea1d31db00eb37e607bfda17ffac09064670ddf05da067944c4766f517876390",
strip_prefix = "abseil-cpp-c2435f8342c2d0ed8101cb43adfd605fdc52dca2", # May 04, 2023.
urls = ["https://github.com/abseil/abseil-cpp/archive/c2435f8342c2d0ed8101cb43adfd605fdc52dca2.zip"],
)

def zlib_repositories(bind = True):
Expand Down Expand Up @@ -92,28 +90,17 @@ cc_library(
build_file_content = BUILD,
)

PROTOBUF_COMMIT = "3.16.0" # Mar 04, 2021
PROTOBUF_SHA256 = "7892a35d979304a404400a101c46ce90e85ec9e2a766a86041bb361f626247f5"

RULES_PROTO_SHA = "97d8af4dc474595af3900dd85cb3a29ad28cc313" # Oct 31, 2019
RULES_PROTO_SHA256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208"
PROTOBUF_COMMIT = "315ffb5be89460f2857387d20aefc59b76b8bdc3" # May 31, 2023
PROTOBUF_SHA256 = "aa61db6ff113a1c76eac9408144c6e996c5e2d6b2410818fd7f1b0d222a50bf8"

def protobuf_repositories(bind = True):
http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-" + PROTOBUF_COMMIT,
url = "https://github.com/google/protobuf/archive/v" + PROTOBUF_COMMIT + ".tar.gz",
sha256 = PROTOBUF_SHA256,
)

http_archive(
name = "rules_proto",
sha256 = RULES_PROTO_SHA256,
strip_prefix = "rules_proto-" + RULES_PROTO_SHA,
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/" + RULES_PROTO_SHA + ".tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/" + RULES_PROTO_SHA + ".tar.gz",
"https://github.com/google/protobuf/archive/" + PROTOBUF_COMMIT + ".tar.gz",
],
sha256 = PROTOBUF_SHA256,
)

GOOGLETEST_COMMIT = "703bd9caab50b139428cea1aaff9974ebee5742e" # v1.10.0: Oct 2, 2019
Expand Down Expand Up @@ -194,3 +181,11 @@ def io_bazel_rules_docker(bind = True):
sha256 = RULES_DOCKER_SHA256,
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v" + RULES_DOCKER_COMMIT + "/rules_docker-v" + RULES_DOCKER_COMMIT + ".tar.gz"],
)

def protoconverter_repositories(bind = True):
http_archive(
name = "com_google_protoconverter",
sha256 = "6081836fa3838ebb1aa15089a5c3e20f877a0244c7a39b92a2000efb40408dcb",
strip_prefix = "proto-converter-d77ff301f48bf2e7a0f8935315e847c1a8e00017",
urls = ["https://github.com/grpc-ecosystem/proto-converter/archive/d77ff301f48bf2e7a0f8935315e847c1a8e00017.zip"],
)
4 changes: 4 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cc_library(
],
deps = [
"@com_google_protobuf//:protobuf",
"@com_google_protoconverter//:all",
],
)

Expand Down Expand Up @@ -78,6 +79,7 @@ cc_library(
],
deps = [
":transcoder_input_stream",
"@com_google_absl//absl/status",
"@com_google_protobuf//:protobuf",
],
)
Expand Down Expand Up @@ -276,6 +278,7 @@ cc_library(
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_protobuf//:protobuf",
"@com_google_protoconverter//:all",
],
)

Expand All @@ -292,6 +295,7 @@ cc_library(
],
deps = [
":protobuf",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
],
Expand Down
3 changes: 1 addition & 2 deletions src/include/grpc_transcoding/internal/protobuf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
#ifndef GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_
#define GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_

#include "google/protobuf/stubs/stringpiece.h"

namespace google {
namespace grpc {
namespace transcoding {
namespace internal {

typedef ::google::protobuf::StringPiece string_view;
typedef ::absl::string_view string_view;

} // namespace internal
} // namespace transcoding
Expand Down
2 changes: 1 addition & 1 deletion src/include/grpc_transcoding/json_request_translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <memory>

#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/util/internal/json_stream_parser.h"
#include "google/protobuf/util/converter/json_stream_parser.h"
#include "google/protobuf/util/type_resolver.h"
#include "message_stream.h"
#include "request_message_translator.h"
Expand Down
6 changes: 3 additions & 3 deletions src/include/grpc_transcoding/message_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include <memory>

#include "google/protobuf/stubs/status.h"
#include "transcoder_input_stream.h"
#include "absl/status/status.h"

namespace google {
namespace grpc {
Expand Down Expand Up @@ -92,7 +92,7 @@ class MessageReader {
// is OK before consuming the `grpc_frame`.
MessageAndGrpcFrame NextMessageAndGrpcFrame();

::google::protobuf::util::Status Status() const { return status_; }
absl::Status Status() const { return status_; }

// Returns true if the stream has ended (this is permanent); otherwise returns
// false.
Expand All @@ -107,7 +107,7 @@ class MessageReader {
// Are we all done?
bool finished_;
// Status
::google::protobuf::util::Status status_;
absl::Status status_;
// Buffer to store the current delimiter value.
unsigned char delimiter_[kGrpcDelimiterByteSize];

Expand Down
4 changes: 2 additions & 2 deletions src/include/grpc_transcoding/message_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <string>

#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/stubs/status.h"
#include "transcoder_input_stream.h"
#include "absl/status/status.h"

namespace google {
namespace grpc {
Expand Down Expand Up @@ -70,7 +70,7 @@ class MessageStream {
// false.
virtual bool Finished() const = 0;
// Stream status to report errors
virtual ::google::protobuf::util::Status Status() const = 0;
virtual absl::Status Status() const = 0;
// Virtual destructor
virtual ~MessageStream() {}
// Creates ZeroCopyInputStream implementation based on this stream
Expand Down
Loading

0 comments on commit ff41eb3

Please sign in to comment.