Nav apraksta

George Barnett 0e4aac54e8 Add editorconfig (#1920) 1 gadu atpakaļ
.github 7f2a6df168 Add Swift 6 nightly CI (#1919) 1 gadu atpakaļ
Examples 666e30dff3 Update SwiftFormat version (#1639) 2 gadi atpakaļ
FuzzTesting c4682a9c5d Connect EmbeddedChannel when FuzzTesting (#1569) 2 gadi atpakaļ
Performance 492da8913f Add some slack to allocation tests (#1884) 1 gadu atpakaļ
Plugins 0da4b47775 Add reflection support to plugin (#1835) 1 gadu atpakaļ
Protos 53e2739912 Add target and generated code for QPS (#1827) 1 gadu atpakaļ
Sources eb503ca626 Start the idle timer when the connection is ready (#1915) 1 gadu atpakaļ
Tests eb503ca626 Start the idle timer when the connection is ready (#1915) 1 gadu atpakaļ
dev 8a70336d12 Remove the gRPC Authors copyright header from generated swift files (#1612) 2 gadi atpakaļ
docs c596dfb5ec Update tutorial docs (#1889) 1 gadu atpakaļ
scripts 73a34ffc0f Cache swift-format (#1887) 1 gadu atpakaļ
.editorconfig 0e4aac54e8 Add editorconfig (#1920) 1 gadu atpakaļ
.gitignore 99e9956158 Add support for ordo-one/package-benchmark (#1678) 2 gadi atpakaļ
.gitmodules 63c6acfa40 Move CgRPC, gRPC, and QuickProto to "Sources" directory and add new top-level Package.swift. 9 gadi atpakaļ
.spi.yml 81873c0ced Add reflection service to .spi.yml (#1742) 2 gadi atpakaļ
.swift-format 9cdcd2d9de Switch to swift-format 2 gadi atpakaļ
AUTHORS 0aa90a79ee Relicense to Apache 2, change owners to "the gRPC Authors". 8 gadi atpakaļ
CODE-OF-CONDUCT.md 5ef0870727 Add/update GOVERNANCE.md, CODE-OF-CONDUCT.md and CONTRIBUTING.md (#595) 6 gadi atpakaļ
CONTRIBUTING.md 5ef0870727 Add/update GOVERNANCE.md, CODE-OF-CONDUCT.md and CONTRIBUTING.md (#595) 6 gadi atpakaļ
GOVERNANCE.md 5ef0870727 Add/update GOVERNANCE.md, CODE-OF-CONDUCT.md and CONTRIBUTING.md (#595) 6 gadi atpakaļ
LICENSE 6dde0518ca Revert to Apache 2.0 license verbatim [skip ci] (#504) 6 gadi atpakaļ
MAINTAINERS.md e0c70ce6f8 Add MAINTAINERS.md. (#564) (#576) 6 gadi atpakaļ
NOTICES.txt e9273f1d54 [CodeGenLib] Translator for enums containing type aliases and static properties (#1733) 2 gadi atpakaļ
PATENTS 36f2bde28e Add PATENTS declaration 9 gadi atpakaļ
Package.swift 706023bc9c Add a NIOPosix based client transport (#1909) 1 gadu atpakaļ
README.md 7028cfb537 Raise minimum swift version to 5.8 (#1825) 1 gadu atpakaļ
SECURITY.md 7fbc418471 Add a security policy. (#1193) 4 gadi atpakaļ

README.md

CI Latest Version

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.