From c01ec8ee383553344c75cef26f986ac1ae8687e9 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 15 Jan 2024 19:03:46 +0200 Subject: feat(tvix/build): add GRPCBuildServiceWrapper This produces a gRPC BuildService server for anything implementing our BuildService trait. Change-Id: I59c690a432b5e1f59209fd67e2718cb8c935adf2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10628 Autosubmit: flokli Reviewed-by: raitobezarius Tested-by: BuildkiteCI --- tvix/build/src/proto/grpc_buildservice_wrapper.rs | 35 +++++++++++++++++++++++ tvix/build/src/proto/mod.rs | 4 +++ 2 files changed, 39 insertions(+) create mode 100644 tvix/build/src/proto/grpc_buildservice_wrapper.rs (limited to 'tvix') diff --git a/tvix/build/src/proto/grpc_buildservice_wrapper.rs b/tvix/build/src/proto/grpc_buildservice_wrapper.rs new file mode 100644 index 000000000000..4c176e3cf4fb --- /dev/null +++ b/tvix/build/src/proto/grpc_buildservice_wrapper.rs @@ -0,0 +1,35 @@ +use crate::buildservice::BuildService; +use std::ops::Deref; +use tonic::async_trait; + +use super::{Build, BuildRequest}; + +/// Implements the gRPC server trait ([self::build_service_server::BuildService] +/// for anything implementing [BuildService]. +pub struct GRPCBuildServiceWrapper { + inner: BUILD, +} + +impl GRPCBuildServiceWrapper { + pub fn new(build_service: BUILD) -> Self { + Self { + inner: build_service, + } + } +} + +#[async_trait] +impl crate::proto::build_service_server::BuildService for GRPCBuildServiceWrapper +where + BUILD: Deref + Send + Sync + 'static, +{ + async fn do_build( + &self, + request: tonic::Request, + ) -> Result, tonic::Status> { + match self.inner.do_build(request.into_inner()).await { + Ok(resp) => Ok(tonic::Response::new(resp)), + Err(e) => Err(tonic::Status::internal(e.to_string())), + } + } +} diff --git a/tvix/build/src/proto/mod.rs b/tvix/build/src/proto/mod.rs index a9e620ecdd7f..c7831795c30e 100644 --- a/tvix/build/src/proto/mod.rs +++ b/tvix/build/src/proto/mod.rs @@ -3,6 +3,10 @@ use std::path::{Path, PathBuf}; use itertools::Itertools; use tvix_castore::proto::{NamedNode, ValidateNodeError}; +mod grpc_buildservice_wrapper; + +pub use grpc_buildservice_wrapper::GRPCBuildServiceWrapper; + tonic::include_proto!("tvix.build.v1"); #[cfg(feature = "tonic-reflection")] -- cgit 1.4.1