GAPIC Generator Bazel Integration
This is not an officially supported Google project.
This repository contains Bazel rules for generating Google Cloud client libraries using the corresponding generators:
The input for each generator is usually a set of proto files defining the given API. The definitions for Google Cloud APIs can be found in the googleapis repository.
Example of generating a client library for Language API:
git clone https://github.com/googleapis/googleapis
cd googleapis
bazel build //google/cloud/language/v1:google-cloud-language-v1-java
bazel build //google/cloud/language/v1:gapi-cloud-language-v1-go
bazel build //google/cloud/language/v1:language-v1-py
bazel build //google/cloud/language/v1:google-cloud-language-v1-php
bazel build //google/cloud/language/v1:language-v1-nodejs
bazel build //google/cloud/language/v1:google-cloud-language-v1-ruby
bazel build //google/cloud/language/v1:google-cloud-language-v1-csharp
(note that the Bazel target names are different for different languages for legacy reasons)
- Bazel version
3.0.0+
. - Linux (may work on other platforms, but this haven't been tested).
gcc
,make
,autoconf
,unzip
tools
The rules will call gapic-generator
and do all the necessary pre- and post- generation steps to generate a fully-functional client library for a specified service API in a specified language. The rules are expected to be used from within a Bazel workspace containing service interface definitions in one of the following formats:
proto/grpc
format, defined by<service>.proto
,<service>.yaml
and<service>_gapic.yaml
files; see googleapis repository for an example.discovery/httpjson
format, defined by<service>.json
and<service>_gapic.yaml
; see discovery-artifact-manager repository for an example.
gapic_srcjar
- cross-language (main) rule which calls gapic-generator, supplies necessary input files to it (likegapic_<service>.yaml
,<service>.yaml
ordiscovery_doc.json
in case of discogapic generation). Notice thatartman_<service>.yaml
(googleapis),dependencies.yaml
andapi_defaults.yaml
(gapic-generator) andpackage_yaml2
(generated by artman from artman and service yamls) become obsolete (not required at any stage). The chosen name tries to follow Bazel best practices, in which a rule name must be a noun, which represents the output of the rule.proto_custom_library
- cross-language rule, which allows: 1) callingprotoc
with custom plugins; 2) specifying the output files format and file extension (essential for consuming (down the chain) rules); 3) acceptingproto_library
targets as inputs (to adhere to Bazel protobuf best practices and stay consistent with everything else). Unfortunately Bazel does not have native support for the features above and a similar rule in protobuf repo proto_gen satisfies the 1st requirement/feature but not the other two. Notice that this rule does not replaceproto_library
, it is additive to it (it usesproto_library
's output as input, whileproto_library
has raw proto files as input).proto_library_with_info
- cross-language macro, which wrapsproto_custom_library
and provides "fat" proto descriptor. This is not supported by nativeproto_library
rule but is required by gapic-generator to include documentation from protos and to overcome the limitation of "only one" desc file as an input in gapic-generator (dependencies' proto descriptors must be supplied somehow, here they are embedded in one big descriptor which then goes to gapic-gen as input).moved_proto_library
- A deprecated cross-language macro currently used only to generate Python clients. It is used to achieve backward compatibility with previous generator tools, which used to move all protos under google/cloud domain before running the generation.
java_gapic_srcjar
- Java rule, which does all the Java-specific post-processing of the Java gapic-generator output (produced bygapic_srcjar
rule). This includes running formatter and splitting output into main and test packages (a design decision/assumption made, but it is essential (though not strictly required) for proper building of the artifacts within Bazel).java_gapic_library
- Java macro, which subsequently callsgapic_srcjar
to generate sources, thenjava_gapic_srcjar
to post-process them, then nativejava_library
(twice, one for main and one for tests) to build Java binary lib from the generated output within Bazel. This is the rule, which intends to put gapic-generator on same level of tools integration as protoc (java_proto_library
) and gRPC (java_grpc_library
).java_discogapic_library
- Java macro, which is very similar tojava_gapic_library
and does same, but for discogapic libraries.java_gapic_test
- Java macro, which createsjava_test
and groups them in atest_suite
, acceptingjava_gapic_library
test artifact and the generated test classes full names (with package).java_gapic_assembly_gradle_pkg
- Java macro which accepts the previously builtjava_proto_library
,java_grpc_library
,java_gapic_library
andproto_library
artifacts as arguments and packages them into an idiomatic (for PHP) package which is ready for opensourcing and is independent from Bazel.
py_gapic_srcjar
- Python macro, which first callsgapic_srcjar
to generate the source code. Then, it calls an internal rule, which does all the Python-specific postprocessing of the code. This postprocessing includes formatting the code and splitting the code into main and test.srcjar
archives (a zip format).py_gapic_library
- Python macro, which first callspy_gapic_srcjar
to generate and post process the gapic library. Then, it calls the nativepy_library
rule to build the generated code. It declares directories. Finally, it unpacks the sources for the main and test into those directories, so that they can be consumed bypy_library
andpy_test
(which do not accept.srcjar
files as an input).py_gapic_assembly_pkg
- Python macro which accepts the previously builtpy_gapic_library
(including the-test.srcjar
and-smoke-test.srcjar
),py_proto_library
andpy_grpc_library
artifacts and packages them into an idiomatic (for Python) package which is ready for opensourcing and is independent from Bazel.
-
php_proto_library
- PHP macro, which generates php protobuf stubs by calling protobuf compiler with--php_out
parameter. -
php_grpc_library
- PHP macro, which generates php gRPC stubs by calling protobuf compiler with the php gRPC plugin. -
php_gapic_srcjar
- PHP macro, which first callsgapic_srcjar
to generate the source code, then calls an internal rule which does all the php-specific postprocessing of the code (calling usingphp-cs-fixer
andphpcbf
tools, splitting the code into main and test and smoke test.srcjar
files (zip format)). -
php_gapic_library
- PHP macro, which callsphp_gapic_srcjar
to generate and postprocess gapic library. -
php_gapic_assembly_pkg
- PHP macro which accepts the previously builtphp_proto_library
,php_grpc_library
andphp_gapic_library
artifacts as arguments and packages them into an idiomatic (for PHP) package which is ready for opensourcing and is independent from Bazel.
-
ruby_proto_library
- Ruby macro, which generates Ruby protobuf stubs by calling protobuf compiler with--ruby_out
parameter. -
ruby_grpc_library
- Ruby macro, which generates Ruby gRPC stubs by calling protobuf compiler with the Ruby gRPC plugin. -
ruby_gapic_srcjar
- Ruby macro, which first callsgapic_srcjar
to generate the source code, then calls an internal rule which does all the ruby-specific postprocessing of the code (currenly just splitting the code into main and test and smoke test.srcjar
files (zip format)). -
ruby_gapic_library
- Ruby macro, which callsruby_gapic_srcjar
to generate and postprocess gapic library. -
ruby_gapic_assembly_pkg
- Ruby macro which accepts the previously builtruby_proto_library
,ruby_grpc_library
andruby_gapic_library
artifacts as arguments and packages them into an idiomatic (for Ruby) package which is ready for opensourcing and is independent from Bazel.
-
csharp_proto_library
- C# macro, which generates C# protobuf stubs by calling protobuf compiler with--csharp_out
parameter. -
csharp_grpc_library
- C# macro, which generates C# gRPC stubs by calling protobuf compiler with the C# gRPC plugin. -
csharp_gapic_srcjar
- C# macro, which first callsgapic_srcjar
to generate the source code, then calls an internal rule which does all the C#-specific postprocessing of the code (currently just splitting the code into main, test, smoke test and package.srcjar
files (zip format)). -
csharp_gapic_library
- C# macro, which callscsharp_gapic_srcjar
to generate and postprocess gapic library. -
csharp_gapic_assembly_pkg
- C# macro which accepts the previously builtcsharp_proto_library
,csharp_grpc_library
andcsharp_gapic_library
artifacts as arguments and packages them into an idiomatic (for C#) package which is ready for opensourcing and is independent from Bazel.
java/java_gapic_repositories.bzl
- this file essentially replacesartman_<service>.yaml
,dependencies.yaml
andapi_defaults.yaml
by usingbazel
itself for dependencies resolution. Previously the dependencies were handled in a form of yaml config values, when they are not validated to: 1) be correct/exist; 2) match generated code; 3) be sufficient/redundant. To deal with dependencies versions mismatch, therepo_mapping
feature of Bazel is supposed to be used (enabled by--experimental_enable_repo_mapping
command line argument).
python/py_gapic_repositories.bzl
- this file declares the Python-specific dependencies of the generated output. It is intended to be included in theWORKSPACE
file of the consuming workspace (for example, ingoogleapis
).
php/php_gapic_repositories.bzl
- this file declares the PHP-specific dependencies of the generated output and is supposed to be included in the WORKSPACE file of the consuming workspace (for example ingoogleapis
). This file also declares thephp
repository rule, which downloads and builds from sources the PHP interpreter (by usinggcc
,make
andautoconf
tools, so they are expected to be installed on the system).
There are not any specific to Ruby dependencies at this moment (they may be added in the future).
There are not any specific to C# dependencies at this moment (they may be added in the future).