1

I'm trying to build gRPC binaries in C++ but I don't need all the features provided by gRPC. In particular, I have no need for XDS support. I can disable it using the bazel build flag --define=grpc_no_xds=true, but it means I have to pass it all the time when compiling my cc_binary (which is error-prone). What I'd like to do is make this setting a permanent part of my cc_binary. But how?

This is the config setting in question in the gRPC source: https://github.com/grpc/grpc/blob/master/BUILD#L53-L56

Here's my binary's build rule:

cc_binary(
    name = "greeter_client",
    srcs = ["greeter_client.cc"],
    deps = [
        "//src/myproject/grpc/examples/proto:helloworld_cc_grpc",
        "@com_github_grpc_grpc//:grpc++",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
    ],
)

As you can see, I can say bazel build //src/myproject/grpc/examples:greeter_client and it works, but pulls in all kinds of crap I don't need. If I say bazel build --define=grpc_no_xds=true //src/myproject/grpc/examples:greeter_client, then the resulting binary is much smaller (and compiles faster). Yes, I know I can put this in a .bazelrc file, but I'd like to make it part of my cc_binary rule. Somehow. I read suggestions about creating a custom cc_binary rule, but it's still murky how would that help me in this situation.

It's not relevant here, but I'm using an M1 MacBook Pro for development.

Lajos Nagy
  • 9,075
  • 11
  • 44
  • 55

0 Answers0