No Description

George Barnett 14215b0e01 Vendor gRPC 1.24.3 5 years ago
.github 0faf1d6e9c Docs/add question template (#310) 7 years ago
Assets 44f194e443 Update vendored gRPC-core to v1.23.0 (#563) 6 years ago
Docker 811e1bb11c Updated Dockerfile (#575) 6 years ago
Examples 7c9a83c424 Fix two memory leaks and update a link in the README. (#501) 6 years ago
Sources 14215b0e01 Vendor gRPC 1.24.3 5 years ago
SwiftGRPC-Carthage.xcodeproj ad0f0b0aef Rebuild the Carthage project with Swift 5 for gRPC-Core 1.23. (#613) 6 years ago
Tests f4d5da3cd5 Added Package.swift with swift 5.0 and Swift package manager support (#682) 6 years ago
scripts 4eec016edf Fix vendoring scripts 5 years ago
.gitignore f4d5da3cd5 Added Package.swift with swift 5.0 and Swift package manager support (#682) 6 years ago
.gitmodules 63c6acfa40 Move CgRPC, gRPC, and QuickProto to "Sources" directory and add new top-level Package.swift. 9 years ago
.travis-install.sh 0f2af51ff7 Run CI on both Swift 4.2 and 5, and fix Swift 5 warning (#426) 6 years ago
.travis.yml 0f2af51ff7 Run CI on both Swift 4.2 and 5, and fix Swift 5 warning (#426) 6 years ago
AUTHORS 0aa90a79ee Relicense to Apache 2, change owners to "the gRPC Authors". 8 years ago
CODE-OF-CONDUCT.md 3a1c40094e Add/update GOVERNANCE.md, CODE-OF-CONDUCT.md and CONTRIBUTING.md 6 years ago
CONTRIBUTING.md 3a1c40094e Add/update GOVERNANCE.md, CODE-OF-CONDUCT.md and CONTRIBUTING.md 6 years ago
DEPRECATION.md ed3cde38ae Add a deprecation notice and plan (#620) 6 years ago
DOCKER.md 410ff70c78 update PROTOBUF 7 years ago
GOVERNANCE.md 3a1c40094e Add/update GOVERNANCE.md, CODE-OF-CONDUCT.md and CONTRIBUTING.md 6 years ago
LICENSE cf002e0aea Revert to Apache 2.0 license verbatim [skip ci] (#498) 6 years ago
LINUX.md 824814b81d Update Linux build documentation (#346) 7 years ago
MAINTAINERS.md 919ae45c0a Add MAINTAINERS.md. (#564) 6 years ago
Makefile f4d5da3cd5 Added Package.swift with swift 5.0 and Swift package manager support (#682) 6 years ago
OVERVIEW.md a11da8644e Fix font weight formatting in OVERVIEW.md 8 years ago
PATENTS 36f2bde28e Add PATENTS declaration 9 years ago
Package.resolved f4d5da3cd5 Added Package.swift with swift 5.0 and Swift package manager support (#682) 6 years ago
Package.swift f4d5da3cd5 Added Package.swift with swift 5.0 and Swift package manager support (#682) 6 years ago
Package@swift-4.2.swift f4d5da3cd5 Added Package.swift with swift 5.0 and Swift package manager support (#682) 6 years ago
README.md a8e4fc2d18 Update README.md (#755) 5 years ago
SwiftGRPC.podspec d46240e3f8 Update the Podspec for v0.10, with gRPC-Core 1.23 and Swift 5. (#612) 6 years ago
fix-carthage-paths.rb 8bc025ea64 Setup bundler (#493) 6 years ago
fix-project-settings.rb 79ecfa5dc9 Support tvOS (#446) 6 years ago
patch-carthage-project.rb 67a5352f17 Avoids linking nghttp2 in Carthage project (#450) 6 years ago

README.md

Build Status

‼️ Please use the master branch ‼️

gRPC Swift versions v0.x based on gRPC-Core will soon be replaced with a re-implementation based on SwiftNIO.

We strongly suggest that new projects use the re-implementation from the master branch which we consider to be production ready.

Please see DEPRECATION.md for more information.

Swift gRPC

This repository contains an experimental Swift gRPC API and code generator.

It is intended for use with Apple's swift-protobuf 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.

The Echo example provides a comprehensive demonstration of currently-supported features.

Swift Package Manager builds may also be made on Linux systems. Please see DOCKER.md and LINUX.md for details.

CocoaPods integration

Swift gRPC is currently available from CocoaPods. To integrate, add the following line to your Podfile:

pod 'SwiftGRPC'

Then, run pod install from command line and use your project's generated .xcworkspace file.

Manual integration

When not using CocoaPods, Swift gRPC includes vendored copies of the gRPC Core library and BoringSSL (an OpenSSL fork that is used by the gRPC Core). These are built automatically in Swift Package Manager builds.

After building your project, add the generated SwiftGRPC.xcodeproj to your project, and add build dependencies on BoringSSL, CgRPC, and SwiftGRPC.

Please also note that your project will need to include the SwiftProtobuf.xcodeproj from Swift Protobuf and the source files that you generate with protoc/plugins.

See Echo for a working Xcode-based example, and don't hesitate to file issues if you find any problems.

Usage

The recommended way to use Swift gRPC is to first define an API using the Protocol Buffer language and then use the Protocol Buffer Compiler and the Swift Protobuf and Swift gRPC plugins to generate the necessary support code.

Getting the plugins

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

To build the plugins, run make plugin in the main directory. This uses the Swift Package Manager to build both of the necessary plugins: protoc-gen-swift, which generates Protocol Buffer support code and protoc-gen-swiftgrpc, which generates gRPC interface code.

To install these plugins, just copy the two executables (protoc-gen-swift and protoc-gen-swiftgrpc) that show up in the main directory into a directory that is part of your PATH environment variable.

Using the plugins

To use the plugins, protoc and both plugins should be in your search path (see above). Invoke them with commands like the following:

protoc <your proto files> \
    --swift_out=. \
    --swiftgrpc_out=.

By convention the --swift_out option invokes the protoc-gen-swift plugin and --swiftgrpc_out invokes protoc-gen-swiftgrpc.

Parameters

To pass extra parameters to the plugin, use a comma-separated parameter list separated from the output directory by a colon.

| Flag | Values | Default | Description | |:-|:-|:-|:-| | Visibility | Internal/Public | Internal | ACL of generated code | | Server | true/false | true | Whether to generate server code | | Client | true/false | true | Whether to generate client code | | Async | true/false | true | Whether to generate asynchronous code | | Sync | true/false | true | Whether to generate synchronous code | | Implementations | true/false | true | Whether to generate protocols and non-test service code. Toggling this to false is mostly useful when combined with TestStubs=true to generate files containing only test stub code | | TestStubs | true/false | false | Whether to generate test stub code | | FileNaming | FullPath/PathToUnderscores/DropPath | FullPath | How to handle the naming of generated sources | | ExtraModuleImports | String | `` | Extra module to import in generated code. This parameter may be included multiple times to import more than one module |

Example:

$ protoc <your proto> --swiftgrpc_out=Client=true,Server=false:.

Building your project

Most grpc-swift development is done with the Swift Package Manager. For usage in Xcode projects, we rely on the swift package generate-xcodeproj command to generate an Xcode project for the grpc-swift core libraries.

The top-level Makefile uses the Swift Package Manager to generate an Xcode project for the SwiftGRPC package:

$ make && make project

This will create SwiftGRPC.xcodeproj, which you should add to your project, along with setting the necessary build dependencies mentioned above.

Low-level gRPC

While the recommended way to use gRPC is with Protocol Buffers and generated code, at its core gRPC is a powerful HTTP/2-based communication system that can support arbitrary payloads. As such, each gRPC library includes low-level interfaces that can be used to directly build API clients and servers with no generated code. For an example of this in Swift, please see the Simple example.

Having build problems?

grpc-swift depends on Swift, Xcode, and swift-protobuf. We are currently testing with the following versions:

  • Xcode 10.2
  • Swift 4.2 / 5.0
  • swift-protobuf 1.5.0

GRPC package based on SwiftNIO

GRPC is a clean-room implementation of the gRPC protocol on top of the SwiftNIO library; you can find the latest version of that implementation on the nio branch. We consider this implementation production-ready and are planning to sunset the gRPC-Core implementation within the next few months. We strongly recommend using the nio branch for all new projects.

You may also want to have a look at this presentation for more details on the motivation for switching to SwiftNIO.

License

grpc-swift is released under the same license as gRPC, repeated in LICENSE.

Contributing

Please get involved! See our guidelines for contributing.

Releasing

When issuing a new release, the following steps should be followed:

  1. Run the CocoaPods linter to ensure that there are no new warnings/errors:

    $ pod spec lint SwiftGRPC.podspec

  2. Update the Carthage Xcode project (diff will need to be checked in with the version bump):

    $ make project-carthage

  3. Bump the version in the SwiftGRPC.podspec file

  4. Merge these changes, then create a new Release with corresponding Tag. Be sure to include a list of changes in the message

  5. Push the update to the CocoaPods specs repo:

    $ pod trunk push