diff --git a/Cargo.lock b/Cargo.lock index 0485d4b..d9413b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -833,15 +833,6 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" -[[package]] -name = "no_std_test" -version = "0.1.0" -dependencies = [ - "bytes", - "prost", - "roto-runtime", -] - [[package]] name = "num-traits" version = "0.2.19" diff --git a/Cargo.toml b/Cargo.toml index 557325a..7421390 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,13 +6,15 @@ members = [ "benches", "roto-tonic", "examples/hello_world", - "examples/no_std_test", ] exclude = [ - "test_gen_project" + "test_gen_project", + "examples/no_std_test", ] +resolver = "3" + [profile.dev] panic = "abort" diff --git a/benches/Cargo.toml b/benches/Cargo.toml index a8bbb74..c7c1770 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -3,6 +3,9 @@ name = "roto-benches" version = "0.1.0" edition = "2024" +[features] +alloc = [] + [dependencies] roto-runtime = { path = "../runtime" } clap = { version = "4", features = ["derive"] } diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index d9541d5..f122e26 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -3,6 +3,9 @@ name = "roto-codegen" version = "0.1.0" edition = "2024" +[features] +alloc = [] + [dependencies] roto-runtime = { path = "../runtime" } diff --git a/codegen/src/generator/mod.rs b/codegen/src/generator/mod.rs index a0b5ac9..4c072c9 100644 --- a/codegen/src/generator/mod.rs +++ b/codegen/src/generator/mod.rs @@ -7,19 +7,23 @@ use crate::runtime::ProtoAccessor; use std::collections::{HashMap, HashSet}; use std::str; -const DATA_IMPORTS: &str = "use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\nuse core::str;\nuse bytes::{Bytes, BytesMut, Buf, BufMut};\n"; -const SERVICE_IMPORTS: &str = "use tonic::{Request, Response, Status};\n\ - use tokio_stream::Stream;\n\ - use std::pin::Pin;\n\ - use std::sync::Arc;\n\ - use std::task::{Context, Poll};\n\ - use std::future::Future;\n\ - use tonic::body::BoxBody;\n\ - use tower::Service;\n\ - use futures_util::StreamExt;\n\ - use http_body_util::BodyExt;\n\ - use http_body::Body;\n\ - use crate::{BufferPool, StatusBody};\n"; +const DATA_IMPORTS: &str = "#[allow(unused)]\n\ +use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\n\ +use core::str;\n\ +use bytes::{Bytes, BytesMut, Buf, BufMut};\n"; +const SERVICE_IMPORTS: &str = "#[allow(unused)]\n\ +use tonic::{Request, Response, Status};\n\ +use tokio_stream::Stream;\n\ +use std::pin::Pin;\n\ +use std::sync::Arc;\n\ +use std::task::{Context, Poll};\n\ +use std::future::Future;\n\ +use tonic::body::BoxBody;\n\ +use tower::Service;\n\ +use futures_util::StreamExt;\n\ +use http_body_util::BodyExt;\n\ +use http_body::Body;\n\ +use crate::{BufferPool, StatusBody};\n"; pub fn to_pascal_case(s: &str) -> String { s.split('_') @@ -456,10 +460,7 @@ fn write_message(msg_proto: &DescriptorProto, output: &mut String) { output.push_str(&format!(" pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {{\n self.builder.finish()\n }}\n}}\n\n")); - output.push_str(&format!( - "pub struct Owned{} {{\n", - msg_name - )); + output.push_str(&format!("pub struct Owned{} {{\n", msg_name)); output.push_str(" pub data: bytes::Bytes,\n"); output.push_str("}\n\n"); @@ -828,7 +829,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut output.push_str(SERVICE_IMPORTS); output.push_str("\n"); let svc_name = to_pascal_case(svc_proto.name().unwrap()); - + output.push_str(&format!( "#[async_trait::async_trait]\npub trait {}: Send + Sync + 'static {{\n", svc_name @@ -875,7 +876,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut output.push_str("}\n\n"); let server_name = format!("{}Server", svc_name); - + output.push_str(&format!( "#[derive(Clone)]\npub struct {} {{\n", server_name @@ -884,7 +885,6 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut output.push_str(" pool: Arc,\n"); output.push_str("}\n\n"); - output.push_str(&format!("impl {} {{\n", server_name)); output.push_str(&format!( " pub fn new(inner: Arc, pool: Arc) -> Self {{\n", @@ -894,7 +894,6 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut output.push_str(" }\n"); output.push_str("}\n\n"); - output.push_str(&format!( "impl tonic::server::NamedService for {} {{\n", server_name @@ -910,7 +909,6 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut )); output.push_str("}\n\n"); - output.push_str(&format!( "impl Service> for {} {{\n", server_name @@ -946,7 +944,8 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut output.push_str(" return Ok(http::Response::builder().status(200).body(res_body).unwrap());\n"); output.push_str(" }\n\n"); output.push_str(" let payload = bytes_vec.slice(5..);\n"); - output.push_str(" let mut routed = false;\n\n"); + output.push_str(" #[allow(unused_assignments)]\n"); + output.push_str(" let mut routed = false;\n"); let mut methods = Vec::new(); for method_res in svc_proto.method() { @@ -1003,7 +1002,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut input_owned )); output.push_str(" Ok(msg) => msg,\n"); - output.push_str(" Err(e) => {\n"); + output.push_str(" Err(_e) => {\n"); output.push_str(" let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));\n"); output.push_str(" return Ok(http::Response::builder().status(200).body(res_body).unwrap());\n"); output.push_str(" }\n"); @@ -1013,7 +1012,7 @@ fn write_service(svc_proto: &ServiceDescriptorProto, package: &str, output: &mut method_name )); output.push_str(" Ok(res) => res,\n"); - output.push_str(" Err(e) => {\n"); + output.push_str(" Err(_e) => {\n"); output.push_str(" let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));\n"); output.push_str(" return Ok(http::Response::builder().status(200).body(res_body).unwrap());\n"); output.push_str(" }\n"); diff --git a/codegen/src/google/protobuf/compiler/plugin.rs b/codegen/src/google/protobuf/compiler/plugin.rs index a81a835..4ff4a27 100644 --- a/codegen/src/google/protobuf/compiler/plugin.rs +++ b/codegen/src/google/protobuf/compiler/plugin.rs @@ -1,5 +1,5 @@ // @generated by protoc-gen-roto — do not edit -#[allow(unused_imports)] +#[allow(unused)] use crate::runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; use std::str; diff --git a/codegen/src/google/protobuf/descriptor.rs b/codegen/src/google/protobuf/descriptor.rs index 210f0be..f659858 100644 --- a/codegen/src/google/protobuf/descriptor.rs +++ b/codegen/src/google/protobuf/descriptor.rs @@ -1,5 +1,5 @@ // @generated by protoc-gen-roto — do not edit -#[allow(unused_imports)] +#[allow(unused)] use crate::runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; use std::str; diff --git a/codegen/tests/test_oneofs.rs b/codegen/tests/test_oneofs.rs index 938ff9c..f393224 100644 --- a/codegen/tests/test_oneofs.rs +++ b/codegen/tests/test_oneofs.rs @@ -1,13 +1,5 @@ -use roto_codegen::generator::generate_rust_code; -use roto_codegen::google::protobuf::descriptor::{ - DescriptorProto, FieldDescriptorProto, FileDescriptorSet, -}; -use std::collections::HashMap; - #[test] fn test_oneof_generation() { - let mut set = FileDescriptorSet::new(b"").unwrap(); // Simplified for testing - // In a real scenario, we'd build up a FileDescriptorSet from a proto. // For this unit test, we'll manually construct a DescriptorProto that has a oneof. diff --git a/examples/hello_world/build.rs b/examples/hello_world/build.rs index 8b39c10..b68361a 100644 --- a/examples/hello_world/build.rs +++ b/examples/hello_world/build.rs @@ -1,7 +1,6 @@ fn main() { let proto_file = "proto/hello.proto"; let out_dir = std::env::var("OUT_DIR").unwrap(); - let dest_path = std::path::Path::new(&out_dir).join("hello.rs"); // Find the protoc-gen-roto binary // Since we added roto-codegen to build-dependencies, it will be built. diff --git a/roto-tonic/src/generated/helloworld.rs b/roto-tonic/src/generated/helloworld.rs index 71a5031..94af62a 100644 --- a/roto-tonic/src/generated/helloworld.rs +++ b/roto-tonic/src/generated/helloworld.rs @@ -1,5 +1,5 @@ // @generated by protoc-gen-roto — do not edit -#[allow(unused_imports)] +#[allow(unused)] use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage}; use std::str; diff --git a/roto-tonic/src/generated/interop.rs b/roto-tonic/src/generated/interop.rs index 49e10c1..fe94017 100644 --- a/roto-tonic/src/generated/interop.rs +++ b/roto-tonic/src/generated/interop.rs @@ -1,5 +1,5 @@ // @generated by protoc-gen-roto — do not edit -#[allow(unused_imports)] +#![allow(unused)] use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage}; use core::str; use bytes::{Bytes, BytesMut, Buf, BufMut}; diff --git a/roto-tonic/src/lib.rs b/roto-tonic/src/lib.rs index 96840b3..dbe5de6 100644 --- a/roto-tonic/src/lib.rs +++ b/roto-tonic/src/lib.rs @@ -1,12 +1,11 @@ -use std::marker::PhantomData; -use tonic::codec::{Codec, Decoder, Encoder, DecodeBuf, EncodeBuf}; use bytes::{Buf, BufMut, Bytes, BytesMut}; -use roto_runtime::RotoMessage; -use std::sync::{Arc, Mutex}; -use std::pin::Pin; -use std::future::Future; -use std::task::{Context, Poll}; use http_body::Body; +use roto_runtime::RotoMessage; +use std::marker::PhantomData; +use std::pin::Pin; +use std::sync::Mutex; +use std::task::{Context, Poll}; +use tonic::codec::{Codec, DecodeBuf, Decoder, EncodeBuf, Encoder}; pub mod generated { pub mod helloworld; @@ -95,7 +94,11 @@ impl BufferPool { } pub fn get(&self) -> BytesMut { - self.pool.lock().unwrap().pop().unwrap_or_else(|| BytesMut::with_capacity(self.default_capacity)) + self.pool + .lock() + .unwrap() + .pop() + .unwrap_or_else(|| BytesMut::with_capacity(self.default_capacity)) } pub fn put(&self, mut buf: BytesMut) { @@ -128,7 +131,7 @@ impl Body for StatusBody { fn poll_frame( mut self: Pin<&mut Self>, - cx: &mut Context<'_>, + _cx: &mut Context<'_>, ) -> Poll, Self::Error>>> { if let Some(data) = self.data.take() { Poll::Ready(Some(Ok(http_body::Frame::data(data)))) diff --git a/roto-tonic/tests/interop_test.rs b/roto-tonic/tests/interop_test.rs index 78e67cb..5d20755 100644 --- a/roto-tonic/tests/interop_test.rs +++ b/roto-tonic/tests/interop_test.rs @@ -6,7 +6,6 @@ use roto_runtime::RotoOwned; use roto_tonic::{BufferPool, generated::interop::{InteropService, InteropServiceServer, OwnedUnaryRequest, OwnedUnaryResponse, OwnedStreamingRequest, OwnedStreamingResponse, UnaryResponseBuilder}}; use futures_util::Stream; use std::pin::Pin; -use bytes::BufMut; struct InteropHandler;