#grpc #bindings #http2 #metadata #ssl #future #server

sys ekiden-grpcio-sys

gRPC C核心库的FFI绑定

1个不稳定版本

使用旧的Rust 2015

0.2.4 2018年7月14日
0.2.3 2018年7月13日

#47 in #http2


用于 ekiden-grpcio

Apache-2.0

25MB
549K SLoC

C 236K SLoC // 0.2% comments C++ 124K SLoC // 0.2% comments Perl 58K SLoC // 0.1% comments C# 28K SLoC // 0.2% comments Go 25K SLoC // 0.1% comments Python 24K SLoC // 0.2% comments Visual Studio Project 18K SLoC GNU Style Assembly 10K SLoC // 0.1% comments M4 9K SLoC // 0.2% comments Bazel 5K SLoC // 0.1% comments Shell 4K SLoC // 0.5% comments Ada 1.5K SLoC // 0.2% comments Assembly 1.5K SLoC // 0.2% comments Visual Studio Solution 1K SLoC Pascal 1K SLoC // 0.2% comments Bitbake 862 SLoC // 0.0% comments Automake 839 SLoC // 0.2% comments Forge Config 673 SLoC // 0.6% comments Rust 655 SLoC // 0.0% comments Scons 579 SLoC // 0.2% comments Batch 499 SLoC // 0.0% comments SQL 88 SLoC Xcode Config 66 SLoC // 0.7% comments Ruby 39 SLoC // 0.5% comments JavaScript 19 SLoC // 0.5% comments NuGet Config 18 SLoC AWK 18 SLoC // 0.3% comments PHP 10 SLoC // 0.6% comments Cython 8 SLoC // 0.6% comments D 6 SLoC Poke 1 SLoC

包含 (晦涩的autoconf代码,23KB) configure.ac,(晦涩的autoconf代码,3KB) configure.ac,(晦涩的autoconf代码,1KB) configure.ac,(晦涩的autoconf代码,7KB) configure.ac,(晦涩的autoconf代码,3KB) configure.ac,(晦涩的autoconf代码,1KB) configure.ac

gRPC-rs

gRPC-rs 是 gRPC 核心的 Rust 封装。 gRPC CoregRPC 是一个高性能、开源的通用RPC框架,优先考虑移动和HTTP/2。

Crates.io docs.rs Build Status Build Status

状态

该项目仍在开发中。以下带有勾选符号的功能已支持

  • 基本的异步单例/流调用
  • SSL
  • 通用调用
  • 连接级别压缩
  • 互操作性测试
  • QPS基准测试
  • 自定义元数据
  • 健康检查
  • 反射
  • 身份验证
  • 负载均衡,客户端完全支持,服务器端负载报告尚未实现。

先决条件

  • CMake >= 3.8.0
  • Rust >= 1.36.0
  • binutils >= 2.22
  • 如果需要在编译时生成绑定,LLVM和Clang >= 3.9。

对于Linux和MacOS,您还需要安装gcc 7.3+(或clang 6+)。

为x86_64/arm64 Linux预生成了绑定。对于其他平台,绑定将在编译时生成。

对于Windows,您还需要安装以下软件

  • Active State Perl
  • yasm
  • Visual Studio 2015+

构建

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

链接OpenSSL时出错

如果您在构建项目时使用 gRPC-rs 时遇到链接器错误,请查看 openssl 功能部分,以获取可能的修复方法。

用法

从proto文件生成源代码

选项1 - 手动生成

  1. 安装protobuf编译器
$ cargo install protobuf-codegen
  1. 安装gRPC编译器
$ cargo install grpcio-compiler
  1. 生成源代码
$ protoc --rust_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_rust_plugin` example.proto

选项2 - 程序生成

可以通过使用 protoc-grpcio,通过你的 build.rs 文件来生成 Rust 模块,从而实现程序化生成。

有关更多信息及示例,请参阅 README

要将此项目作为依赖项添加

[dependencies]
grpcio = "0.13"

功能 boringssl

boringssl 功能启用了对 TLS 加密和某些认证机制的支持。在不需要时,例如在 intranet 中工作,您可以通过以下配置禁用它:

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

功能 prost-codecprotobuf-codec

gRPC-rs 默认使用 protobuf 包。如果您想使用 prost,可以启用 prost-codec 功能。您可能只需要启用这两个功能中的一个。尽管 grpcio 在同时启用这两个功能时也可以正常工作,但 grpcio-compiler 将不会按预期工作。

功能 opensslopenssl-vendored

gRPC-rs 随带 gRPC Core,默认使用 BoringSSL 而不是 OpenSSL。这可能会因为符号冲突和/或缺失符号而导致链接问题。要解决这个问题,您可以指定在您的 Cargo.toml 文件的 gprcio 功能列表中使用 "openssl",这需要 openssl (>=1.0.2)。例如:

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

功能 openssl-vendored 与功能 openssl 相同,但它将从捆绑的源构建 openssl。

性能

请参阅 benchmark 了解如何自行运行基准测试。

交叉编译

请参阅 cross_compile

贡献

在提交 PR 之前,请确保格式化和测试代码。

如果 grpc-sys/grpc 的内容已更新,您可能需要重新生成绑定。

$ cargo xtask bindgen

依赖项