-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use GRPC and SwiftProtobuf from Swift Package Manager
- Loading branch information
1 parent
19ef290
commit 676c95e
Showing
27 changed files
with
583 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "grpc-swift", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/grpc/grpc-swift.git", | ||
"state" : { | ||
"revision" : "4ab02e1ae5b4dfdd723773e955b62f35ccbaa7c7", | ||
"version" : "1.16.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-atomics", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-atomics.git", | ||
"state" : { | ||
"revision" : "cd142fd2f64be2100422d658e7411e39489da985", | ||
"version" : "1.2.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-collections", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-collections.git", | ||
"state" : { | ||
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", | ||
"version" : "1.1.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-http-types", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-http-types", | ||
"state" : { | ||
"revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65", | ||
"version" : "1.0.3" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-log", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-log.git", | ||
"state" : { | ||
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", | ||
"version" : "1.5.4" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio.git", | ||
"state" : { | ||
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982", | ||
"version" : "2.64.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-extras", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-extras.git", | ||
"state" : { | ||
"revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63", | ||
"version" : "1.22.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-http2", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-http2.git", | ||
"state" : { | ||
"revision" : "0904bf0feb5122b7e5c3f15db7df0eabe623dd87", | ||
"version" : "1.30.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-ssl", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-ssl.git", | ||
"state" : { | ||
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5", | ||
"version" : "2.26.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-transport-services", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-transport-services.git", | ||
"state" : { | ||
"revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce", | ||
"version" : "1.20.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-protobuf", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-protobuf.git", | ||
"state" : { | ||
"revision" : "88c7d15e1242fdb6ecbafbc7926426a19be1e98a", | ||
"version" : "1.20.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-system", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-system.git", | ||
"state" : { | ||
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496", | ||
"version" : "1.2.1" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | ||
load( | ||
"@build_bazel_rules_swift//proto:proto.bzl", | ||
"swift_proto_compiler", | ||
) | ||
load( | ||
"//compilers:swift_proto_compiler_macros.bzl", | ||
"GRPC_VARIANT_CLIENT", | ||
"GRPC_VARIANT_SERVER", | ||
"GRPC_VARIANT_TEST_CLIENT", | ||
"PROTO_PLUGIN_OPTIONS", | ||
"PROTO_PLUGIN_OPTION_ALLOWLIST", | ||
"make_grpc_swift_proto_compiler", | ||
) | ||
|
||
# Swift Protobuf | ||
|
||
swift_proto_compiler( | ||
name = "swift_proto", | ||
plugin = "@swiftpkg_swift_protobuf//:protoc-gen-swift", | ||
plugin_name = "swift", | ||
plugin_option_allowlist = PROTO_PLUGIN_OPTION_ALLOWLIST, | ||
plugin_options = PROTO_PLUGIN_OPTIONS, | ||
protoc = "@com_google_protobuf//:protoc", | ||
suffixes = [".pb.swift"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@swiftpkg_swift_protobuf//:SwiftProtobuf", | ||
], | ||
) | ||
|
||
# Swift GRPC | ||
|
||
make_grpc_swift_proto_compiler( | ||
name = "swift_server_proto", | ||
variants = [GRPC_VARIANT_SERVER], | ||
) | ||
|
||
make_grpc_swift_proto_compiler( | ||
name = "swift_client_proto", | ||
variants = [GRPC_VARIANT_CLIENT], | ||
) | ||
|
||
make_grpc_swift_proto_compiler( | ||
name = "swift_test_client_proto", | ||
variants = [GRPC_VARIANT_TEST_CLIENT], | ||
) | ||
|
||
bzl_library( | ||
name = "swift_proto_compiler_macros", | ||
srcs = ["swift_proto_compiler_macros.bzl"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@bazel_skylib//lib:dicts", | ||
"@build_bazel_rules_swift//swift", | ||
], | ||
) |
85 changes: 85 additions & 0 deletions
85
examples/grpc_example/compilers/swift_proto_compiler_macros.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2023 The Bazel Authors. All rights reserved. | ||
# | ||
# 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 | ||
# | ||
# http://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. | ||
|
||
""" | ||
Utilities for proto compiler rules. | ||
""" | ||
|
||
load( | ||
"@bazel_skylib//lib:dicts.bzl", | ||
"dicts", | ||
) | ||
load( | ||
"@build_bazel_rules_swift//proto:proto.bzl", | ||
"swift_proto_compiler", | ||
) | ||
|
||
# NOTE: The ProtoPathModuleMappings option is set internally for all plugins. | ||
# This is used to inform the plugins which Swift module the generated code for each plugin is located in. | ||
PROTO_PLUGIN_OPTION_ALLOWLIST = [ | ||
"FileNaming", | ||
"Visibility", | ||
] | ||
PROTO_PLUGIN_OPTIONS = { | ||
"Visibility": "Public", | ||
} | ||
GRPC_VARIANT_SERVER = "Server" | ||
GRPC_VARIANT_CLIENT = "Client" | ||
GRPC_VARIANT_TEST_CLIENT = "TestClient" | ||
GRPC_VARIANTS = [ | ||
GRPC_VARIANT_SERVER, | ||
GRPC_VARIANT_CLIENT, | ||
GRPC_VARIANT_TEST_CLIENT, | ||
] | ||
GRPC_PLUGIN_OPTION_ALLOWLIST = PROTO_PLUGIN_OPTION_ALLOWLIST + [ | ||
"KeepMethodCasing", | ||
"ExtraModuleImports", | ||
"GRPCModuleName", | ||
"SwiftProtobufModuleName", | ||
] + GRPC_VARIANTS | ||
|
||
def make_grpc_swift_proto_compiler( | ||
name, | ||
variants, | ||
plugin_options = PROTO_PLUGIN_OPTIONS): | ||
"""Generates a GRPC swift_proto_compiler target for the given variants. | ||
Args: | ||
name: The name of the generated swift proto compiler target. | ||
variants: The list of variants the compiler should generate. | ||
plugin_options: Additional options to pass to the plugin. | ||
""" | ||
|
||
# Merge the plugin options to include the variants: | ||
merged_plugin_options = dicts.add( | ||
plugin_options, | ||
{variant: "false" for variant in GRPC_VARIANTS}, | ||
) | ||
for variant in variants: | ||
merged_plugin_options[variant] = "true" | ||
|
||
swift_proto_compiler( | ||
name = name, | ||
protoc = "@com_google_protobuf//:protoc", | ||
plugin = "@swiftpkg_grpc_swift//:protoc-gen-grpc-swift", | ||
plugin_name = name.removesuffix("_proto"), | ||
plugin_option_allowlist = GRPC_PLUGIN_OPTION_ALLOWLIST, | ||
plugin_options = merged_plugin_options, | ||
suffixes = [".grpc.swift"], | ||
deps = [ | ||
"@swiftpkg_swift_protobuf//:SwiftProtobuf", | ||
"@swiftpkg_grpc_swift//:GRPC", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.