Skip to content

Commit

Permalink
Add protoc-gen-prost crate, a protoc codegen plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuetuopay committed Jun 25, 2021
1 parent e2c5907 commit 4096053
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
"prost-derive",
"prost-types",
"protobuf",
"protoc-gen-prost",
"tests",
"tests-2015",
"tests-no-std",
Expand Down
15 changes: 15 additions & 0 deletions protoc-gen-prost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "protoc-gen-prost"
version = "0.7.0"
authors = ["Tokio Contributors <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/tokio-rs/prost"
documentation = "https://docs.rs/prost-build"
readme = "README.md"
description = "A Protocol Buffers implementation for the Rust Language."
edition = "2018"

[dependencies]
prost = { version = "0.7.0", path = "..", default-features = false }
prost-build = { version = "0.7.0", path = "../prost-build", default-features = false }
prost-types = { version = "0.7.0", path = "../prost-types", default-features = false }
26 changes: 26 additions & 0 deletions protoc-gen-prost/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::io::{Read, Result, Write};

use prost::Message;
use prost_build::Config;
use prost_types::compiler::CodeGeneratorRequest;

fn main() {
if let Err(e) = faillible_main() {
eprintln!("{}", e);
std::process::exit(1);
}
}

fn faillible_main() -> Result<()> {
let mut buf = Vec::new();
std::io::stdin().read_to_end(&mut buf)?;

let req = CodeGeneratorRequest::decode(buf.as_slice()).unwrap();
let res = Config::new_from_opts(req.parameter(), true).compile_request(req);

buf.clear();
res.encode(&mut buf).unwrap();
std::io::stdout().write_all(&buf)?;

Ok(())
}

0 comments on commit 4096053

Please sign in to comment.