Skip to content

Commit

Permalink
feat: support protobuf in workspace mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Millione committed Jul 29, 2024
1 parent 21efbba commit cc1e4e1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pilota-build/src/codegen/protobuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ impl ProtobufBackend {
}

impl CodegenBackend for ProtobufBackend {
const PROTOCOL: &'static str = "protobuf";

fn codegen_struct_impl(&self, def_id: DefId, stream: &mut String, s: &rir::Message) {
let name = self.cx.rust_name(def_id);
let encoded_len = s
Expand Down
2 changes: 2 additions & 0 deletions pilota-build/src/codegen/thrift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ impl ThriftBackend {
}

impl CodegenBackend for ThriftBackend {
const PROTOCOL: &'static str = "thrift";

fn codegen_struct_impl(&self, def_id: DefId, stream: &mut String, s: &Message) {
let keep = self.keep_unknown_fields.contains(&def_id);
let name = self.cx.rust_name(def_id);
Expand Down
2 changes: 2 additions & 0 deletions pilota-build/src/codegen/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::{
};

pub trait CodegenBackend: Clone {
const PROTOCOL: &'static str;

fn cx(&self) -> &Context;
fn codegen_struct_impl(&self, _def_id: DefId, _stream: &mut String, _s: &rir::Message) {}
fn codegen_service_impl(&self, _def_id: DefId, _stream: &mut String, _s: &rir::Service) {}
Expand Down
9 changes: 8 additions & 1 deletion pilota-build/src/codegen/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ where
pilota = "*"
anyhow = "1"
volo = "*"
volo-thrift = "*""#
volo-{} = "*""#,
if B::PROTOCOL == "thrift" {
"thrift"
} else if B::PROTOCOL == "protobuf" {
"grpc"
} else {
panic!("unknown protocol")
}
))
.unwrap(),
);
Expand Down

0 comments on commit cc1e4e1

Please sign in to comment.