Skip to content

Latest commit

 

History

History
100 lines (77 loc) · 2.45 KB

README.md

File metadata and controls

100 lines (77 loc) · 2.45 KB

C++ Rules

Rule Description
cpp_proto_repositories Load WORKSPACE dependencies.
cc_proto_compile Generate protobuf source files.
cc_proto_library Generate and compiles protobuf source files.

cpp_proto_repositories

Enable C++ support by loading the dependencies in your workspace.

load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cpp_proto_repositories")
cpp_proto_repositories()

cc_proto_compile

This is a thin wrapper over the proto_compile rule having language @org_pubref_rules_protobuf//cpp.

load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cc_proto_compile")

cc_proto_compile(
  name = "protos",
  protos = ["message.proto"],
  with_grpc = True,
)
$ bazel build :protos
Target //:protos up-to-date:
  bazel-genfiles/message.pb.h
  bazel-genfiles/message.pb.cc
  bazel-genfiles/message.grpc.pb.h
  bazel-genfiles/message.grpc.pb.cc

cc_proto_library

Pass the set of protobuf source files to the protos attribute.

load("@org_pubref_rules_protobuf//cpp:rules.bzl", "cc_proto_library")

cc_proto_library(
  name = "protolib",
  protos = ["message.proto"],
  with_grpc = True,
)
$ bazel build :protolib
$ bazel build --spawn_strategy=standalone :protolib
Target //:protolib up-to-date:
  bazel-bin/libprotolib.a
  bazel-bin/libprotolib.so

Note: there are some remaining issues with grpc++ compiling on linux that may require disabling the sandbox via the --spawn_strategy=standalone build option. See #7

When using the compiled library in other rules, #include the generated files relative to the WORKSPACE root. For example, the //examples/helloworld/proto/helloworld.proto functions can be loaded via:

#include <grpc++/grpc++.h>

#include "examples/helloworld/proto/helloworld.pb.h"
#include "examples/helloworld/proto/helloworld.grpc.pb.h"

To get the list of required compile-time dependencies in other contexts for grpc-related code, load the list from the rules.bzl file:

load("@org_pubref_rules_protobuf//cpp:rules.bzl", "GRPC_COMPILE_DEPS")

cc_library(
  name = "mylib",
  srcs = ['MyApp.cpp'],
  deps = [
    ":protolib"
  ] + GRPC_COMPILE_DEPS,
)

Consult source files in the examples/helloworld/cpp directory for additional information.