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 <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2024-01-15 19:03:46 +02:00 committed by clbot
parent 4fb4fc263d
commit c01ec8ee38
2 changed files with 39 additions and 0 deletions

View file

@ -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())),
}
}
}

View file

@ -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")]