Skip to content

becomeliminal/rust-proto-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 = "jackmarsh",
    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
        └── 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"],
    languages = {
        "rust": rust_grpc_language(),
    },
    visibility = ["PUBLIC"],
    deps = [
        "//third_party/rust:prost",
        "//third_party/rust:tonic",
    ],
)

And you can use the protoc generated service.rs and service.tonic.rs in your Rust code:

rust_binary(
    name = "service_test",
    edition = "2021",
    root = "src/main.rs",
    deps = [
        "//path/to/your/package/src/proto:_proto#rust",
        "//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

About

Rust language implementation for Protobuf and Please

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published