Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to split generated pilota files #510

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
25 changes: 16 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"examples/volo-gen",
"benchmark",
"tests/code-generation",
"tests/code-generation-split",
]
resolver = "2"

Expand All @@ -24,12 +25,12 @@ license = "MIT OR Apache-2.0"
rust-version = "1.80.0"

[workspace.dependencies]
pilota = "0.11"
pilota-build = "0.11"
pilota-thrift-parser = "0.11"
# pilota = { git = "https://github.com/cloudwego/pilota", branch = "main" }
# pilota-build = { git = "https://github.com/cloudwego/pilota", branch = "main" }
# pilota-thrift-parser = { git = "https://github.com/cloudwego/pilota", branch = "main" }
#pilota = "0.11"
#pilota-build = "0.11"
#pilota-thrift-parser = "0.11"
pilota = { git = "https://github.com/cloudwego/pilota", branch = "main" }
pilota-build = { git = "https://github.com/cloudwego/pilota", branch = "main" }
pilota-thrift-parser = { git = "https://github.com/cloudwego/pilota", branch = "main" }

motore = "0.4"
# motore = { git = "https://github.com/cloudwego/motore", branch = "main" }
Expand Down
1 change: 1 addition & 0 deletions examples/volo-gen/volo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ entries:
thrift:
filename: thrift_gen.rs
protocol: thrift
split_generated_files: true
services:
- idl:
source: local
Expand Down
23 changes: 23 additions & 0 deletions tests/code-generation-split/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "code-generation-split"
version = "0.0.0"
edition.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
authors.workspace = true
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
doctest = false

[dependencies]
pilota.workspace = true
volo = { path = "../../volo" }
volo-grpc = { path = "../../volo-grpc" }
volo-thrift = { path = "../../volo-thrift" }

[build-dependencies]
volo-build = { path = "../../volo-build" }
3 changes: 3 additions & 0 deletions tests/code-generation-split/build.rs
Millione marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
volo_build::ConfigBuilder::default().write().unwrap();
}
6 changes: 6 additions & 0 deletions tests/code-generation-split/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod gen {
include!(concat!(env!("OUT_DIR"), "/thrift_gen.rs"));
include!(concat!(env!("OUT_DIR"), "/proto_gen.rs"));
}

pub use gen::*;
5 changes: 5 additions & 0 deletions tests/code-generation-split/thrift/common.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for test dedups
namespace rs common

struct CommonReq {
}
5 changes: 5 additions & 0 deletions tests/code-generation-split/thrift/common2.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for test dedups
namespace rs common

struct CommonReq {
}
25 changes: 25 additions & 0 deletions tests/code-generation-split/thrift/test.thrift
Millione marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace rs test

include "common.thrift"
include "common2.thrift"

struct TestRequest {
254: optional common.CommonReq common,
255: optional common2.CommonReq common2,
}

struct TestResponse {
1: required string message,
}

service TestService {
TestResponse Test (1: TestRequest req),
TestResponse test (1: TestRequest Req),
TestResponse Test2 (1: TestRequest type),
TestResponse Test3 (1: TestRequest self),
}

service testService {
TestResponse Test (1: TestRequest req),
TestResponse test (1: TestRequest Req),
}
37 changes: 37 additions & 0 deletions tests/code-generation-split/volo.yml
Millione marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Please refer to https://www.cloudwego.io/docs/volo/guide/config/ for the configuration file format.
entries:
proto:
filename: proto_gen.rs
protocol: protobuf
split_generated_files: true
repos:
protobuf:
url: https://github.com/protocolbuffers/protobuf.git
ref: HEAD
lock: cb93f9aa6e81329e368f09ded42d17c3f26442f2
services:
- idl:
source: git
repo: protobuf
path: examples/addressbook.proto
includes:
- examples
thrift:
filename: thrift_gen.rs
protocol: thrift
split_generated_files: true
repos:
thrift:
url: https://github.com/apache/thrift.git
ref: HEAD
lock: 9bd1f1bee7bf59080492bbd3213ca1fed57ab4d6
services:
- idl:
source: local
path: thrift/test.thrift
- idl:
source: git
repo: thrift
path: test/Service.thrift
dedups:
- CommonReq
10 changes: 10 additions & 0 deletions volo-build/src/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ impl InnerBuilder {
}
}

pub fn split_generated_files(self, split_generated_files: bool) -> Self {
match self {
InnerBuilder::Protobuf(inner) => {
InnerBuilder::Protobuf(inner.split_generated_files(split_generated_files))
}
InnerBuilder::Thrift(inner) => InnerBuilder::Thrift(inner.split_generated_files(split_generated_files)),
}
}

pub fn common_crate_name(self, name: FastStr) -> Self {
match self {
InnerBuilder::Protobuf(inner) => InnerBuilder::Protobuf(inner.common_crate_name(name)),
Expand Down Expand Up @@ -192,6 +201,7 @@ impl ConfigBuilder {
.add_services(service_builders)
.ignore_unused(!entry.common_option.touch_all)
.special_namings(entry.common_option.special_namings)
.split_generated_files(entry.common_option.split_generated_files)
.dedup(entry.common_option.dedups)
.write()?;

Expand Down
8 changes: 8 additions & 0 deletions volo-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ impl<MkB, Parser> Builder<MkB, Parser> {
self
}

pub fn split_generated_files(
mut self,
split_generated_files: bool
) -> Self {
self.pilota_builder = self.pilota_builder.split_generated_files(split_generated_files);
self
}

pub fn special_namings(mut self, namings: impl IntoIterator<Item = FastStr>) -> Self {
self.pilota_builder = self.pilota_builder.special_namings(namings);
self
Expand Down
2 changes: 2 additions & 0 deletions volo-build/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct CommonOption {
pub dedups: Vec<FastStr>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub special_namings: Vec<FastStr>,
#[serde(default, skip_serializing_if = "is_false")]
pub split_generated_files: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
6 changes: 6 additions & 0 deletions volo-build/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ where
.dedup(config.common_option.dedups)
.special_namings(config.common_option.special_namings)
.common_crate_name(config.common_crate_name)
.split_generated_files(config.common_option.split_generated_files)
.pilota_builder
.compile_with_config(idl_services, pilota_build::Output::Workspace(work_dir));
}
Expand Down Expand Up @@ -148,6 +149,11 @@ where
self
}

pub fn split_generated_files(mut self, split_generated_files: bool) -> Self {
self.pilota_builder = self.pilota_builder.split_generated_files(split_generated_files);
self
}

pub fn touch(
mut self,
items: impl IntoIterator<Item = (PathBuf, Vec<impl Into<String>>)>,
Expand Down
1 change: 1 addition & 0 deletions volo-cli/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl CliCommand for Migrate {
touch_all: old_entry.touch_all,
dedups: Vec::new(),
special_namings: Vec::new(),
split_generated_files: false,
},
};

Expand Down
Loading