Git Product home page Git Product logo

protoc-grpcio's Introduction

protoc-grpcio

crates.io Build Status License

A programmatic API to the grpc-rs compiler.

Requirements

  • You must have Google's Protocol Buffer compiler (protoc) installed and in PATH.

Example build.rs

For a project laid out like so:

$ tree
.
├── build.rs
├── Cargo.toml
└── src
    ├── client.rs
    ├── protos
    │   ├── example
    │   │   └── diner.proto
    │   └── mod.rs
    └── server.rs

3 directories, 7 files

The build.rs might look like:

extern crate protoc_grpcio;

fn main() {
    let proto_root = "src/protos";
    println!("cargo:rerun-if-changed={}", proto_root);
    protoc_grpcio::compile_grpc_protos(
        &["example/diner.proto"],
        &[proto_root],
        &proto_root
    ).expect("Failed to compile gRPC definitions!");
}

Example Cargo.toml

And the Cargo.toml might look like:

[package]
# ...
build = "build.rs"

[lib]
name = "protos"
path = "src/protos/mod.rs"

[[bin]]
name = "server"
path = "src/server.rs"

[[bin]]
name = "client"
path = "src/client.rs"

[dependencies]
futures = "0.1.16"
grpcio = "0.2.0"
protobuf = "1.4.1"

[build-dependencies]
protoc-grpcio = "0.1.1"

You can inspect this example under example/ by compiling and running the example server in one shell session:

cargo run --manifest-path example/Cargo.toml --bin server
...
    Finished dev [unoptimized + debuginfo] target(s) in 27.97 secs
     Running `example/target/debug/server`
listening on 127.0.0.1:34431

And then running the client in another:

$ cargo run --manifest-path example/Cargo.toml --bin client 34431
...
    Finished dev [unoptimized + debuginfo] target(s) in 1.28 secs
     Running `example/target/debug/client 34431`
Ate items: SPAM items: EGGS and got charged $0.30

Credits

Credit to both the TiKV project developers for (grpc-rs) and Stepan Koltsov (@stepancheg, rust-protobuf) for their amazing work bringing Protocol Buffers and gRPC support to Rust.

protoc-grpcio's People

Contributors

mtp401 avatar jsirois avatar marcelbuesing avatar jasonahills avatar mehcode avatar

Watchers

James Cloos avatar Light Ning avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.