Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add bazel build for grpc example #910

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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