diff --git a/WORKSPACE b/WORKSPACE index 1bd7b57c39..e44ca82ad4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -29,6 +29,7 @@ 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..2ac65c226c --- /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 = [ + "messages_cc_grpc", + ":tracer_common", + "//api", + "//sdk/src/trace", + "@com_github_grpc_grpc//:grpc++", + ], +) + +cc_binary( + name = "server_grpc", + srcs = [ + "server.cpp", + ], + defines = ["BAZEL_BUILD"], + deps = [ + "messages_cc_grpc", + ":tracer_common", + "//api", + "//sdk/src/trace", + "@com_github_grpc_grpc//:grpc++", + ], +) 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"