Skip to content

Commit

Permalink
Add support for grpc-service-config; dep updates (#261)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisdunelm committed Jun 23, 2020
1 parent 248bcf7 commit d4c2169
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 46 deletions.
15 changes: 15 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"])
3 changes: 2 additions & 1 deletion bazel_example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions bazel_example/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions bazel_example/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ service Example {

message Request {
string name = 1;
optional int32 number = 2;
}

message Response {
Expand Down
18 changes: 18 additions & 0 deletions bazel_example/grpc_service_config.json
Original file line number Diff line number Diff line change
@@ -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" ]
}
}
]
}
13 changes: 4 additions & 9 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
2 changes: 1 addition & 1 deletion rules_csharp_gapic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
3 changes: 1 addition & 2 deletions rules_csharp_gapic/csharp_compiler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion rules_csharp_gapic/csharp_gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions rules_csharp_gapic/csharp_gapic_repo.bzl

This file was deleted.

0 comments on commit d4c2169

Please sign in to comment.