#grpc #protobuf #rpc #tls #http2

grpcio

The rust language implementation of gRPC, base on the gRPC c core library

36 releases

0.9.0 May 24, 2021
0.8.2 Mar 10, 2021
0.7.2 May 26, 2021
0.7.1 Dec 18, 2020
0.1.0 Jul 27, 2017

#95 in Network programming

Download history 2617/week @ 2021-05-29 2927/week @ 2021-06-05 2392/week @ 2021-06-12 2402/week @ 2021-06-19 2987/week @ 2021-06-26 2602/week @ 2021-07-03 3040/week @ 2021-07-10 3021/week @ 2021-07-17 2974/week @ 2021-07-24 2894/week @ 2021-07-31 3073/week @ 2021-08-07 2736/week @ 2021-08-14 2561/week @ 2021-08-21 2499/week @ 2021-08-28 2459/week @ 2021-09-04 3860/week @ 2021-09-11

9,808 downloads per month
Used in 58 crates (43 directly)

Apache-2.0

17MB
354K SLoC

C++ 248K SLoC // 0.1% comments C 56K SLoC // 0.1% comments Python 26K SLoC // 0.2% comments Rust 13K SLoC // 0.0% comments Shell 5.5K SLoC // 0.5% comments Lua 1K SLoC // 0.1% comments Go 1K SLoC // 0.2% comments Batch 641 SLoC // 0.0% comments SWIG 346 SLoC // 0.3% comments PHP 333 SLoC // 0.8% comments XSL 185 SLoC Perl 154 SLoC // 0.1% comments Automake 145 SLoC // 0.3% comments Swift 140 SLoC SQL 97 SLoC PowerShell 63 SLoC // 0.2% comments C# 63 SLoC // 0.4% comments GNU Style Assembly 55 SLoC Pan 49 SLoC // 0.1% comments Ruby 46 SLoC // 0.5% comments Visual Studio Solution 27 SLoC Alex 19 SLoC Prolog 12 SLoC D 5 SLoC

gRPC-rs

gRPC-rs is a Rust wrapper of gRPC Core. gRPC is a high performance, open source universal RPC framework that puts mobile and HTTP/2 first.

Crates.io docs.rs Build Status Build Status

Status

This project is still under development. The following features with the check marks are supported:

  • Basic asynchronous unary/steaming call
  • SSL
  • Generic call
  • Connection level compression
  • Interoperability test
  • QPS benchmark
  • Custom metadata
  • Health check
  • Reflection
  • Authentication
  • Load balance, client side is fully supported, server side load report is not implemented yet.

Prerequisites

  • CMake >= 3.8.0
  • Rust >= 1.36.0
  • binutils >= 2.22
  • LLVM and Clang >= 3.9 if you need to generate bindings at compile time.
  • By default, the secure feature is provided by boringssl. You can also use openssl instead by enabling openssl feature.

For Linux and MacOS, you also need to install gcc 4.9+ (or clang) too.

Bindings are pre-generated for x86_64/arm64 Linux. For other platforms, bindings are generated at compile time.

For Windows, you also need to install following software:

  • Active State Perl
  • yasm
  • Visual Studio 2015+

Build

$ cargo xtask submodule # if you just cloned the repository
$ cargo build

Error linking OpenSSL

If you're getting linker errors when building your project using gRPC-rs, head down to the openssl feature section for a possible fix.

Usage

To generate the sources from proto files:

Option 1 - Manual Generation

  1. Install the protobuf compiler:
$ cargo install protobuf-codegen
  1. Install the gRPC compiler:
$ cargo install grpcio-compiler
  1. Generate the sources:
$ protoc --rust_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_rust_plugin` example.proto

Option 2 - Programmatic Generation

Programmatic generation can be used to generate Rust modules from proto files via your build.rs by using protoc-grpcio.

For more information and examples see README.

To include this project as a dependency:

[dependencies]
grpcio = "0.6"

Feature secure

secure feature enables support for TLS encryption and some authentication mechanism. When you do not need it, for example when working in intranet, you can disable it by using the following configuration:

[dependencies]
grpcio = { version = "0.6", default-features = false, features = ["protobuf-codec"] }

Feature prost-codec and protobuf-codec

gRPC-rs uses protobuf crate by default. If you want to use prost instead, you can enable prost-codec feature. You probably only want to enable only one of the two features. Though grpcio is completely fine with both features enabled at the same time, grpcio-compiler will not going to work as expected.

Feature openssl and openssl-vendored

gRPC-rs comes vendored with gRPC Core, which by default uses BoringSSL instead of OpenSSL. This may cause linking issues due to symbol clashes and/or missing symbols when another one of your dependencies uses OpenSSL. To resolve this, you can tell gRPC-rs to use OpenSSL too by specifying "openssl" in your Cargo.toml's features list for gprcio, which requires openssl (>=1.0.2). E.g.:

[dependencies]
grpcio = { version = "0.6", features = ["openssl"] }

Feature openssl-vendored is the same as feature openssl except it will build openssl from bundled sources.

Performance

See benchmark to find out how to run a benchmark by yourself.

Cross Compile

See cross_compile

Contributing

Make sure to format and test the code before sending a PR.

If the content in grpc-sys/grpc is updated, you may need to regenerate bindings:

$ cargo xtask bindgen

Dependencies

~3.5–7MB
~159K SLoC