Code Monkey home page Code Monkey logo

grpc-swift's Introduction

CI Latest Version sswg:graduated|104x20

gRPC Swift

This repository contains a gRPC Swift API and code generator.

It is intended for use with Apple's SwiftProtobuf support for Protocol Buffers. Both projects contain code generation plugins for protoc, Google's Protocol Buffer compiler, and both contain libraries of supporting code that is needed to build and run the generated code.

APIs and generated code is provided for both gRPC clients and servers, and can be built either with Xcode or the Swift Package Manager. Support is provided for all four gRPC API styles (Unary, Server Streaming, Client Streaming, and Bidirectional Streaming) and connections can be made either over secure (TLS) or insecure channels.

Versions

gRPC Swift has recently been rewritten on top of SwiftNIO as opposed to the core library provided by the gRPC project.

Version Implementation Branch protoc Plugin Support
1.x SwiftNIO main protoc-gen-grpc-swift Actively developed and supported
0.x gRPC C library cgrpc protoc-gen-swiftgrpc No longer developed; security fixes only

The remainder of this README refers to the 1.x version of gRPC Swift.

Supported Platforms

gRPC Swift's platform support is identical to the platform support of Swift NIO.

The earliest supported version of Swift for gRPC Swift releases are as follows:

gRPC Swift Version Earliest Swift Version
1.0.0 ..< 1.8.0 5.2
1.8.0 ..< 1.11.0 5.4
1.11.0..< 1.16.0. 5.5
1.16.0..< 1.20.0 5.6
1.20.0..< 1.22.0 5.7
1.22.0... 5.8

Versions of clients and services which are use Swift's Concurrency support are available from gRPC Swift 1.8.0 and require Swift 5.6 and newer.

Getting gRPC Swift

There are two parts to gRPC Swift: the gRPC library and an API code generator.

Getting the gRPC library

Swift Package Manager

The Swift Package Manager is the preferred way to get gRPC Swift. Simply add the package dependency to your Package.swift:

dependencies: [
  .package(url: "https://github.com/grpc/grpc-swift.git", from: "1.21.0")
]

...and depend on "GRPC" in the necessary targets:

.target(
  name: ...,
  dependencies: [.product(name: "GRPC", package: "grpc-swift")]
]

Getting the protoc Plugins

Binary releases of protoc, the Protocol Buffer Compiler, are available on GitHub.

To build the plugins, run:

  • swift build -c release --product protoc-gen-swift to build the protoc plugin which generates Protocol Buffer support code, and
  • swift build -c release --product protoc-gen-grpc-swift to build the protoc plugin which generates gRPC interface code.

To install these plugins, just copy the two executables (protoc-gen-swift and protoc-gen-grpc-swift) from the build directory (.build/release) into a directory that is part of your PATH environment variable. Alternatively the full path to the plugins can be specified when using protoc.

Using the Swift Package Manager plugin

You can also use the Swift Package Manager build plugin to generate messages and gRPC code at build time rather than using protoc to generate them ahead of time. Using this method Swift Package Manager takes care of building protoc-gen-swift and protoc-gen-grpc-swift for you.

One important distinction between using the Swift Package Manager build plugin and generating the code ahead of time is that the build plugin has an implicit dependency on protoc. It's therefore unsuitable for libraries as they can't guarantee that end users will have protoc available at compile time.

You can find more documentation about the Swift Package Manager build plugin in Using the Swift Package Manager plugin.

Examples

gRPC Swift has a number of tutorials and examples available. They are split across two directories:

  • /Sources/Examples contains examples which do not require additional dependencies and may be built using the Swift Package Manager.
  • /Examples contains examples which rely on external dependencies or may not be built by the Swift Package Manager (such as an iOS app).

Some of the examples are accompanied by tutorials, including:

  • A quick start guide for creating and running your first gRPC service.
  • A basic tutorial covering the creation and implementation of a gRPC service using all four call types as well as the code required to setup and run a server and make calls to it using a generated client.
  • An interceptors tutorial covering how to create and use interceptors with gRPC Swift.

Documentation

The docs directory contains documentation, including:

Benchmarks

Benchmarks for grpc-swift are in a separate Swift Package in the Performance/Benchmarks subfolder of this repository. They use the package-benchmark plugin. Benchmarks depends on the jemalloc memory allocation library, which is used by package-benchmark to capture memory allocation statistics. An installation guide can be found in the Getting Started article of package-benchmark. Afterwards you can run the benchmarks from CLI by going to the Performance/Benchmarks subfolder (e.g. cd Performance/Benchmarks) and invoking:

swift package benchmark

Profiling benchmarks or building the benchmarks in release mode in Xcode with jemalloc is currently not supported and requires disabling jemalloc. Make sure Xcode is closed and then open it from the CLI with the BENCHMARK_DISABLE_JEMALLOC=true environment variable set e.g.:

BENCHMARK_DISABLE_JEMALLOC=true xed .

For more information please refer to swift package benchmark --help or the documentation of package-benchmark.

Security

Please see SECURITY.md.

License

gRPC Swift is released under the same license as gRPC, repeated in LICENSE.

Contributing

Please get involved! See our guidelines for contributing.

grpc-swift's People

Contributors

acchou avatar armstrongnate avatar chemidy avatar clintonpi avatar cvanderschuere avatar fabianfett avatar franzbusch avatar gjcairo avatar glbrntt avatar ishkawa avatar jagobagascon avatar jake-prickett avatar jonasvautherin avatar kevints avatar kyoheig3 avatar lukasa avatar mpetrov avatar mrmage avatar peteradams-a avatar rebello95 avatar rnro avatar ryanwilson avatar sebastianthiebaud avatar sergiocampama avatar simonjbeaumont avatar stefanadranca avatar takasek avatar tikidunpon avatar timburks avatar weissi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpc-swift's Issues

Support for pod.

When grpc-swift support for pod?
master branch podspec name have "incomplete".

Crash, Speech example not functional iOS 10 / iPhone 7 - SSL?

I got a crash on run that was fixed by changing this line in Channel.init
underlyingChannel = cgrpc_channel_create_secure(address, (s! as NSString).utf8String, host)

I got things compiled and running, but I'm getting empty response callbacks from receiveMessage in Call.swift

hardware sample rate = 16000.0, using specified rate = 16000
2016-12-02 09:13:53.244610 Speech[5314:1374671] [Accessibility] Got a keyboard will show notification, but keyboard was not on screen.
2016-12-02 09:13:53.263157 Speech[5314:1374671] [Accessibility] Got a keyboard will hide notification, but keyboard was not even present.
sending 5944 bytes of audio data
Received initial metadata -> date : Fri, 02 Dec 2016 17:13:54 GMT
Received initial metadata -> alt-svc : quic=":443"; ma=2592000; v="36,35,34"
Got a message
Got a message
Got a message
Got a message
Got a message
Got a message

The alt-svc metadata seems to suggest that we're not using port 443?

Extend Echo sample to exercise all streaming cases.

Currently the Echo example demonstrates a nonstreaming and a fully-streaming API call.

To complete our prototype, this needs to be extended to include a call with streaming input and nonstreaming output and one with nonstreaming input and streaming output. Like the two existing calls, this code should be structured to indicate which code would be generated and which would be user-written.

Metadata access needed throughout the API

The generated code currently provides very limited access to metadata.

Both client and server code need access to metadata provided from the other side and clear mechanisms for sending it.

Swift 3.1 Support

Upgrading to Xcode 8.3, I am seeing some trivial compilation errors from Swift 3.1:

$ cd Plugin
$ make
rm -f echo.client.pb.swift echo.server.pb.swift swiftgrpc.log
swift build # This run is to build the template encoder
Compile Swift Module 'SwiftProtobuf' (35 sources)
Compile Swift Module 'Stencil' (19 sources)
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/swift-protobuf.git--7219529775138357838/Sources/SwiftProtobuf/ProtobufJSONDecoding.swift:1035:53: error: 'Generator' has been renamed to 'Iterator'
    private var charGenerator: String.CharacterView.Generator
                                                    ^~~~~~~~~
                                                    Iterator
Swift.Collection:3:22: note: 'Generator' has been explicitly marked unavailable here
    public typealias Generator = Self.Iterator
                     ^
.../grpc-swift/Plugin/.build/checkouts/Stencil.git-7635584243355970173/Sources/Context.swift:46:25: warning: expression implicitly coerced from 'Any?' to Any
    return dictionaries.popLast()
                        ^~~~~~~
.../grpc-swift/Plugin/.build/checkouts/Stencil.git-7635584243355970173/Sources/Context.swift:46:25: note: provide a default value to avoid this warning
    return dictionaries.popLast()
                        ^~~~~~~
                                ?? <#default value#>
.../grpc-swift/Plugin/.build/checkouts/Stencil.git-7635584243355970173/Sources/Context.swift:46:25: note: force-unwrap the value to avoid this warning
    return dictionaries.popLast()
                        ^~~~~~~
                               !
.../grpc-swift/Plugin/.build/checkouts/Stencil.git-7635584243355970173/Sources/Context.swift:46:25: note: explicitly cast to Any with 'as Any' to silence this warning
    return dictionaries.popLast()
                        ^~~~~~~
                                as Any
.../grpc-swift/Plugin/.build/checkouts/Stencil.git-7635584243355970173/Sources/Loader.swift:55:14: warning: no calls to throwing functions occur within 'try' expression
      return try environment.templateClass.init(templateString: content, environment: environment, name: name)
             ^
.../grpc-swift/Plugin/.build/checkouts/Stencil.git-7635584243355970173/Sources/Loader.swift:68:18: warning: no calls to throwing functions occur within 'try' expression
          return try environment.templateClass.init(templateString: content, environment: environment, name: templateName)
                 ^
<unknown>:0: error: build had 1 command failures
swift-build: error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f .../grpc-swift/Plugin/.build/debug.yaml
make: *** [build] Error 1

Bundle code generation templates with or inside the plugin

It would be nice to not have to worry about where the template files are located when using the swiftgrpc plugin. We could resolve this by:

  1. compiling the template text into the plugin binary
  2. installing the templates in a standard location
  3. doing something else...

tiny defect - filename generated for service seem to overwrite each other

this maybe one of those obscure bugs that doesn't cause any problems for some time....
but thought I'd capture it.

I grabbed this proto file
https://github.com/tensorflow/serving/blob/c948af73268c8071fed17a6edcf95b34e40583f2/tensorflow_serving/example/inception_inference.proto

threw it into my tensorflow serving folder

for some reason - the name over lapped with the primary tensorflow serving
tensorflow.serving.server.pb.swift

so the inception class over wrote the file generated from
tensorflow_serving/apis/prediction_service.proto

probably not a bug / but interested to dive deeper into file naming.

Building Xcode examples

Hey,
I am trying to build Xcode example Echo, but it fails. Header "CgRPC.h" is not found.
Steps:

  • clone repo
  • run RUNME.sh
  • make all
  • link libz
  • build Examples/Echo/Xcode/Echo.xcodeproj
CompileSwift normal x86_64 /Users/macuser/Projects/github/grpc-swift/Examples/Echo/Xcode/Echo/EchoViewController.swift
    cd /Users/macuser/Projects/github/grpc-swift/Examples/Echo/Xcode
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/macuser/Projects/github/grpc-swift/Examples/Echo/Xcode/Echo/EchoViewController.swift /Users/macuser/Projects/github/grpc-swift/Examples/Echo/Xcode/Echo/AppDelegate.swift /Users/macuser/Projects/github/grpc-swift/Examples/Echo/Generated/echo.server.pb.swift /Users/macuser/Projects/github/grpc-swift/Examples/Echo/EchoProvider.swift /Users/macuser/Projects/github/grpc-swift/Examples/Echo/Generated/echo.client.pb.swift /Users/macuser/Projects/github/grpc-swift/Examples/Echo/Generated/echo.pb.swift -target x86_64-apple-macosx10.11 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Products/Debug -F /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Products/Debug -enable-testing -g -module-cache-path /Users/macuser/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Echo-generated-files.hmap -Xcc -I/Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Echo-own-target-headers.hmap -Xcc -I/Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Echo-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Echo-project-headers.hmap -Xcc -I/Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Products/Debug/include -Xcc -I/Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/DerivedSources/x86_64 -Xcc -I/Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/macuser/Projects/github/grpc-swift/Examples/Echo/Xcode -emit-module-doc-path /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Objects-normal/x86_64/EchoViewController~partial.swiftdoc -Onone -module-name Echo -emit-module-path /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Objects-normal/x86_64/EchoViewController~partial.swiftmodule -serialize-diagnostics-path /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Objects-normal/x86_64/EchoViewController.dia -emit-dependencies-path /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Objects-normal/x86_64/EchoViewController.d -emit-reference-dependencies-path /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Objects-normal/x86_64/EchoViewController.swiftdeps -o /Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Intermediates/Echo.build/Debug/Echo.build/Objects-normal/x86_64/EchoViewController.o

/Users/macuser/Library/Developer/Xcode/DerivedData/Echo-caqyyrptplhoeogfutxlhuwpypxi/Build/Products/Debug/CgRPC.framework/Modules/module.modulemap:2:12: error: header 'CgRPC.h' not found
    header "CgRPC.h"
           ^
<unknown>:0: error: could not build Objective-C module 'CgRPC'

Cocoapods build configuration (Podspec is broken)

I've put an initial podspec in SwiftGRPC.podspec and put a reference to it in Examples/Speech/Podfile. Attempting to build it has a few problems:

  1. #import "internal.h" needs to be removed from the automatically-generated SwiftGRPC-umbrella.h.
  2. The CgRPC code refers to grpc_slice and the latest tagged version of gRPC-Core uses the older gpr_slice.

gRPC on Docker ubuntu 14.04

I followed your steps
https://github.com/grpc/grpc-swift/tree/master/Packages

I ran into make not found
apt-get install make
resolved this

but then ran into
make: no_c_compiler: Command not found

This doesn't seem to be working
https://gist.githubusercontent.com/johndpope/503029706ed56d5375d1e9469f0135d4/raw/61c9adb603758e1a0ef2318809a431d6e4bd50df/installCGPC.sh

I get


include/grpc++/ext/reflection.pb.h:51:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is
  ^
include/grpc++/ext/reflection.pb.h:52:2: error: #error incompatible with your Protocol Buffer headers. Please
 #error incompatible with your Protocol Buffer headers.  Please
  ^
include/grpc++/ext/reflection.pb.h:53:2: error: #error regenerate this file with a newer version of protoc.
 #error regenerate this file with a newer version of protoc.
  ^
make: *** [/grpc/objs/opt/src/cpp/ext/proto_server_reflection.o] Error 1


when I use git cloning https://github.com/grpc/grpc.git it does compile successfully.
https://gist.github.com/johndpope/503029706ed56d5375d1e9469f0135d4/9d3c2126e8ff5c004f9cb00ee326b9b8aa9eb119

IMPORTANT
@timburks you need to open pr to master to grpc or fetch latest changes from master to your branch to resolve out of date protoc files.

NB some dependencies are missing from prescribed docker file.
I'm using this one for dev.
https://gist.github.com/johndpope/01a74ffb93921df48e334097117be1b3

This line has trouble / saying no git tag exists.
cd gRPC; make; cd ..

screen shot 2016-10-25 at 23 30 39

SSL Authentication for Google (already have OAauth2 token)

I'm trying to securely connect to a Google API. I have already obtained my OAuth2 token, and am including it in the request by doing service?.metadata = Metadata(["authorization" : token]). However, it wasn't working so upon looking at the gRPC website (which doesn't seem to have any documentation about the Swift library, probably because this is experimental right now), I found this in Node.js:

var GoogleAuth = require('google-auth-library'); // from https://www.npmjs.com/package/google-auth-library
...
var ssl_creds = grpc.Credentials.createSsl(root_certs); // load_certs typically loads a CA roots file
var scope = 'https://www.googleapis.com/auth/grpc-testing';
(new GoogleAuth()).getApplicationDefault(function(err, auth) {
  if (auth.createScopeRequired()) {
    auth = auth.createScoped(scope);
  }
  var call_creds = grpc.credentials.createFromGoogleCredential(auth);
  var combined_creds = grpc.credentials.combineChannelCredentials(ssl_creds, call_creds);
  var stub = new helloworld.Greeter('greeter.googleapis.com', combined_credentials);
});

I'm assuming I want to do something similar, but I can't seem to find any Credential class in the Swift gRPC library, let alone something along the lines of createFromGoogleCredential. Is there something that I'm missing, or is it just not implemented yet?

Unable to generate client & server

hey,

I am not able to generate client & server code when I run

protoc ./helloworld.proto --swift_out=./generated/  --swiftgrpc_out=./generated/

I am using the latest github master. This is generating helloworld.pb.swift and swiftgrpc.log. Do I need to use an additional param?

Any help would be much appreciated. Thanking in advance!

P.S. swiftgrpc.log is attached for reference
swiftgrpc.log.zip

rpc stream: Swift Compiler error

//// file "RPC.proto"
syntax = "proto3";

message MyRequest {
  string id = 1;
}
message MyResponse {
  string result = 1;
}
service API {
  rpc my_method(stream MyRequest) returns (MyResponse) {}
}

protoc --proto_path=. --swiftgrpc_out=./swift/ RPC.proto 
ls -l ./swift/
  >> RPC.client.pb.swift
  >> RPC.server.pb.swift

Swift Compiler error:

RPC.client.pb.swift:720:30: Use of undeclared type 'Echo_EchoRequest'

//// file: "RPC.client.pb.swift"

719 /// Call this to send each message in the request stream. Nonblocking.
720 public func send(_ message:Echo_EchoRequest, errorHandler:@escaping (Error)->()) throws {
721  let messageData = try message.serializeProtobuf()
722  try call.sendMessage(data:messageData, errorHandler:errorHandler)
723 }

Xcode project configuration issues - modules, headers, etc.

It appears that module maps are present for each target but are not referenced by the generated Xcode project targets, and can probably be removed.

In order to "import CgRPC" from my main application, I had to:

  • Set "Defines Module" to Yes on CgRPC target
  • Add a "Headers" phase to CgRPC target build phases & add CgRPC.h as a public header

I'm not familiar with the Xcode project generation or I'd submit a PR.

Thanks for the continued great work! Happy to see it working in Xcode 8.3.2.

Swift Compiler error: "Method cannot be declared public"

Swift Compiler error: Method cannot be declared public because its parameter uses an internal type.


file: Models.proto
models proto

file: RPC.proto
rpc proto

protoc --proto_path=. --swift_out=./swift/ Models.proto
protoc --proto_path=. --swiftgrpc_out=./swift/ RPC.proto
ls -l ./swift/
  >> RPC.client.pb.swift
  >> RPC.server.pb.swift
  >> Models.pb.swift

file: RPC.client.pb.swift
rpc client pb swift

file: Models.pb.swift
models pb swift

Robust error handling

These error situations that aren't handled well.

  • Server methods receiving invalid message protocol buffers from clients.
  • Clients receiving invalid protocol buffers from servers.
  • Authentication failures from servers.
  • Server handler (aka "provider") failures inside dispatched threads.

Inconsistency in proto message naming convention, too many underscores

Hi @timburks,

While trying to incorporate grpc-swift into my project, I noticed a minor inconsistency between grpc-swift and swift-protobuf in the naming conventions for messages. This caused my generated code to fail to compile.

You can apply this patch, recompile echo.proto and then attempt to build the Echo app to see what I'm talking about:

diff --git a/Examples/Echo/echo.proto b/Examples/Echo/echo.proto
index 1328b5f..ce418b6 100644
--- a/Examples/Echo/echo.proto
+++ b/Examples/Echo/echo.proto
@@ -14,7 +14,7 @@

 syntax = "proto3";

-package echo;
+package echo_package;

 service Echo {
   // Immediately returns an echo of a request.

swift-protobuf creates messages with names like EchoPackage_EchoRequest while grpc-swift assumes Echo_Package_EchoRequest.

Why is public visibility required for the source generated from the protos?

The README.md documents the need for --swift_opt=Visibility=Public as:

The --swift_opt flag passes an option to protoc-gen-swift that makes message classes public, which is necessary to use them with gRPC.

But that explication doesn't make sense. If the .pb.swift files and grpc files are compiled in the same module, then the default internal visibility would be fine.

The real reason one might need public visibility is if the .pb.swift files (and grpc ones) will be placed in a different module from the code that uses them.

Integration Test Parity with Java grpc - for consideration

Been digging into grpc. I found the grpc-java library which has some additional test cases.
I'm thinking

Given THESE exact proto files
https://github.com/grpc/grpc-java/tree/master/testing-proto/src/main/proto/io/grpc/testing/integration

Need some matching integration test cases in swift
https://github.com/grpc/grpc-java/tree/master/testing-proto/src/generated/main/grpc/io/grpc/testing/integration

test for these conditions

  • A service used to control reconnect server.

  • A simple service NOT implemented at servers so clients can test for

  • that case.

  • A simple service to test the various types of RPCs and experiment with

  • performance with various types of payload.

etc
EMPTY_UNARY("empty (zero bytes) request and response"),
CACHEABLE_UNARY("cacheable unary rpc sent using GET"),
LARGE_UNARY("single request and (large) response"),
CLIENT_STREAMING("request streaming with single response"),
SERVER_STREAMING("single request with response streaming"),
PING_PONG("full-duplex ping-pong streaming"),
EMPTY_STREAM("A stream that has zero-messages in both directions"),
COMPUTE_ENGINE_CREDS("large_unary with service_account auth"),
SERVICE_ACCOUNT_CREDS("large_unary with compute engine auth"),
JWT_TOKEN_CREDS("JWT-based auth"),
OAUTH2_AUTH_TOKEN("raw oauth2 access token auth"),
PER_RPC_CREDS("per rpc raw oauth2 access token auth"),
CUSTOM_METADATA("unary and full duplex calls with metadata"),
STATUS_CODE_AND_MESSAGE("request error code and message"),
UNIMPLEMENTED_METHOD("call an unimplemented RPC method"),
UNIMPLEMENTED_SERVICE("call an unimplemented RPC service"),
CANCEL_AFTER_BEGIN("cancel stream after starting it"),
CANCEL_AFTER_FIRST_RESPONSE("cancel on first response"),
TIMEOUT_ON_SLEEPING_SERVER("timeout before receiving a response");

@ericgribkoff - @timburks - consider that there should be a hello world standard for integration test cases. perhaps even spat out as automatic code to test against. As in the test cases + code doing integration testing against
https://github.com/grpc/grpc-java/blob/master/testing-proto/src/main/proto/io/grpc/testing/integration/test.proto
is? valid in other languages.

I've managed to spit out a bunch of swift code that's generated out for tensorflow - but now need to start climbing - and need to have some sanity checks on service. I imagine for any grpc generated code - having a base test harness for grpc service would help troubleshoot lower level things.

README doesn't mention the required plugin

Nothing in the README mentions the fact that the plugin needs to be compiled. The README only mentions the regular swift-protobuf plugin, not the gRPC specific one.

The README should have step by step instructions for getting started that list out all of the required steps.

Nested proto message error

Models.proto

syntax = "proto3";
// file: Models.proto

package M;

message Account {
  uint32 id    = 1;
  string phone = 2;
  string email = 3;

  message Identifier {
    oneof type {
      uint32 id    = 1;
      string phone = 2;
      string email = 3;
    }
  }
}

message MyResponse {
  uint32 status  = 1;
  string message = 2;
}

RPC.proto

syntax = "proto3";
// file: RPC.proto

package RPC;

import "Models.proto";

service API {

  rpc Account_Info(M.Account.Identifier) returns (M.MyResponse) {}

}

generate_protobuf_swift_grpc_files.sh

#!/bin/bash
# 
# file: generate_protobuf_swift_grpc_files.sh
# 

export PLUGIN_BIN="/tmp/grpc-swift/third_party/swift-protobuf/.build/debug/protoc-gen-swift"

out_path="./swift"
mkdir -p "${out_path}"
rm -f "${out_path}"/*.swift

protoc \
  --proto_path=. \
  --swift_out="${out_path}" \
  --swift_opt=Visibility=Public \
  --plugin="${PLUGIN_BIN}" \
  Models.proto

protoc \
  --proto_path=. \
  --swiftgrpc_out="${out_path}" \
  RPC.proto

# 
# $ protoc --version
# > libprotoc 3.3.0
# 
# $ "${PLUGIN_BIN}" --version
# > protoc-gen-swift 0.9.901
# 
$ ls -al ./swift/
> Models.pb.swift
> RPC.client.pb.swift
> RPC.server.pb.swift

Swift compiler show me the error like this:

..../MyProject/protos/RPC.server.pb.swift:199:34: Use of unresolved identifier 'M_Account_Identifier'

M_Account_Identifier should be M_Account.Identifier here.
( p.s. Maybe M.Account.Identifier looks better )

Define 1.0 release requirements.

Presumably:

  1. Pass interoperability tests.
  2. Implement service code generation.
  3. Support both Darwin (Apple platforms) and Linux.

Also (suggested in comments):
4. Explicit gRPC and Swift Proto version dependencies.
5. Surface stability.
6. Continuous testing set up, with high code coverage.
7. Manual testing in a device under changing networking conditions (e.g. with an app like this one).
8. At least 1 app successfully launched?
9. Samples and tutorials.

Please comment with additional requirements.

Carthage Support

It would be fantastic if you had Carthage support with pre-built binaries ❤️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.