Skip to content

Instantly share code, notes, and snippets.

@pcj
Created August 4, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcj/eabf86da1cd7e560dbb7b231673a3bd5 to your computer and use it in GitHub Desktop.
Save pcj/eabf86da1cd7e560dbb7b231673a3bd5 to your computer and use it in GitHub Desktop.
Possible approach to extensibility of rules_protobuf
# Later, invoke the protobuf_go_library with the language flag. This will
# trigger building of the protobuffer with the grpc-gateway plugin and
# building of the library with the required dependencies.
load("@org_pubref_rules_protobuf//bzl:rules.bzl", "protobuf_go_library")
protobuf_go_library(
protos = ["service.proto"],
srcs = ["service_impl.go"],
deps = [
"//third_party/foo:go_default_library"
],
with_grpc = True,
with_grpc_gateway = True,
)
# Hypothetical WORKSPACE that demonstrates how to provide an extension
# language with pre- and post- hooks to rules_protobuf:
# ****************************************************************
# Load up the required rules dependencies
# ****************************************************************
git_repository(
name = "org_pubref_rules_protobuf",
remote = "https://github.com/pubref/rules_protobuf",
tag = "0.2.0",
)
git_repository(
name = "com_github_grpc_ecosystem_grpc_gateway",
remote = "https://github.com/grpc-ecosystem/grpc-gateway",
tag = "v1.1.0",
)
# ****************************************************************
# Load the plugin's skylark event hooks
# ****************************************************************
load("@com_github_grpc_ecosystem_grpc_gateway//protoc-gen-grpc-gateway/rules_protobuf_plugin.bzl",
grpc_gateway_pre = "pre"
grpc_gateway_post = "post"
)
load("@org_pubref_rules_protobuf//bzl:rules.bzl", "rules_protobuf")
# ****************************************************************
# Invoke rules_protobuf with the configured language.
# ****************************************************************
rules_protobuf(
languages = [
struct(
lang = "grpc_gateway",
# Provide the plugin binary here
plugin = "@com_github_grpc_ecosystem_grpc_gateway//protoc-gen-grpc-gateway"
# Any default options
plugin_options = [ "foo=bar"],
# The pre- and post- event hooks
pre = grpc_gateway_pre,
post = grpc_gateway_pre,
# Additional dependencies that should be included during compilation of the outputs.
deps = [
{
# Makes //external:grpc_gateway_runtime available as a
# dependency for go_library
"kind": "bind",
"name": "grpc_gateway",
"actual": "@com_github_grpc_ecosystem_grpc_gateway//runtime",
},
],
},
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment