about summary refs log tree commit diff
path: root/tvix/build/src/proto
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/build/src/proto')
-rw-r--r--tvix/build/src/proto/grpc_buildservice_wrapper.rs35
-rw-r--r--tvix/build/src/proto/mod.rs4
2 files changed, 39 insertions, 0 deletions
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<BUILD> {
+    inner: BUILD,
+}
+
+impl<BUILD> GRPCBuildServiceWrapper<BUILD> {
+    pub fn new(build_service: BUILD) -> Self {
+        Self {
+            inner: build_service,
+        }
+    }
+}
+
+#[async_trait]
+impl<BUILD> crate::proto::build_service_server::BuildService for GRPCBuildServiceWrapper<BUILD>
+where
+    BUILD: Deref<Target = dyn BuildService> + Send + Sync + 'static,
+{
+    async fn do_build(
+        &self,
+        request: tonic::Request<BuildRequest>,
+    ) -> Result<tonic::Response<Build>, 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")]