This update brings some major improvements to rules_proto_grpc and solves many of the longstanding issues that have been present. However, in doing so there have been some changes that make a major version increment necessary and may require updates to your build files. The updates for each language are explained below and should you have any issues, please open a new issue or discussion.
The most substantial change is that compilation of .proto files into language specific files is no longer transitive. This means that only the direct dependencies of a lang_proto_library will be present within the generated library, rather than every transitive proto message. The justification for this is below, but if you're just interested in the changes, you can skip down to the next heading.
In previous versions of rules_proto_grpc, the compilation aspect would compile and aggregate all dependent .proto files from any top level target. In hindsight, this was not the correct behaviour and led to many bugs, since you may end up creating a library that contains compiled proto files from a third party, where you should instead be depending on a proper library for that third party's protos.
Even in a single repo, this may have meant multiple copies of a single compiled proto file being present in a target, if it is depended on via multiple routes. For some languages, such as C++, this breaks the ‘one definition rule’ and produces compilation failures or runtime bugs. For other languages, such as Python, this just meant unnecessary duplicate files in the output binaries.
Therefore, in this release of rules_proto_grpc, there is now a recommedned option to bundle only the direct proto dependencies into the libraries, without including the compiled transitive proto files. This is done by replacing the deps attr on lang_{proto|grpc}_{compile|library} with the protos attr. Since this would be a substantial breaking change to drop at once on a large project, the new behaviour is opt-in in 3.0.0 and the old method continues to work throughout the 3.x.x release cycle. Rules using the previous deps attr will have a warning written to console to signify that your library may be bundling more than expect and should switch attr.
As an additional benefit of this change, we can now support passing arbitrary per-target rules to protoc through the new options attr of the rules, which was a much sought after change that was impossible in the aspect based compilation.
In short, replace deps with protos on your targets:
# Old python_grpc_library( name = "routeguide", deps = ["//example/proto:routeguide_proto"], ) # New python_grpc_library( name = "routeguide", protos = ["//example/proto:routeguide_proto"], )
In applying the above change, you may discover that you were inheriting dependencies transitively and that your builds now fail. In such cases, you should add a lang_{proto|grpc}_{compile|library} target for those proto files and depend on it explicitly from the relevant top level binaries/libraries.
options and extra_protoc_args attributes to control options to protoc #54 #68 #105rules_proto to latest headaspect.bzl and plugin.bzl have merged to a single top level defs.bzlgrpc-java. Please see the examples for the latest WORKSPACE template for the Android rulescc_library rule #40rules_dotnet to latest. Note that the new versions of rules_dotnet drop support for .Net Framework and MonoGrpc to 2.35.0rules_d to latestrules_go to 0.25.1version to go_register_toolchainsgazelle to 0.22.3org_golang_x_net to v0.0.0-20210129194117-4acb7895a057org_golang_x_text to 0.3.5grpc-gateway to 2.2.0gateway_swagger_compile rule has been replaced with gateway_openapiv2_compile #93github.com/... prefix. To Update your use of these rules find and replace @rules_proto_grpc//github.com/grpc-ecosystem/grpc-gateway with @rules_proto_grpc//grpc-gateway//jsgrpc-java. Please see the examples for the latest WORKSPACE template for the Java rules@rules_proto_grpc//nodejs to @rules_proto_grpc//js, but the old rules are still aliased to ease transitionrules_nodejs to 3.1.0@grpc/grpc-js to 1.2.6copt argument pass-through for Obj-C library rules.cc_library rule #40rules_python to latestpy_repositories from rules_python is no longer requiredyugui/rules_ruby to bazelruby/rules_rubyrules_proto_grpc_gems to rules_proto_grpc_bundlegrpc gem may not be loadable in generated Ruby libraries, please see this issue.io_bazel_rules_rust has been renamed to rules_rust. The rust_workspace rule is also no longer requiredrules_rust to latestgrpcio to 0.7.1protobuf to 2.20.0rules_scala to latest #108scala_config rule from rules_scala is now required in your WORKSPACErules_swift to 0.18.0grpc-swift to 1.0.0options #111Thanks to everyone who has contributed issues and patches for this release.
protobuf to 3.13.0grpc to 1.32.0rules_proto, which must be added to your WORKSPACE filetransitivity attribute on proto_plugin. The exclusions attribute is the supported way of achieving thisoutput_dirs attribute of ProtoCompileInfo is now a depset, meaning directories will be deduplicateddeps.bzl files that have been deprecated since version 1.0.0rules_dotnet to latest masterGoogle.Protobuf to 3.13.0Grpc to 2.32.0rules_closure to 0.11.0rules_d to latest masterprotobuf-d to 0.6.2grpc-gateway to 1.15.0rules_go to 0.24.3bazel-gazelle to 0.21.1org_golang_x_net to v0.0.0-20200930145003-4acb6c075d10org_golang_x_text to 0.3.3rules_nodejs to 2.2.0defs.bzl file in rules_nodejs has moved to index.bzlyarn_install() is needed in more casesgrpc_deps() is no longer necessary for just the NodeJS rulesgrpc to @grpc/grpc-js packagejs_library rather than npm_packagerules_python to latest mastergrpclib to 0.4.1grpcio library directly from the local grpc repository.grpclib rulesrules_rust to latest masterprotobuf crate to 2.17.0grpcio crate to 0.6.0rules_rust has changed in the newer version. Please see the Rust language page.grpc_deps() rule is now needed for Rustrules_scala to latest masterScalaPB is now pulled from rules_scala, which uses 0.9.7scala_proto_repositories() rule is now neededrules_swift to 0.15.0grpc-swift to 0.11.0com_google_errorprone_error_prone_annotationsoutput_directory and produce no output files: #39rules_proto_grpc_repos() WORKSPACE rule has been added and is recommended to be usedproto_source_rootimport_prefixrules_pip to the standard rules_python. Please check the documentation for the new WORKSPACE rules required and remove the old onesInitial release of rules_proto_grpc. For changes from predecessor rules_proto, please see MIGRATION.md