From 5ba2bb0448a5ddf4018c7497229b4caddbd85bcf Mon Sep 17 00:00:00 2001 From: esigo Date: Sun, 18 Jul 2021 19:30:18 +0200 Subject: [PATCH 1/2] Add bazel build for grpc example --- WORKSPACE | 2 ++ examples/grpc/BUILD | 60 ++++++++++++++++++++++++++++++++++++++++ examples/grpc/client.cpp | 4 +++ examples/grpc/server.cpp | 4 +++ 4 files changed, 70 insertions(+) create mode 100644 examples/grpc/BUILD diff --git a/WORKSPACE b/WORKSPACE index 1bd7b57c39..57358fb021 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -29,6 +29,8 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") grpc_extra_deps() +load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") + load("@upb//bazel:workspace_deps.bzl", "upb_deps") upb_deps() diff --git a/examples/grpc/BUILD b/examples/grpc/BUILD new file mode 100644 index 0000000000..f6469d5536 --- /dev/null +++ b/examples/grpc/BUILD @@ -0,0 +1,60 @@ + +package(default_visibility = ["//visibility:public"]) +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") + +proto_library( + name = "messages_proto", + srcs = ["protos/messages.proto"], +) + +cc_proto_library( + name = "messages_cc_proto", + deps = [":messages_proto"], +) + +cc_grpc_library( + name = "messages_cc_grpc", + srcs = [":messages_proto"], + grpc_only = True, + deps = [":messages_cc_proto"], +) + +cc_library( + name = "tracer_common", + srcs = ["tracer_common.h"], + defines = ["BAZEL_BUILD"], + deps = [ + "//exporters/ostream:ostream_span_exporter", + ], +) + +cc_binary( + name = "client_grpc", + srcs = [ + "client.cpp", + ], + defines = ["BAZEL_BUILD"], + deps = [ + "@com_github_grpc_grpc//:grpc++", + "messages_cc_grpc", + ":tracer_common", + "//api", + "//sdk/src/trace", + ], +) + +cc_binary( + name = "server_grpc", + srcs = [ + "server.cpp", + ], + defines = ["BAZEL_BUILD"], + deps = [ + "@com_github_grpc_grpc//:grpc++", + "messages_cc_grpc", + ":tracer_common", + "//api", + "//sdk/src/trace", + ], +) diff --git a/examples/grpc/client.cpp b/examples/grpc/client.cpp index 719a62225b..472a933b98 100644 --- a/examples/grpc/client.cpp +++ b/examples/grpc/client.cpp @@ -2,7 +2,11 @@ // ambiguity with `nostd::variant` if compiled with Visual Studio 2015. Other // modern compilers are unaffected. #include +#ifdef BAZEL_BUILD +#include "examples/grpc/protos/messages.grpc.pb.h" +#else #include "messages.grpc.pb.h" +#endif #include "tracer_common.h" #include diff --git a/examples/grpc/server.cpp b/examples/grpc/server.cpp index 167fc08966..6bbdfc64ba 100644 --- a/examples/grpc/server.cpp +++ b/examples/grpc/server.cpp @@ -1,4 +1,8 @@ +#ifdef BAZEL_BUILD +#include "examples/grpc/protos/messages.grpc.pb.h" +#else #include "messages.grpc.pb.h" +#endif #include "tracer_common.h" #include "opentelemetry/trace/span_context_kv_iterable_view.h" From 6d1544d8262421f73585897d727333cd0d76c9ce Mon Sep 17 00:00:00 2001 From: esigo Date: Sun, 18 Jul 2021 19:38:38 +0200 Subject: [PATCH 2/2] fix format --- WORKSPACE | 1 - examples/grpc/BUILD | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 57358fb021..e44ca82ad4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -30,7 +30,6 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") grpc_extra_deps() load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") - load("@upb//bazel:workspace_deps.bzl", "upb_deps") upb_deps() diff --git a/examples/grpc/BUILD b/examples/grpc/BUILD index f6469d5536..2ac65c226c 100644 --- a/examples/grpc/BUILD +++ b/examples/grpc/BUILD @@ -1,5 +1,5 @@ - package(default_visibility = ["//visibility:public"]) + load("@rules_proto//proto:defs.bzl", "proto_library") load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") @@ -36,11 +36,11 @@ cc_binary( ], defines = ["BAZEL_BUILD"], deps = [ - "@com_github_grpc_grpc//:grpc++", "messages_cc_grpc", ":tracer_common", "//api", "//sdk/src/trace", + "@com_github_grpc_grpc//:grpc++", ], ) @@ -51,10 +51,10 @@ cc_binary( ], defines = ["BAZEL_BUILD"], deps = [ - "@com_github_grpc_grpc//:grpc++", "messages_cc_grpc", ":tracer_common", "//api", "//sdk/src/trace", + "@com_github_grpc_grpc//:grpc++", ], )