From 2979dd476e0978573cb40def6a5ec36658b483f7 Mon Sep 17 00:00:00 2001 From: charles Date: Tue, 9 Jun 2026 22:25:35 -0700 Subject: [PATCH] Remove alloc guards and update codegen Remove unnecessary `alloc` feature guards in `roto-tonic`. Add `roto-runtime` dependency to `codegen`, fix test data paths, and include `async-trait` in the hello world build test. --- Cargo.lock | 1 + codegen/Cargo.toml | 1 + codegen/src/runtime/mod.rs | 2 +- codegen/tests/test_helloworld_build.rs | 13 +- roto-tonic/src/generated/interop.rs | 30 ---- test_output.log | 229 ------------------------- 6 files changed, 13 insertions(+), 263 deletions(-) delete mode 100644 test_output.log diff --git a/Cargo.lock b/Cargo.lock index 56c9fe8..0485d4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1186,6 +1186,7 @@ dependencies = [ "http-body", "http-body-util", "log", + "roto-runtime", "roto-tonic", "tokio-stream", "tonic", diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index c3b457b..d9541d5 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -5,6 +5,7 @@ edition = "2024" [dependencies] +roto-runtime = { path = "../runtime" } roto-tonic = { path = "../roto-tonic" } clap = { version = "4", features = ["derive"] } log = "0.4" diff --git a/codegen/src/runtime/mod.rs b/codegen/src/runtime/mod.rs index 5123f12..ea480fa 100644 --- a/codegen/src/runtime/mod.rs +++ b/codegen/src/runtime/mod.rs @@ -646,7 +646,7 @@ mod tests { #[test] fn test_protoc_binary_compatibility() { - let data = include_bytes!("../data/test_data.pb"); + let data = include_bytes!("../../data/test_data.pb"); let acc = ProtoAccessor::new(data).unwrap(); // 1. Varints (Integers, Booleans, Enums) diff --git a/codegen/tests/test_helloworld_build.rs b/codegen/tests/test_helloworld_build.rs index 28de3de..e79108e 100644 --- a/codegen/tests/test_helloworld_build.rs +++ b/codegen/tests/test_helloworld_build.rs @@ -34,7 +34,11 @@ fn test_helloworld_generated_code_builds() { // Create new library project let status = Command::new("cargo") - .args(["new", "--lib", temp_project_dir.to_str().expect("Invalid path")]) + .args([ + "new", + "--lib", + temp_project_dir.to_str().expect("Invalid path"), + ]) .status() .expect("Failed to run cargo new"); assert!(status.success(), "cargo new failed"); @@ -44,7 +48,7 @@ fn test_helloworld_generated_code_builds() { let cargo_toml_content = fs::read_to_string(&cargo_toml_path).expect("Failed to read Cargo.toml"); let updated_cargo_toml = format!( - "{}\n\nroto-codegen = {{ path = \"{}\" }}\nroto-runtime = {{ path = \"{}\" }}\nroto-tonic = {{ path = \"{}\" }}\nbytes = \"1.7\"\ntonic = \"0.12\"\ntokio-stream = \"0.1\"\ntower = \"0.4\"\nfutures-util = \"0.3\"\nhttp-body-util = \"0.1\"\nhttp-body = \"1.0\"\n\nhttp = \"1.0\"\n\n[workspace]\n", + "{}\n\nroto-codegen = {{ path = \"{}\" }}\nroto-runtime = {{ path = \"{}\" }}\nroto-tonic = {{ path = \"{}\" }}\nbytes = \"1.7\"\ntonic = \"0.12\"\ntokio-stream = \"0.1\"\ntower = \"0.4\"\nfutures-util = \"0.3\"\nhttp-body-util = \"0.1\"\nhttp-body = \"1.0\"\nasync-trait = \"0.1\"\n\nhttp = \"1.0\"\n\n[workspace]\n", cargo_toml_content, codegen_root.to_string_lossy(), project_root.join("runtime").to_string_lossy(), @@ -55,7 +59,10 @@ fn test_helloworld_generated_code_builds() { // 4. Write the generated code to src/lib.rs let mut all_code = String::new(); for (_, content) in generated_files { - let replaced = content.replace("use crate::{BufferPool, StatusBody};", "use roto_tonic::{BufferPool, StatusBody};"); + let replaced = content.replace( + "use crate::{BufferPool, StatusBody};", + "use roto_tonic::{BufferPool, StatusBody};", + ); all_code.push_str(&replaced); all_code.push_str("\n"); } diff --git a/roto-tonic/src/generated/interop.rs b/roto-tonic/src/generated/interop.rs index a70a155..49e10c1 100644 --- a/roto-tonic/src/generated/interop.rs +++ b/roto-tonic/src/generated/interop.rs @@ -2,7 +2,6 @@ #[allow(unused_imports)] use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage}; use core::str; -#[cfg(feature = "alloc")] use bytes::{Bytes, BytesMut, Buf, BufMut}; pub struct UnaryRequest<'a> { @@ -81,12 +80,10 @@ impl<'b> UnaryRequestBuilder<'b> { } } -#[cfg(feature = "alloc")] pub struct OwnedUnaryRequest { pub data: bytes::Bytes, } -#[cfg(feature = "alloc")] impl roto_runtime::RotoOwned for OwnedUnaryRequest { type Reader<'a> = UnaryRequest<'a>; fn reader(&self) -> UnaryRequest<'_> { @@ -94,7 +91,6 @@ impl roto_runtime::RotoOwned for OwnedUnaryRequest { } } -#[cfg(feature = "alloc")] impl roto_runtime::RotoMessage for OwnedUnaryRequest { fn decode(buf: bytes::Bytes) -> roto_runtime::Result { Ok(OwnedUnaryRequest { data: buf }) @@ -181,12 +177,10 @@ impl<'b> UnaryResponseBuilder<'b> { } } -#[cfg(feature = "alloc")] pub struct OwnedUnaryResponse { pub data: bytes::Bytes, } -#[cfg(feature = "alloc")] impl roto_runtime::RotoOwned for OwnedUnaryResponse { type Reader<'a> = UnaryResponse<'a>; fn reader(&self) -> UnaryResponse<'_> { @@ -194,7 +188,6 @@ impl roto_runtime::RotoOwned for OwnedUnaryResponse { } } -#[cfg(feature = "alloc")] impl roto_runtime::RotoMessage for OwnedUnaryResponse { fn decode(buf: bytes::Bytes) -> roto_runtime::Result { Ok(OwnedUnaryResponse { data: buf }) @@ -281,12 +274,10 @@ impl<'b> StreamingRequestBuilder<'b> { } } -#[cfg(feature = "alloc")] pub struct OwnedStreamingRequest { pub data: bytes::Bytes, } -#[cfg(feature = "alloc")] impl roto_runtime::RotoOwned for OwnedStreamingRequest { type Reader<'a> = StreamingRequest<'a>; fn reader(&self) -> StreamingRequest<'_> { @@ -294,7 +285,6 @@ impl roto_runtime::RotoOwned for OwnedStreamingRequest { } } -#[cfg(feature = "alloc")] impl roto_runtime::RotoMessage for OwnedStreamingRequest { fn decode(buf: bytes::Bytes) -> roto_runtime::Result { Ok(OwnedStreamingRequest { data: buf }) @@ -381,12 +371,10 @@ impl<'b> StreamingResponseBuilder<'b> { } } -#[cfg(feature = "alloc")] pub struct OwnedStreamingResponse { pub data: bytes::Bytes, } -#[cfg(feature = "alloc")] impl roto_runtime::RotoOwned for OwnedStreamingResponse { type Reader<'a> = StreamingResponse<'a>; fn reader(&self) -> StreamingResponse<'_> { @@ -394,7 +382,6 @@ impl roto_runtime::RotoOwned for OwnedStreamingResponse { } } -#[cfg(feature = "alloc")] impl roto_runtime::RotoMessage for OwnedStreamingResponse { fn decode(buf: bytes::Bytes) -> roto_runtime::Result { Ok(OwnedStreamingResponse { data: buf }) @@ -407,58 +394,41 @@ impl roto_runtime::RotoMessage for OwnedStreamingResponse { -#[cfg(feature = "alloc")] use tonic::{Request, Response, Status}; -#[cfg(feature = "alloc")] use tokio_stream::Stream; -#[cfg(feature = "alloc")] use std::pin::Pin; -#[cfg(feature = "alloc")] use std::sync::Arc; -#[cfg(feature = "alloc")] use std::task::{Context, Poll}; -#[cfg(feature = "alloc")] use std::future::Future; -#[cfg(feature = "alloc")] use tonic::body::BoxBody; -#[cfg(feature = "alloc")] use tower::Service; -#[cfg(feature = "alloc")] use futures_util::StreamExt; -#[cfg(feature = "alloc")] use http_body_util::BodyExt; -#[cfg(feature = "alloc")] use http_body::Body; -#[cfg(feature = "alloc")] use crate::{BufferPool, StatusBody}; -#[cfg(feature = "alloc")] #[async_trait::async_trait] pub trait InteropService: Send + Sync + 'static { async fn unary_call(&self, request: Request) -> std::result::Result, Status>; async fn streaming_call(&self, request: Request) -> std::result::Result> + Send>>>, Status>; } -#[cfg(feature = "alloc")] #[derive(Clone)] pub struct InteropServiceServer { inner: Arc, pool: Arc, } -#[cfg(feature = "alloc")] impl InteropServiceServer { pub fn new(inner: Arc, pool: Arc) -> Self { Self { inner, pool } } } -#[cfg(feature = "alloc")] impl tonic::server::NamedService for InteropServiceServer { const NAME: &'static str = "interop.InteropService"; } -#[cfg(feature = "alloc")] impl Service> for InteropServiceServer { type Response = http::Response; type Error = std::convert::Infallible; diff --git a/test_output.log b/test_output.log deleted file mode 100644 index 1d424ed..0000000 --- a/test_output.log +++ /dev/null @@ -1,229 +0,0 @@ -warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2024 which implies `resolver = "3"` - | - = note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest - = note: to use the edition 2024 resolver, specify `workspace.resolver = "3"` in the workspace root's manifest - = note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:5:7 - | -5 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - = note: `#[warn(unexpected_cfgs)]` on by default - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:184:7 - | -184 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:189:7 - | -189 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:197:7 - | -197 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:384:7 - | -384 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:389:7 - | -389 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:397:7 - | -397 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:684:7 - | -684 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:689:7 - | -689 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:697:7 - | -697 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:909:7 - | -909 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:914:7 - | -914 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:922:7 - | -922 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:1209:7 - | -1209 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:1214:7 - | -1214 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:1222:7 - | -1222 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:1359:7 - | -1359 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:1364:7 - | -1364 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - -warning: unexpected `cfg` condition value: `alloc` - --> benches/src/hackers.rs:1372:7 - | -1372 | #[cfg(feature = "alloc")] - | ^^^^^^^^^^^^^^^^^ help: remove the condition - | - = note: no expected values for `feature` - = help: consider adding `alloc` as a feature in `Cargo.toml` - = note: see for more information about checking conditional configuration - - Compiling no_std_test v0.1.0 (/opt/workspace/examples/no_std_test) -warning: `roto-benches` (lib) generated 19 warnings - Compiling roto-tonic v0.1.0 (/opt/workspace/roto-tonic) -warning: `roto-benches` (lib test) generated 19 warnings (19 duplicates) - Compiling tonic v0.12.3 -error: failed to run custom build command for `roto-tonic v0.1.0 (/opt/workspace/roto-tonic)` - -Caused by: - process didn't exit successfully: `/opt/workspace/target/debug/build/roto-tonic-3195fff626ab2304/build-script-build` (exit status: 101) - --- stdout - cargo:rerun-if-changed=proto/interop.proto - cargo:rerun-if-changed=proto - - --- stderr - - thread 'main' (391) panicked at roto-tonic/build.rs:9:45: - Failed to compile protos with tonic-build: Custom { kind: NotFound, error: "Could not find `protoc`. If `protoc` is installed, try setting the `PROTOC` environment variable to the path of the `protoc` binary. To install it on Debian, run `apt-get install protobuf-compiler`. It is also available at https://github.com/protocolbuffers/protobuf/releases For more information: https://docs.rs/prost-build/#sourcing-protoc" } - note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -warning: build failed, waiting for other jobs to finish... -error[E0152]: found duplicate lang item `panic_impl` - --> examples/no_std_test/src/main.rs:7:1 - | -7 | / fn panic(_info: &PanicInfo) -> ! { -8 | | loop {} -9 | | } - | |_^ - | - = note: the lang item is first defined in crate `std` (which `test` depends on) - = note: first definition in `std` loaded from /root/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-30b8a9ba02153abd.so, /root/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-30b8a9ba02153abd.rlib, /root/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-30b8a9ba02153abd.rmeta - = note: second definition in the local crate (`no_std_test`) - -For more information about this error, try `rustc --explain E0152`. -error: could not compile `no_std_test` (bin "no_std_test" test) due to 1 previous error