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

feat(build): Add extern_path config support #223

Merged
merged 2 commits into from
Jan 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tonic-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mod server;
pub struct Builder {
build_client: bool,
build_server: bool,
extern_path: Vec<(String, String)>,
field_attributes: Vec<(String, String)>,
type_attributes: Vec<(String, String)>,
out_dir: Option<PathBuf>,
Expand Down Expand Up @@ -111,6 +112,17 @@ impl Builder {
self
}

/// Declare externally provided Protobuf package or type.
///
/// Passed directly to `prost_build::Config.extern_path`.
pub fn extern_path(mut self, proto_path: impl AsRef<str>, rust_path: impl AsRef<str>) -> Self {
self.extern_path.push((
proto_path.as_ref().to_string(),
rust_path.as_ref().to_string(),
));
self
}

/// Add additional attribute to matched messages, enums, and one-offs.
///
/// Passed directly to `prost_build::Config.field_attribute`.
Expand Down Expand Up @@ -142,6 +154,9 @@ impl Builder {
.unwrap_or_else(|| PathBuf::from(std::env::var("OUT_DIR").unwrap()));

config.out_dir(out_dir.clone());
for (proto_path, rust_path) in self.extern_path.iter() {
config.extern_path(proto_path, rust_path);
}
for (path, attr) in self.field_attributes.iter() {
config.field_attribute(path, attr);
}
Expand Down Expand Up @@ -171,6 +186,7 @@ pub fn configure() -> Builder {
build_client: true,
build_server: true,
out_dir: None,
extern_path: Vec::new(),
field_attributes: Vec::new(),
type_attributes: Vec::new(),
#[cfg(feature = "rustfmt")]
Expand Down