From 403200d6bcd841a58e0e2863f115a08f1586e2d6 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 30 Sep 2024 23:51:33 +0200 Subject: [PATCH] feat: slim down reduce tonic features, add feature flags to compile only server, client, both or neither --- Cargo.toml | 11 ++++++++--- build.rs | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3209f36..14c241c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ authors = [ "cschen " ] license = "GPL-3.0-only" -version = "0.7.0" +version = "0.7.1" edition = "2021" [lib] @@ -18,8 +18,13 @@ name = "codemp_proto" [dependencies] prost = "0.13" -tonic = "0.12" -uuid = "1.7" +uuid = "1.10" +tonic = { version = "0.12", default-features = false, features = ["codegen", "prost"] } [build-dependencies] tonic-build = "0.12" + +[features] +default = ["client"] +client = [] +server = [] diff --git a/build.rs b/build.rs index 46b91c0..0acca80 100644 --- a/build.rs +++ b/build.rs @@ -1,14 +1,34 @@ fn main() -> Result<(), Box> { - Ok(tonic_build::configure().compile( - &[ - "proto/common.proto", - "proto/cursor.proto", - "proto/files.proto", - "proto/auth.proto", - "proto/session.proto", - "proto/workspace.proto", - "proto/buffer.proto", - ], - &["proto"], - )?) + let server = { + #[cfg(feature = "server")] { true } + #[cfg(not(feature = "server"))] { false } + }; + + let client = { + #[cfg(feature = "client")] { true } + #[cfg(not(feature = "client"))] { false } + }; + + let transport = { + #[cfg(any(feature = "server", feature = "client"))] { true } + #[cfg(not(any(feature = "server", feature = "client")))] { false } + }; + + Ok + (tonic_build::configure() + .build_server(server) + .build_client(client) + .build_transport(transport) + .compile_protos( + &[ + "proto/common.proto", + "proto/cursor.proto", + "proto/files.proto", + "proto/auth.proto", + "proto/session.proto", + "proto/workspace.proto", + "proto/buffer.proto", + ], + &["proto"], + )?) }