From 12ae96cff2e925f502cee8afb4f8dcf54aba27d8 Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Tue, 16 Jan 2024 05:31:20 +0100 Subject: feat(tvix/glue): use TvixStoreIO as derivation builtin state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We propagate a `TvixStoreIO` as the `state` of our derivation-specific builtins in the glue crate. The evaluators `io_handle` itself is using a Rc. An earlier version of TvixStoreIO was also introducing generics over the different internal services themselves, but we opted for instead hardcoding this to Arc for the sake of less macro voodoo. Change-Id: I535c476f06b840858fa3070c4a237ece47f7a15b Reviewed-on: https://cl.tvl.fyi/c/depot/+/10636 Reviewed-by: raitobezarius Autosubmit: raitobezarius Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/glue/src/tvix_io.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'tvix/glue/src/tvix_io.rs') diff --git a/tvix/glue/src/tvix_io.rs b/tvix/glue/src/tvix_io.rs index 77dcb9291032..19e5dd0b41df 100644 --- a/tvix/glue/src/tvix_io.rs +++ b/tvix/glue/src/tvix_io.rs @@ -13,24 +13,27 @@ use std::path::{Path, PathBuf}; use tvix_eval::{EvalIO, FileType}; // TODO: Merge this together with TvixStoreIO? -pub struct TvixIO { +pub struct TvixIO { // Actual underlying [EvalIO] implementation. actual: T, } -impl TvixIO { +impl TvixIO { pub fn new(actual: T) -> Self { Self { actual } } } -impl EvalIO for TvixIO { +impl EvalIO for TvixIO +where + T: AsRef, +{ fn store_dir(&self) -> Option { - self.actual.store_dir() + self.actual.as_ref().store_dir() } fn import_path(&self, path: &Path) -> io::Result { - let imported_path = self.actual.import_path(path)?; + let imported_path = self.actual.as_ref().import_path(path)?; Ok(imported_path) } @@ -39,7 +42,7 @@ impl EvalIO for TvixIO { return Ok(true); } - self.actual.path_exists(path) + self.actual.as_ref().path_exists(path) } fn read_to_string(&self, path: &Path) -> io::Result { @@ -56,10 +59,10 @@ impl EvalIO for TvixIO { return Ok(include_str!("fetchurl.nix").to_string()); } - self.actual.read_to_string(path) + self.actual.as_ref().read_to_string(path) } fn read_dir(&self, path: &Path) -> io::Result> { - self.actual.read_dir(path) + self.actual.as_ref().read_dir(path) } } -- cgit 1.4.1