Skip to content

Commit

Permalink
feat(build): Rename compile method with compile_protos (#1920)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Sep 4, 2024
1 parent bc6c36a commit e4c71b8
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn codegen(
.build_server(build_server)
.out_dir(&tempdir)
.file_descriptor_set_path(file_descriptor_set_path)
.compile(&iface_files, &include_dirs)
.compile_protos(&iface_files, &include_dirs)
.unwrap();

for path in std::fs::read_dir(tempdir.path()).unwrap() {
Expand Down
10 changes: 5 additions & 5 deletions examples/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::{env, path::PathBuf};
fn main() {
tonic_build::configure()
.type_attribute("routeguide.Point", "#[derive(Hash)]")
.compile(&["proto/routeguide/route_guide.proto"], &["proto"])
.compile_protos(&["proto/routeguide/route_guide.proto"], &["proto"])
.unwrap();

let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
tonic_build::configure()
.file_descriptor_set_path(out_dir.join("helloworld_descriptor.bin"))
.compile(&["proto/helloworld/helloworld.proto"], &["proto"])
.compile_protos(&["proto/helloworld/helloworld.proto"], &["proto"])
.unwrap();

tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
Expand All @@ -21,12 +21,12 @@ fn main() {
.server_attribute("Echo", "#[derive(PartialEq)]")
.client_mod_attribute("attrs", "#[cfg(feature = \"client\")]")
.client_attribute("Echo", "#[derive(PartialEq)]")
.compile(&["proto/attrs/attrs.proto"], &["proto"])
.compile_protos(&["proto/attrs/attrs.proto"], &["proto"])
.unwrap();

tonic_build::configure()
.build_server(false)
.compile(
.compile_protos(
&["proto/googleapis/google/pubsub/v1/pubsub.proto"],
&["proto/googleapis"],
)
Expand All @@ -39,7 +39,7 @@ fn main() {
tonic_build::configure()
.out_dir(smallbuff_copy)
.codec_path("crate::common::SmallBufferCodec")
.compile(&["proto/helloworld/helloworld.proto"], &["proto"])
.compile_protos(&["proto/helloworld/helloworld.proto"], &["proto"])
.unwrap();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/default_stubs/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
fn main() {
tonic_build::configure()
.compile(&["proto/test.proto"], &["proto"])
.compile_protos(&["proto/test.proto"], &["proto"])
.unwrap();
tonic_build::configure()
.generate_default_stubs(true)
.compile(&["proto/test_default.proto"], &["proto"])
.compile_protos(&["proto/test_default.proto"], &["proto"])
.unwrap();
}
2 changes: 1 addition & 1 deletion tests/disable_comments/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn main() {
.disable_comments("test.Service1.Rpc1")
.build_client(true)
.build_server(true)
.compile_with_config(config, &["proto/test.proto"], &["proto"])
.compile_protos_with_config(config, &["proto/test.proto"], &["proto"])
.unwrap();
}
2 changes: 1 addition & 1 deletion tests/extern_path/my_application/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() -> Result<(), std::io::Error> {
.build_server(false)
.build_client(true)
.extern_path(".uuid", "::uuid")
.compile(
.compile_protos(
&["service.proto", "uuid.proto"],
&["../proto/my_application", "../proto/uuid"],
)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/root-crate-path/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.extern_path(".foo.bar.baz.Animal", "crate::Animal")
.compile(&["foo.proto"], &["."])?;
.compile_protos(&["foo.proto"], &["."])?;

Ok(())
}
2 changes: 1 addition & 1 deletion tests/skip_debug/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
.skip_debug("test.Output")
.build_client(true)
.build_server(true)
.compile_with_config(config, &["proto/test.proto"], &["proto"])
.compile_protos_with_config(config, &["proto/test.proto"], &["proto"])
.unwrap();

// Add a dummy impl Debug to the skipped debug implementations to avoid missing impl Debug errors
Expand Down
2 changes: 1 addition & 1 deletion tests/use_arc_self/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
tonic_build::configure()
.use_arc_self(true)
.compile(&["proto/test.proto"], &["proto"])
.compile_protos(&["proto/test.proto"], &["proto"])
.unwrap();
}
2 changes: 1 addition & 1 deletion tests/wellknown-compiled/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {

tonic_build::configure()
.compile_well_known_types(true)
.compile_with_config(
.compile_protos_with_config(
config,
&["proto/google.proto", "proto/test.proto"],
&["proto"],
Expand Down
26 changes: 24 additions & 2 deletions tonic-build/src/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn compile_protos(proto: impl AsRef<Path>) -> io::Result<()> {
.parent()
.expect("proto file should reside in a directory");

self::configure().compile(&[proto_path], &[proto_dir])
self::configure().compile_protos(&[proto_path], &[proto_dir])
}

/// Non-path Rust types allowed for request/response types.
Expand Down Expand Up @@ -596,17 +596,39 @@ impl Builder {
}

/// Compile the .proto files and execute code generation.
#[deprecated(since = "0.12.3", note = "renamed to `compile_protos()`")]
pub fn compile(
self,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> io::Result<()> {
self.compile_with_config(Config::new(), protos, includes)
self.compile_protos(protos, includes)
}

/// Compile the .proto files and execute code generation using a
/// custom `prost_build::Config`.
#[deprecated(since = "0.12.3", note = "renamed to `compile_protos_with_config()`")]
pub fn compile_with_config(
self,
config: Config,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> io::Result<()> {
self.compile_protos_with_config(config, protos, includes)
}

/// Compile the .proto files and execute code generation.
pub fn compile_protos(
self,
protos: &[impl AsRef<Path>],
includes: &[impl AsRef<Path>],
) -> io::Result<()> {
self.compile_protos_with_config(Config::new(), protos, includes)
}

/// Compile the .proto files and execute code generation using a
/// custom `prost_build::Config`.
pub fn compile_protos_with_config(
self,
mut config: Config,
protos: &[impl AsRef<Path>],
Expand Down
2 changes: 1 addition & 1 deletion tonic-web/tests/integration/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
let protos = &["proto/test.proto"];

tonic_build::configure()
.compile(protos, &["proto"])
.compile_protos(protos, &["proto"])
.unwrap();

protos
Expand Down

0 comments on commit e4c71b8

Please sign in to comment.