Skip to content

Commit

Permalink
✨ add bazel build for grpc example (open-telemetry#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Jul 20, 2021
1 parent ecb9a27 commit 40d2eb5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
60 changes: 60 additions & 0 deletions examples/grpc/BUILD
Original file line number Diff line number Diff line change
@@ -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++",
],
)
4 changes: 4 additions & 0 deletions examples/grpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// ambiguity with `nostd::variant` if compiled with Visual Studio 2015. Other
// modern compilers are unaffected.
#include <grpcpp/grpcpp.h>
#ifdef BAZEL_BUILD
#include "examples/grpc/protos/messages.grpc.pb.h"
#else
#include "messages.grpc.pb.h"
#endif

#include "tracer_common.h"
#include <iostream>
Expand Down
4 changes: 4 additions & 0 deletions examples/grpc/server.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down

0 comments on commit 40d2eb5

Please sign in to comment.