Giter Site home page Giter Site logo

rust-proto-rules's Introduction

Rust Proto Rules

Rust protobuf definitions for the Proto plugin, for the Please build system.

Basic Usage

First, add the proto plugin and this plugin to your project:

# BUILD
plugin_repo(
    name = "proto",
    revision = "<Some git tag, commit, or other reference>",
)

plugin_repo(
    name = "rust_proto",
    owner = "odonate",
    plugin = "rust-proto",
    revision = "<Some git tag, commit, or other reference>",
)

Then add rust to the list of language definitions for the proto plugin:

[Plugin "proto"]
LanguageDef = ///rust_proto//build_defs:rust_proto

You'll then need to add the protobuf sdk, as well as the gRPC sdk if you want to use grpc_library(). You can copy the rust_crate() rules from third_party/rust/BUILD in this repo to get started.

Now add the rust proto plugin to your .plzconfig:

[Plugin "rust_proto"]
Target = //plugins:rust_proto
ProtoPlugin = //third_party/rust:protoc_gen_prost
ProtoDep = //third_party/rust:prost
GrpcPlugin = //third_party/rust:protoc_gen_tonic
GrpcDep = //third_party/rust:tonic

The Rust plugin and Rust Proto plugin expects a specific package structure:

path/to/your/package/
├── BUILD
└── src
    ├── lib.rs || main.rs
    └── proto
        ├── BUILD
        ├── mod.rs
        └── service.proto

You can then use proto_library() or grpc_library() to generate Rust code for your .proto files:

grpc_library(
    name = "proto",
    srcs = ["service.proto"],
    visibility = ["PUBLIC"],
    deps = [
        "//third_party/rust:prost",
        "//third_party/rust:tonic",
    ],
)

export_file(
    name = "mod",
    src = "mod.rs",
    visibility = ["PUBLIC"],
)

You must define a mod.rs module to expose the generated proto files:

pub mod your_proto_package {
    include!("your.proto.package.rs");
}

pub mod your_proto_package_tonic {
    include!("your.proto.package.rs");
    include!("your.proto.package.tonic.rs");
}
rust_binary(
    name = "service_test",
    edition = "2021",
    root = "src/main.rs",
    deps = [
        "//path/to/your/package/src/proto:_proto#rust",
        "//path/to/your/package/src/proto:mod",
        "//third_party/rust:prost",
        "//third_party/rust:tonic",
    ],
)

See the Proto plugin for more information on these rules.

Configuration

This plugin can be configured via the plugins section as follows:

[Plugin "rust_proto"]
SomeConfig = some-value

rust-proto-rules's People

Contributors

jackmarsh avatar

Watchers

 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.