refactor(tvix/glue): add BuildService to TvixStoreIO
TvixStoreIO triggers builds whenever IO into a not-yet-built store path is requested, if it knows how to build that path. Change-Id: If30e9db6be2f2a30cbc9d0576f357f3ecfa0d35a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10645 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
This commit is contained in:
parent
12ae96cff2
commit
501827db59
8 changed files with 25 additions and 6 deletions
1
tvix/Cargo.lock
generated
1
tvix/Cargo.lock
generated
|
@ -3308,6 +3308,7 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tvix-build",
|
||||||
"tvix-castore",
|
"tvix-castore",
|
||||||
"tvix-eval",
|
"tvix-eval",
|
||||||
"tvix-glue",
|
"tvix-glue",
|
||||||
|
|
|
@ -10356,6 +10356,10 @@ rec {
|
||||||
name = "tracing";
|
name = "tracing";
|
||||||
packageId = "tracing";
|
packageId = "tracing";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
name = "tvix-build";
|
||||||
|
packageId = "tvix-build";
|
||||||
|
}
|
||||||
{
|
{
|
||||||
name = "tvix-castore";
|
name = "tvix-castore";
|
||||||
packageId = "tvix-castore";
|
packageId = "tvix-castore";
|
||||||
|
|
|
@ -9,6 +9,7 @@ path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nix-compat = { path = "../nix-compat" }
|
nix-compat = { path = "../nix-compat" }
|
||||||
|
tvix-build = { path = "../build" }
|
||||||
tvix-castore = { path = "../castore" }
|
tvix-castore = { path = "../castore" }
|
||||||
tvix-store = { path = "../store", default-features = false, features = []}
|
tvix-store = { path = "../store", default-features = false, features = []}
|
||||||
tvix-eval = { path = "../eval" }
|
tvix-eval = { path = "../eval" }
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rustyline::{error::ReadlineError, Editor};
|
use rustyline::{error::ReadlineError, Editor};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
use std::{fs, path::PathBuf};
|
use std::{fs, path::PathBuf};
|
||||||
|
use tvix_build::buildservice::DummyBuildService;
|
||||||
use tvix_eval::builtins::impure_builtins;
|
use tvix_eval::builtins::impure_builtins;
|
||||||
use tvix_eval::observer::{DisassemblingObserver, TracingObserver};
|
use tvix_eval::observer::{DisassemblingObserver, TracingObserver};
|
||||||
use tvix_eval::{EvalIO, Value};
|
use tvix_eval::{EvalIO, Value};
|
||||||
|
@ -88,6 +90,7 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b
|
||||||
blob_service.clone(),
|
blob_service.clone(),
|
||||||
directory_service.clone(),
|
directory_service.clone(),
|
||||||
path_info_service.into(),
|
path_info_service.into(),
|
||||||
|
Arc::<DummyBuildService>::default(),
|
||||||
tokio_runtime.handle().clone(),
|
tokio_runtime.handle().clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::{env, rc::Rc, sync::Arc, time::Duration};
|
use std::{env, rc::Rc, sync::Arc, time::Duration};
|
||||||
|
use tvix_build::buildservice::DummyBuildService;
|
||||||
use tvix_castore::{
|
use tvix_castore::{
|
||||||
blobservice::{BlobService, MemoryBlobService},
|
blobservice::{BlobService, MemoryBlobService},
|
||||||
directoryservice::{DirectoryService, MemoryDirectoryService},
|
directoryservice::{DirectoryService, MemoryDirectoryService},
|
||||||
|
@ -33,6 +34,7 @@ fn interpret(code: &str) {
|
||||||
BLOB_SERVICE.clone(),
|
BLOB_SERVICE.clone(),
|
||||||
DIRECTORY_SERVICE.clone(),
|
DIRECTORY_SERVICE.clone(),
|
||||||
PATH_INFO_SERVICE.clone(),
|
PATH_INFO_SERVICE.clone(),
|
||||||
|
Arc::<DummyBuildService>::default(),
|
||||||
TOKIO_RUNTIME.handle().clone(),
|
TOKIO_RUNTIME.handle().clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ mod derivation;
|
||||||
mod derivation_error;
|
mod derivation_error;
|
||||||
|
|
||||||
pub use derivation_error::Error as DerivationError;
|
pub use derivation_error::Error as DerivationError;
|
||||||
use tvix_eval::EvalIO;
|
|
||||||
|
|
||||||
/// Adds derivation-related builtins to the passed [tvix_eval::Evaluation].
|
/// Adds derivation-related builtins to the passed [tvix_eval::Evaluation].
|
||||||
///
|
///
|
||||||
|
@ -16,10 +15,7 @@ use tvix_eval::EvalIO;
|
||||||
///
|
///
|
||||||
/// As they need to interact with `known_paths`, we also need to pass in
|
/// As they need to interact with `known_paths`, we also need to pass in
|
||||||
/// `known_paths`.
|
/// `known_paths`.
|
||||||
pub fn add_derivation_builtins<IO>(eval: &mut tvix_eval::Evaluation<IO>, io: Rc<TvixStoreIO>)
|
pub fn add_derivation_builtins<IO>(eval: &mut tvix_eval::Evaluation<IO>, io: Rc<TvixStoreIO>) {
|
||||||
where
|
|
||||||
IO: AsRef<dyn EvalIO>,
|
|
||||||
{
|
|
||||||
eval.builtins
|
eval.builtins
|
||||||
.extend(derivation::derivation_builtins::builtins(io));
|
.extend(derivation::derivation_builtins::builtins(io));
|
||||||
|
|
||||||
|
@ -30,13 +26,14 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::rc::Rc;
|
use std::{rc::Rc, sync::Arc};
|
||||||
|
|
||||||
use crate::tvix_store_io::TvixStoreIO;
|
use crate::tvix_store_io::TvixStoreIO;
|
||||||
|
|
||||||
use super::add_derivation_builtins;
|
use super::add_derivation_builtins;
|
||||||
use nix_compat::store_path::hash_placeholder;
|
use nix_compat::store_path::hash_placeholder;
|
||||||
use test_case::test_case;
|
use test_case::test_case;
|
||||||
|
use tvix_build::buildservice::DummyBuildService;
|
||||||
use tvix_eval::{EvalIO, EvaluationResult};
|
use tvix_eval::{EvalIO, EvaluationResult};
|
||||||
use tvix_store::utils::construct_services;
|
use tvix_store::utils::construct_services;
|
||||||
|
|
||||||
|
@ -54,6 +51,7 @@ mod tests {
|
||||||
blob_service,
|
blob_service,
|
||||||
directory_service,
|
directory_service,
|
||||||
path_info_service.into(),
|
path_info_service.into(),
|
||||||
|
Arc::<DummyBuildService>::default(),
|
||||||
runtime.handle().clone(),
|
runtime.handle().clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::{rc::Rc, sync::Arc};
|
||||||
|
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use tvix_build::buildservice::DummyBuildService;
|
||||||
use tvix_castore::{
|
use tvix_castore::{
|
||||||
blobservice::{BlobService, MemoryBlobService},
|
blobservice::{BlobService, MemoryBlobService},
|
||||||
directoryservice::{DirectoryService, MemoryDirectoryService},
|
directoryservice::{DirectoryService, MemoryDirectoryService},
|
||||||
|
@ -43,6 +44,7 @@ fn eval_test(code_path: PathBuf, expect_success: bool) {
|
||||||
blob_service,
|
blob_service,
|
||||||
directory_service,
|
directory_service,
|
||||||
path_info_service.into(),
|
path_info_service.into(),
|
||||||
|
Arc::new(DummyBuildService::default()),
|
||||||
tokio_runtime.handle().clone(),
|
tokio_runtime.handle().clone(),
|
||||||
));
|
));
|
||||||
let mut eval = tvix_eval::Evaluation::new(tvix_store_io.clone() as Rc<dyn EvalIO>, true);
|
let mut eval = tvix_eval::Evaluation::new(tvix_store_io.clone() as Rc<dyn EvalIO>, true);
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::{
|
||||||
};
|
};
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use tracing::{error, instrument, warn};
|
use tracing::{error, instrument, warn};
|
||||||
|
use tvix_build::buildservice::BuildService;
|
||||||
use tvix_eval::{EvalIO, FileType, StdIO};
|
use tvix_eval::{EvalIO, FileType, StdIO};
|
||||||
|
|
||||||
use tvix_castore::{
|
use tvix_castore::{
|
||||||
|
@ -41,6 +42,8 @@ pub struct TvixStoreIO {
|
||||||
directory_service: Arc<dyn DirectoryService>,
|
directory_service: Arc<dyn DirectoryService>,
|
||||||
path_info_service: Arc<dyn PathInfoService>,
|
path_info_service: Arc<dyn PathInfoService>,
|
||||||
std_io: StdIO,
|
std_io: StdIO,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
build_service: Arc<dyn BuildService>,
|
||||||
tokio_handle: tokio::runtime::Handle,
|
tokio_handle: tokio::runtime::Handle,
|
||||||
pub(crate) known_paths: RefCell<KnownPaths>,
|
pub(crate) known_paths: RefCell<KnownPaths>,
|
||||||
}
|
}
|
||||||
|
@ -50,6 +53,7 @@ impl TvixStoreIO {
|
||||||
blob_service: Arc<dyn BlobService>,
|
blob_service: Arc<dyn BlobService>,
|
||||||
directory_service: Arc<dyn DirectoryService>,
|
directory_service: Arc<dyn DirectoryService>,
|
||||||
path_info_service: Arc<dyn PathInfoService>,
|
path_info_service: Arc<dyn PathInfoService>,
|
||||||
|
build_service: Arc<dyn BuildService>,
|
||||||
tokio_handle: tokio::runtime::Handle,
|
tokio_handle: tokio::runtime::Handle,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -57,6 +61,7 @@ impl TvixStoreIO {
|
||||||
directory_service,
|
directory_service,
|
||||||
path_info_service,
|
path_info_service,
|
||||||
std_io: StdIO {},
|
std_io: StdIO {},
|
||||||
|
build_service,
|
||||||
tokio_handle,
|
tokio_handle,
|
||||||
known_paths: Default::default(),
|
known_paths: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -292,6 +297,7 @@ mod tests {
|
||||||
use std::{path::Path, rc::Rc, sync::Arc};
|
use std::{path::Path, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
use tvix_build::buildservice::DummyBuildService;
|
||||||
use tvix_castore::{
|
use tvix_castore::{
|
||||||
blobservice::{BlobService, MemoryBlobService},
|
blobservice::{BlobService, MemoryBlobService},
|
||||||
directoryservice::{DirectoryService, MemoryDirectoryService},
|
directoryservice::{DirectoryService, MemoryDirectoryService},
|
||||||
|
@ -314,12 +320,14 @@ mod tests {
|
||||||
blob_service.clone(),
|
blob_service.clone(),
|
||||||
directory_service.clone(),
|
directory_service.clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
|
||||||
let io = Rc::new(TvixStoreIO::new(
|
let io = Rc::new(TvixStoreIO::new(
|
||||||
blob_service.clone(),
|
blob_service.clone(),
|
||||||
directory_service.clone(),
|
directory_service.clone(),
|
||||||
path_info_service,
|
path_info_service,
|
||||||
|
Arc::<DummyBuildService>::default(),
|
||||||
runtime.handle().clone(),
|
runtime.handle().clone(),
|
||||||
));
|
));
|
||||||
let mut eval = tvix_eval::Evaluation::new(io.clone() as Rc<dyn EvalIO>, true);
|
let mut eval = tvix_eval::Evaluation::new(io.clone() as Rc<dyn EvalIO>, true);
|
||||||
|
|
Loading…
Reference in a new issue