From d4c21696f5f63e4e9e71511dc75cfb41fbf53447 Mon Sep 17 00:00:00 2001 From: Chris Bacon Date: Tue, 23 Jun 2020 12:00:08 +0100 Subject: [PATCH] Add support for grpc-service-config; dep updates (#261) Add support for specifying grpc-service-config to the gapic bazel rule. Update gapic and grpc dependencies. Remove a pointless bazel self-reference to this repo. Update example to include an optional field. --- BUILD.bazel | 15 ++++++++++++ bazel_example/BUILD.bazel | 3 ++- bazel_example/WORKSPACE.bazel | 6 ++--- bazel_example/example.proto | 1 + bazel_example/grpc_service_config.json | 18 +++++++++++++++ repositories.bzl | 13 ++++------- rules_csharp_gapic/BUILD.bazel | 2 +- rules_csharp_gapic/csharp_compiler.bzl | 3 +-- rules_csharp_gapic/csharp_gapic.bzl | 6 ++++- rules_csharp_gapic/csharp_gapic_repo.bzl | 29 ------------------------ 10 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 bazel_example/grpc_service_config.json delete mode 100644 rules_csharp_gapic/csharp_gapic_repo.bzl diff --git a/BUILD.bazel b/BUILD.bazel index e69de29b..d9c995ab 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -0,0 +1,15 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +exports_files(["Google.Api.Generator"]) diff --git a/bazel_example/BUILD.bazel b/bazel_example/BUILD.bazel index 2ad049bb..90c5c773 100644 --- a/bazel_example/BUILD.bazel +++ b/bazel_example/BUILD.bazel @@ -33,7 +33,8 @@ csharp_gapic_library( deps = [ ":example_csharp_proto", ":example_csharp_grpc", - ] + ], + grpc_service_config = "grpc_service_config.json", ) csharp_gapic_assembly_pkg( diff --git a/bazel_example/WORKSPACE.bazel b/bazel_example/WORKSPACE.bazel index 65d34f55..56ac4561 100644 --- a/bazel_example/WORKSPACE.bazel +++ b/bazel_example/WORKSPACE.bazel @@ -13,9 +13,9 @@ protobuf_deps() # with nuget packages Grpc.Core and Grpc.Core.Api v2.x http_archive( name = "com_github_grpc_grpc", - strip_prefix = "grpc-1.29.1", - sha256 = "2afd3e20fd1d52d3d1a605a74befcdcb048a9213a4903880d9267856b063ae60", - urls = ["https://github.com/grpc/grpc/archive/v1.29.1.zip"], + strip_prefix = "grpc-1.30.0", + sha256 = "4f0ad3557539a3d6edfad1693a92bd21acd3a6c3d610faa4714d64ad1d0a8072", + urls = ["https://github.com/grpc/grpc/archive/v1.30.0.zip"], ) load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") grpc_deps() diff --git a/bazel_example/example.proto b/bazel_example/example.proto index a0650ead..8bfafce0 100644 --- a/bazel_example/example.proto +++ b/bazel_example/example.proto @@ -8,6 +8,7 @@ service Example { message Request { string name = 1; + optional int32 number = 2; } message Response { diff --git a/bazel_example/grpc_service_config.json b/bazel_example/grpc_service_config.json new file mode 100644 index 00000000..ef8d87af --- /dev/null +++ b/bazel_example/grpc_service_config.json @@ -0,0 +1,18 @@ +{ + "method_config": [ + { + "name": [ + { + "service": "example.Example" + } + ], + "timeout": "555s", + "retry_policy": { + "initial_backoff": "0.5s", + "max_backoff": "5s", + "backoff_multiplier": 1.3, + "retryable_status_codes": [ "DEADLINE_EXCEEDED", "RESOURCE_EXHAUSTED" ] + } + } + ] +} diff --git a/repositories.bzl b/repositories.bzl index 2fd6c062..9f826fe4 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -15,28 +15,23 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//rules_csharp_gapic:csharp_compiler_repo.bzl", "csharp_compiler", "dotnet_restore") -load("//rules_csharp_gapic:csharp_gapic_repo.bzl", "gapic_generator_src") def gapic_generator_csharp_repositories(): maybe( http_archive, name = "com_google_api_codegen", - strip_prefix = "gapic-generator-a79e9ea3fcf686a80d92461a4788c5bcf55cea5a", - urls = ["https://github.com/googleapis/gapic-generator/archive/a79e9ea3fcf686a80d92461a4788c5bcf55cea5a.zip"], - sha256 = "c6a13fd221189458ad9eeb1de1f40e21bd80f0063bf05b9fa243722c18577f17", + strip_prefix = "gapic-generator-2.2.0", + urls = ["https://github.com/googleapis/gapic-generator/archive/v2.2.0.zip"], + sha256 = "0633651c7e7cdbea16231025de8a8e55773c224ad840507a8f3b38f96461ad30" ) maybe( csharp_compiler, name = "csharp_compiler", ) - maybe( - gapic_generator_src, - name = "gapic_generator_src", - ) maybe( dotnet_restore, name = "gapic_generator_restore", - src_base = "@gapic_generator_src//:gen_dest/Google.Api.Generator", + src_base = "@//:Google.Api.Generator", csproj_name = "Google.Api.Generator.csproj", runtime = "linux-x64", ) diff --git a/rules_csharp_gapic/BUILD.bazel b/rules_csharp_gapic/BUILD.bazel index 00266990..13fd0aaf 100644 --- a/rules_csharp_gapic/BUILD.bazel +++ b/rules_csharp_gapic/BUILD.bazel @@ -19,7 +19,7 @@ csharp_binary( visibility = ["//visibility:public"], restore_packages = "@gapic_generator_restore//:packages", restore_obj = "@gapic_generator_restore//:obj", - src_base = "@gapic_generator_src//:gen_dest/Google.Api.Generator", + src_base = "//:Google.Api.Generator", csproj_name = "Google.Api.Generator.csproj", runtime = "linux-x64", ) diff --git a/rules_csharp_gapic/csharp_compiler.bzl b/rules_csharp_gapic/csharp_compiler.bzl index 0b073124..11594a20 100644 --- a/rules_csharp_gapic/csharp_compiler.bzl +++ b/rules_csharp_gapic/csharp_compiler.bzl @@ -85,8 +85,7 @@ cp -r ./bin/* {bin_out_path}; if ctx.attr.runtime: out_run_sh = ctx.actions.declare_file("run.sh") run_sh_contents = """#!/bin/bash -cd $(dirname $0) -bin/{configuration}/{framework}/{runtime}/publish/{exe_name} +$(dirname $0)/bin/{configuration}/{framework}/{runtime}/publish/{exe_name} """.format( configuration = ctx.attr.configuration, framework = ctx.attr.framework, diff --git a/rules_csharp_gapic/csharp_gapic.bzl b/rules_csharp_gapic/csharp_gapic.bzl index 26e02715..33671c17 100644 --- a/rules_csharp_gapic/csharp_gapic.bzl +++ b/rules_csharp_gapic/csharp_gapic.bzl @@ -48,13 +48,17 @@ _csharp_gapic_library_add_gapicinfo = rule( } ) -def csharp_gapic_library(name, srcs, deps, **kwargs): +def csharp_gapic_library(name, srcs, deps, grpc_service_config = None, **kwargs): # Build zip file of gapic-generator output name_srcjar = "{name}_srcjar".format(name = name) + plugin_file_args = {} + if grpc_service_config: + plugin_file_args[grpc_service_config] = "grpc-service-config" proto_custom_library( name = name_srcjar, deps = srcs, plugin = Label("//rules_csharp_gapic:csharp_gapic_generator_binary"), + plugin_file_args = plugin_file_args, output_type = "gapic", output_suffix = ".srcjar", **kwargs diff --git a/rules_csharp_gapic/csharp_gapic_repo.bzl b/rules_csharp_gapic/csharp_gapic_repo.bzl deleted file mode 100644 index 7c447210..00000000 --- a/rules_csharp_gapic/csharp_gapic_repo.bzl +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -def _gapic_generator_src_impl(ctx): - ctx.download_and_extract( - url = "https://github.com/googleapis/gapic-generator-csharp/archive/v1.0.0-beta06.tar.gz", - stripPrefix = "gapic-generator-csharp-1.0.0-beta06", - sha256 = "93d2499651b35b43a122253aea060beeaf91fdcbcb9f7993863b1d3ae02bfd5e", - output = "gen_dest", - ) - ctx.file( - "BUILD", - """exports_files(glob(include = ["gen_dest/**"], exclude_directories = 0))""", - ) - -gapic_generator_src = repository_rule( - implementation = _gapic_generator_src_impl, -)