-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add protoc plugin handling to the prost-build Config and basic plugin
This refactors some of the private logic within prost-build's lib.rs so that it is compatible with generating the logic necessary to run a plugin for protoc or a build.rs file. In both cases, the output can be changed based on how the Config is built. This adds the capability for paramters passed in via protoc to a plugin to allow adjust this configuration, but the mechanics of that are left as a TODO until the design is solidified.
- Loading branch information
Showing
3 changed files
with
278 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extern crate prost; | ||
extern crate prost_types; | ||
|
||
use crate::prost::Message; | ||
use prost_types::compiler::{CodeGeneratorRequest, CodeGeneratorResponse}; | ||
use std::io::{Read, Write}; | ||
|
||
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> { | ||
let mut buf = Vec::new(); | ||
std::io::stdin().read_to_end(&mut buf)?; | ||
|
||
let request = CodeGeneratorRequest::decode(&*buf)?; | ||
|
||
let response: CodeGeneratorResponse = prost_build::Config::new().run_plugin(request); | ||
|
||
let mut out = Vec::new(); | ||
response.encode(&mut out)?; | ||
std::io::stdout().write_all(&out)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters