Skip to content

feat: Extract prost into its own tonic based crates #2321

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ members = [
"tonic-health",
"tonic-types",
"tonic-reflection",
"tonic-prost",
"tonic-prost-build",
"tonic-web", # Non-published crates
"examples",
"codegen",
Expand Down
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ prettyplease = "0.2"
quote = "1"
syn = "2"
tempfile = "3.8.0"
tonic-build = {path = "../tonic-build", default-features = false, features = ["prost", "cleanup-markdown"]}
tonic-prost-build = {path = "../tonic-prost-build", default-features = false, features = ["cleanup-markdown"]}
4 changes: 2 additions & 2 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use protox::prost::Message as _;
use quote::quote;
use tonic_build::FileDescriptorSet;
use tonic_prost_build::FileDescriptorSet;

fn main() {
// tonic-health
Expand Down Expand Up @@ -87,7 +87,7 @@ fn codegen(

write_fds(&fds, &file_descriptor_set_path);

tonic_build::configure()
tonic_prost_build::configure()
.build_client(build_client)
.build_server(build_server)
.out_dir(&tempdir)
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,4 @@ hyper-rustls = { version = "0.27.0", features = ["http2", "ring", "tls12"], opti
tower-http = { version = "0.6", optional = true }

[build-dependencies]
tonic-build = { path = "../tonic-build", features = ["prost"] }
tonic-prost-build = { path = "../tonic-prost-build" }
14 changes: 7 additions & 7 deletions examples/build.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use std::{env, path::PathBuf};

fn main() {
tonic_build::configure()
tonic_prost_build::configure()
.compile_protos(&["proto/routeguide/route_guide.proto"], &["proto"])
.unwrap();

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

tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
tonic_prost_build::compile_protos("proto/echo/echo.proto").unwrap();

tonic_build::compile_protos("proto/unaryecho/echo.proto").unwrap();
tonic_prost_build::compile_protos("proto/unaryecho/echo.proto").unwrap();

tonic_build::configure()
tonic_prost_build::configure()
.server_mod_attribute("attrs", "#[cfg(feature = \"server\")]")
.server_attribute("Echo", "#[derive(PartialEq)]")
.client_mod_attribute("attrs", "#[cfg(feature = \"client\")]")
.client_attribute("Echo", "#[derive(PartialEq)]")
.compile_protos(&["proto/attrs/attrs.proto"], &["proto"])
.unwrap();

tonic_build::configure()
tonic_prost_build::configure()
.build_server(false)
.compile_protos(
&["proto/googleapis/google/pubsub/v1/pubsub.proto"],
Expand All @@ -35,7 +35,7 @@ fn main() {

let smallbuff_copy = out_dir.join("smallbuf");
let _ = std::fs::create_dir(smallbuff_copy.clone()); // This will panic below if the directory failed to create
tonic_build::configure()
tonic_prost_build::configure()
.out_dir(smallbuff_copy)
.codec_path("crate::common::SmallBufferCodec")
.compile_protos(&["proto/helloworld/helloworld.proto"], &["proto"])
Expand Down
2 changes: 1 addition & 1 deletion interop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ tower = "0.5"
tracing-subscriber = {version = "0.3"}

[build-dependencies]
tonic-build = {path = "../tonic-build", features = ["prost"]}
tonic-prost-build = {path = "../tonic-prost-build"}
2 changes: 1 addition & 1 deletion interop/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
let proto = "proto/grpc/testing/test.proto";

tonic_build::compile_protos(proto).unwrap();
tonic_prost_build::compile_protos(proto).unwrap();

// prevent needing to rebuild if files (or deps) haven't changed
println!("cargo:rerun-if-changed={proto}");
Expand Down
2 changes: 1 addition & 1 deletion tests/ambiguous_methods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ prost = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/ambiguous_methods/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/ambiguous_methods.proto").unwrap();
tonic_prost_build::compile_protos("proto/ambiguous_methods.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ tower = "0.5"
tower-http = {version = "0.6", features = ["map-response-body", "map-request-body"]}

[build-dependencies]
tonic-build = {path = "../../tonic-build" }
tonic-prost-build = {path = "../../tonic-prost-build" }
2 changes: 1 addition & 1 deletion tests/compression/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/test.proto").unwrap();
tonic_prost_build::compile_protos("proto/test.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/default_stubs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ tonic = {path = "../../tonic"}
tempfile = "3.20"

[build-dependencies]
tonic-build = {path = "../../tonic-build" }
tonic-prost-build = {path = "../../tonic-prost-build" }
4 changes: 2 additions & 2 deletions tests/default_stubs/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn main() {
tonic_build::configure()
tonic_prost_build::configure()
.compile_protos(&["proto/test.proto"], &["proto"])
.unwrap();
tonic_build::configure()
tonic_prost_build::configure()
.generate_default_stubs(true)
.compile_protos(&["proto/test_default.proto"], &["proto"])
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion tests/deprecated_methods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "MIT"
[dependencies]
prost = "0.14"
tonic = { path = "../../tonic" }
tonic-prost = { path = "../../tonic-prost" }

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
tonic-prost-build = { path = "../../tonic-prost-build" }
2 changes: 1 addition & 1 deletion tests/deprecated_methods/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/test.proto").unwrap();
tonic_prost_build::compile_protos("proto/test.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/disable_comments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ prost = "0.14"
tonic = { path = "../../tonic" }

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
tonic-prost-build = { path = "../../tonic-prost-build" }
4 changes: 2 additions & 2 deletions tests/disable_comments/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
let mut config = tonic_build::Config::default();
let mut config = tonic_prost_build::Config::default();
config.disable_comments(["test.Input1", "test.Output1"]);
tonic_build::configure()
tonic_prost_build::configure()
.disable_comments("test.Service1")
.disable_comments("test.Service1.Rpc1")
.build_client(true)
Expand Down
2 changes: 1 addition & 1 deletion tests/extern_path/my_application/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ tonic = {path = "../../../tonic"}
uuid = {package = "uuid1", path = "../uuid"}

[build-dependencies]
tonic-build = {path = "../../../tonic-build"}
tonic-prost-build = {path = "../../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/extern_path/my_application/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() -> Result<(), std::io::Error> {
tonic_build::configure()
tonic_prost_build::configure()
.build_server(false)
.build_client(true)
.extern_path(".uuid", "::uuid")
Expand Down
2 changes: 1 addition & 1 deletion tests/included_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ prost = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/included_service/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/includer.proto").unwrap();
tonic_prost_build::compile_protos("proto/includer.proto").unwrap();
}
3 changes: 2 additions & 1 deletion tests/integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bytes = "1.0"
prost = "0.14"
tokio = {version = "1.0", features = ["macros", "rt-multi-thread", "net", "sync"]}
tonic = {path = "../../tonic"}
tonic-prost = {path = "../../tonic-prost"}
tracing-subscriber = {version = "0.3"}

[dev-dependencies]
Expand All @@ -24,4 +25,4 @@ tower-http = { version = "0.6", features = ["set-header", "trace"] }
tower-service = "0.3"

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
4 changes: 2 additions & 2 deletions tests/integration_tests/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
tonic_build::compile_protos("proto/test.proto").unwrap();
tonic_build::compile_protos("proto/stream.proto").unwrap();
tonic_prost_build::compile_protos("proto/test.proto").unwrap();
tonic_prost_build::compile_protos("proto/stream.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/root-crate-path/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ prost = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/root-crate-path/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
tonic_prost_build::configure()
.extern_path(".foo.bar.baz.Animal", "crate::Animal")
.compile_protos(&["foo.proto"], &["."])?;

Expand Down
2 changes: 1 addition & 1 deletion tests/same_name/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ prost = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/same_name/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/foo.proto").unwrap();
tonic_prost_build::compile_protos("proto/foo.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/service_named_result/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ prost = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/service_named_result/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/result.proto").unwrap();
tonic_prost_build::compile_protos("proto/result.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/service_named_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ prost = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/service_named_service/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/foo.proto").unwrap();
tonic_prost_build::compile_protos("proto/foo.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/skip_debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ tonic = { path = "../../tonic" }
static_assertions = "1"

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
tonic-prost-build = { path = "../../tonic-prost-build" }
2 changes: 1 addition & 1 deletion tests/skip_debug/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
tonic_build::configure()
tonic_prost_build::configure()
.skip_debug("test.Test")
.skip_debug("test.Output")
.build_client(true)
Expand Down
2 changes: 1 addition & 1 deletion tests/stream_conflict/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ prost = "0.14"
tonic = { path = "../../tonic" }

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
tonic-prost-build = { path = "../../tonic-prost-build" }
2 changes: 1 addition & 1 deletion tests/stream_conflict/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/stream_conflict.proto").unwrap();
tonic_prost_build::compile_protos("proto/stream_conflict.proto").unwrap();
}
2 changes: 1 addition & 1 deletion tests/use_arc_self/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ prost = "0.14"
tonic = {path = "../../tonic", features = ["gzip"]}

[build-dependencies]
tonic-build = {path = "../../tonic-build" }
tonic-prost-build = {path = "../../tonic-prost-build" }
2 changes: 1 addition & 1 deletion tests/use_arc_self/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
tonic_build::configure()
tonic_prost_build::configure()
.use_arc_self(true)
.compile_protos(&["proto/test.proto"], &["proto"])
.unwrap();
Expand Down
3 changes: 2 additions & 1 deletion tests/web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ prost = "0.14"
tokio = { version = "1", features = ["macros", "rt", "net"] }
tokio-stream = { version = "0.1", features = ["net"] }
tonic = { path = "../../tonic" }
tonic-prost = { path = "../../tonic-prost" }

[dev-dependencies]
tonic-web = { path = "../../tonic-web" }

[build-dependencies]
tonic-build = { path = "../../tonic-build" }
tonic-prost-build = { path = "../../tonic-prost-build" }
2 changes: 1 addition & 1 deletion tests/web/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
let protos = &["proto/test.proto"];

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

Expand Down
2 changes: 1 addition & 1 deletion tests/wellknown-compiled/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ prost = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/wellknown-compiled/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
tonic_build::configure()
tonic_prost_build::configure()
.extern_path(".google.protobuf.Empty", "()")
.compile_well_known_types(true)
.compile_protos(&["proto/google.proto", "proto/test.proto"], &["proto"])
Expand Down
2 changes: 1 addition & 1 deletion tests/wellknown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ prost-types = "0.14"
tonic = {path = "../../tonic"}

[build-dependencies]
tonic-build = {path = "../../tonic-build"}
tonic-prost-build = {path = "../../tonic-prost-build"}
2 changes: 1 addition & 1 deletion tests/wellknown/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
tonic_build::compile_protos("proto/wellknown.proto").unwrap();
tonic_prost_build::compile_protos("proto/wellknown.proto").unwrap();
}
10 changes: 1 addition & 9 deletions tonic-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ rust-version = { workspace = true }
[dependencies]
prettyplease = { version = "0.2" }
proc-macro2 = "1.0"
prost-build = { version = "0.14", optional = true }
prost-types = { version = "0.14", optional = true }
quote = "1.0"
syn = "2.0"

[features]
default = ["transport", "prost"]
prost = ["prost-build", "dep:prost-types"]
cleanup-markdown = ["prost-build?/cleanup-markdown"]
default = ["transport"]
transport = []

[lints]
Expand All @@ -38,8 +34,4 @@ all-features = true
allowed_external_types = [
# major released
"proc_macro2::*",

# not major released
"prost_build::*",
"prost_types::*",
]
5 changes: 5 additions & 0 deletions tonic-build/src/code_gen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! Generic code generation for gRPC services.
//!
//! This module provides the generic infrastructure for generating
//! client and server code from service definitions.
use std::collections::HashSet;

use proc_macro2::TokenStream;
Expand Down
12 changes: 7 additions & 5 deletions tonic-build/src/compile_settings.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//! Compilation settings for code generation.

/// Settings used when compiling generated code.
#[derive(Debug, Clone)]
pub(crate) struct CompileSettings {
#[cfg(feature = "prost")]
pub(crate) codec_path: String,
pub struct CompileSettings {
/// The path to the codec to use for encoding/decoding messages.
pub codec_path: String,
}

impl Default for CompileSettings {
fn default() -> Self {
Self {
#[cfg(feature = "prost")]
codec_path: "tonic::codec::ProstCodec".to_string(),
codec_path: "tonic_prost::ProstCodec".to_string(),
}
}
}
Loading
Loading