diff options
author | Florian Klink <flokli@flokli.de> | 2024-01-15T17·03+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-01-15T18·41+0000 |
commit | c01ec8ee383553344c75cef26f986ac1ae8687e9 (patch) | |
tree | d1f391501084ede592f7c2a3b766dc4b261036e9 | |
parent | 4fb4fc263d31e207f0fc842f17e98ca276094e00 (diff) |
feat(tvix/build): add GRPCBuildServiceWrapper r/7384
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 <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/build/src/proto/grpc_buildservice_wrapper.rs | 35 | ||||
-rw-r--r-- | tvix/build/src/proto/mod.rs | 4 |
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")] |