Sem descrição

Michael Rebello 9841080d38 Update Carthage project with SwiftProtobuf 1.1.1 há 7 anos atrás
Assets 75940a411e Update CgRPC to v1.12.0 and BoringSSL to 10.0.4 (I guess?). This change requires Swift 4.1 and Ruby (with the 'xcodeproj' gem) installed to compile if building via SPM. há 7 anos atrás
Docker 62e4e3cad4 Update Dockerfile há 7 anos atrás
Examples a86b934ab7 Update examples to SwiftProtobuf 1.1.1 há 7 anos atrás
Sources c03c5c7a35 Fix -Wstrict-prototypes warning há 7 anos atrás
SwiftGRPC-Carthage.xcodeproj 9841080d38 Update Carthage project with SwiftProtobuf 1.1.1 há 7 anos atrás
Tests 97e2fe965a Merge branch 'master' into metadata-tests há 7 anos atrás
scripts d5ff00dd96 Remove comment há 7 anos atrás
third_party f9de073b4a Update vendor-grpc script to include roots.pem and update roots.pem version. há 8 anos atrás
.gitignore 56ecb721c1 Fix building with a clean Xcode and add a CI run to ensure just that. há 7 anos atrás
.gitmodules 63c6acfa40 Move CgRPC, gRPC, and QuickProto to "Sources" directory and add new top-level Package.swift. há 9 anos atrás
.swift-version 04887237e1 Update .swift-version há 8 anos atrás
.travis-install.sh 470fb2fbe3 Update .travis-install.sh to Swift 4.1.1. há 7 anos atrás
.travis.yml 165f6846a7 Only make the Swift Xcode project (instead of a full Xcode build) on macOS CI, as that is covered by the Carthage build already. há 7 anos atrás
AUTHORS 0aa90a79ee Relicense to Apache 2, change owners to "the gRPC Authors". há 8 anos atrás
CONTRIBUTING.md 98a8b64da5 Update README and CONTRIBUTING. há 9 anos atrás
DOCKER.md 410ff70c78 update PROTOBUF há 8 anos atrás
LICENSE 0aa90a79ee Relicense to Apache 2, change owners to "the gRPC Authors". há 8 anos atrás
LINUX.md 93f426875b Update Echo sample path há 8 anos atrás
Makefile 2c576c0a36 Merge pull request #292 from grpc/rework-project-patches há 7 anos atrás
OVERVIEW.md a11da8644e Fix font weight formatting in OVERVIEW.md há 8 anos atrás
PATENTS 36f2bde28e Add PATENTS declaration há 9 anos atrás
Package.swift 6c6d9be3cb Update SwiftProtobuf to 1.1.1 há 7 anos atrás
README.md 9db4d0b339 Update README with swift-protobuf version há 7 anos atrás
SwiftGRPC.podspec 6c6d9be3cb Update SwiftProtobuf to 1.1.1 há 7 anos atrás
fix-project-settings.rb 4984951cfa Project patch script rework. há 7 anos atrás
patch-carthage-project.rb 4984951cfa Project patch script rework. há 7 anos atrás
swift-vendoring.sh.template ffe96e6693 Updating for grpc-1.4.5, WIP. Builds but does not pass tests. há 8 anos atrás
vendor-boringssl.sh 75940a411e Update CgRPC to v1.12.0 and BoringSSL to 10.0.4 (I guess?). This change requires Swift 4.1 and Ruby (with the 'xcodeproj' gem) installed to compile if building via SPM. há 7 anos atrás
vendor-grpc.sh 03f43093fb Move another compiler directive into vendor-grpc.sh. há 7 anos atrás

README.md

Build Status

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 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.

Using the plugins

To use the plugins, protoc and both plugins should be in your search path. 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 | | TestStubs | true/false | false | Whether to generate test stub code |

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 9.1
  • Swift 4.0
  • swift-protobuf 1.1.1

License

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

Contributing

Please get involved! See our guidelines for contributing.

Releasing

Prior to creating a new release tag for SwiftGRPC, the .podspec file's version should be bumped, and the CocoaPods spec linter should be run to ensure that there are no new warnings/errors:

$ pod spec lint SwiftGRPC.podspec

Once a new release tag is created, the updated CocoaPods spec should also be pushed to the master specs repo:

$ pod trunk push SwiftGRPC.podspec