refactor(tvix/glue): remove use of lazy_static
This is now supported in the standard library via std::sync::LazyLock, but requires some manual shuffling around of code. Change-Id: Ibb3be8458b8a8912ea04c9360d64c5cf914254d4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12609 Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
5faf7c9d7b
commit
4beee4cba7
6 changed files with 61 additions and 47 deletions
1
tvix/Cargo.lock
generated
1
tvix/Cargo.lock
generated
|
@ -4721,7 +4721,6 @@ dependencies = [
|
|||
"data-encoding",
|
||||
"futures",
|
||||
"hex-literal",
|
||||
"lazy_static",
|
||||
"magic",
|
||||
"md-5",
|
||||
"mimalloc",
|
||||
|
|
|
@ -15847,10 +15847,6 @@ rec {
|
|||
name = "hex-literal";
|
||||
packageId = "hex-literal";
|
||||
}
|
||||
{
|
||||
name = "lazy_static";
|
||||
packageId = "lazy_static";
|
||||
}
|
||||
{
|
||||
name = "mimalloc";
|
||||
packageId = "mimalloc";
|
||||
|
|
|
@ -36,7 +36,6 @@ clap = { workspace = true }
|
|||
[dev-dependencies]
|
||||
criterion = { workspace = true, features = ["html_reports"] }
|
||||
hex-literal = { workspace = true }
|
||||
lazy_static = { workspace = true }
|
||||
mimalloc = { workspace = true }
|
||||
nix = { workspace = true, features = ["fs"] }
|
||||
pretty_assertions = { workspace = true }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use clap::Parser;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use lazy_static::lazy_static;
|
||||
use mimalloc::MiMalloc;
|
||||
use std::sync::LazyLock;
|
||||
use std::{env, rc::Rc, sync::Arc, time::Duration};
|
||||
use tvix_build::buildservice::DummyBuildService;
|
||||
use tvix_eval::{builtins::impure_builtins, EvalIO};
|
||||
|
@ -16,9 +16,8 @@ use tvix_store::utils::{construct_services, ServiceUrlsMemory};
|
|||
#[global_allocator]
|
||||
static GLOBAL: MiMalloc = MiMalloc;
|
||||
|
||||
lazy_static! {
|
||||
static ref TOKIO_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
}
|
||||
static TOKIO_RUNTIME: LazyLock<tokio::runtime::Runtime> =
|
||||
LazyLock::new(|| tokio::runtime::Runtime::new().unwrap());
|
||||
|
||||
fn interpret(code: &str) {
|
||||
// TODO: this is a bit annoying.
|
||||
|
|
|
@ -144,48 +144,69 @@ impl KnownPaths {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use hex_literal::hex;
|
||||
use nix_compat::{derivation::Derivation, nixbase32, nixhash, store_path::StorePath};
|
||||
use url::Url;
|
||||
|
||||
use super::KnownPaths;
|
||||
use crate::fetchers::Fetch;
|
||||
|
||||
use super::KnownPaths;
|
||||
use hex_literal::hex;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
static ref BAR_DRV: Derivation = Derivation::from_aterm_bytes(include_bytes!(
|
||||
static BAR_DRV: LazyLock<Derivation> = LazyLock::new(|| {
|
||||
Derivation::from_aterm_bytes(include_bytes!(
|
||||
"tests/ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv"
|
||||
))
|
||||
.expect("must parse");
|
||||
static ref FOO_DRV: Derivation = Derivation::from_aterm_bytes(include_bytes!(
|
||||
.expect("must parse")
|
||||
});
|
||||
|
||||
static FOO_DRV: LazyLock<Derivation> = LazyLock::new(|| {
|
||||
Derivation::from_aterm_bytes(include_bytes!(
|
||||
"tests/ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv"
|
||||
))
|
||||
.expect("must parse");
|
||||
static ref BAR_DRV_PATH: StorePath<String> =
|
||||
StorePath::from_bytes(b"ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv").expect("must parse");
|
||||
static ref FOO_DRV_PATH: StorePath<String> =
|
||||
StorePath::from_bytes(b"ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv").expect("must parse");
|
||||
static ref BAR_OUT_PATH: StorePath<String> =
|
||||
StorePath::from_bytes(b"mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar").expect("must parse");
|
||||
static ref FOO_OUT_PATH: StorePath<String> =
|
||||
StorePath::from_bytes(b"fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo").expect("must parse");
|
||||
.expect("must parse")
|
||||
});
|
||||
|
||||
static ref FETCH_URL : Fetch = Fetch::URL{
|
||||
url: Url::parse("https://raw.githubusercontent.com/aaptel/notmuch-extract-patch/f732a53e12a7c91a06755ebfab2007adc9b3063b/notmuch-extract-patch").unwrap(),
|
||||
exp_hash: Some(nixhash::from_sri_str("sha256-Xa1Jbl2Eq5+L0ww+Ph1osA3Z/Dxe/RkN1/dITQCdXFk=").unwrap())
|
||||
};
|
||||
static ref FETCH_URL_OUT_PATH: StorePath<String> = StorePath::from_bytes(b"06qi00hylriyfm0nl827crgjvbax84mz-notmuch-extract-patch").unwrap();
|
||||
static BAR_DRV_PATH: LazyLock<StorePath<String>> = LazyLock::new(|| {
|
||||
StorePath::from_bytes(b"ss2p4wmxijn652haqyd7dckxwl4c7hxx-bar.drv").expect("must parse")
|
||||
});
|
||||
|
||||
static ref FETCH_TARBALL : Fetch = Fetch::Tarball{
|
||||
url: Url::parse("https://github.com/NixOS/nixpkgs/archive/91050ea1e57e50388fa87a3302ba12d188ef723a.tar.gz").unwrap(),
|
||||
exp_nar_sha256: Some(nixbase32::decode_fixed("1hf6cgaci1n186kkkjq106ryf8mmlq9vnwgfwh625wa8hfgdn4dm").unwrap())
|
||||
};
|
||||
static ref FETCH_TARBALL_OUT_PATH: StorePath<String> = StorePath::from_bytes(b"7adgvk5zdfq4pwrhsm3n9lzypb12gw0g-source").unwrap();
|
||||
static FOO_DRV_PATH: LazyLock<StorePath<String>> = LazyLock::new(|| {
|
||||
StorePath::from_bytes(b"ch49594n9avinrf8ip0aslidkc4lxkqv-foo.drv").expect("must parse")
|
||||
});
|
||||
|
||||
static BAR_OUT_PATH: LazyLock<StorePath<String>> = LazyLock::new(|| {
|
||||
StorePath::from_bytes(b"mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar").expect("must parse")
|
||||
});
|
||||
|
||||
static FOO_OUT_PATH: LazyLock<StorePath<String>> = LazyLock::new(|| {
|
||||
StorePath::from_bytes(b"fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo").expect("must parse")
|
||||
});
|
||||
|
||||
static FETCH_URL: LazyLock<Fetch> = LazyLock::new(|| {
|
||||
Fetch::URL {
|
||||
url: Url::parse("https://raw.githubusercontent.com/aaptel/notmuch-extract-patch/f732a53e12a7c91a06755ebfab2007adc9b3063b/notmuch-extract-patch").unwrap(),
|
||||
exp_hash: Some(nixhash::from_sri_str("sha256-Xa1Jbl2Eq5+L0ww+Ph1osA3Z/Dxe/RkN1/dITQCdXFk=").unwrap())
|
||||
}
|
||||
});
|
||||
|
||||
/// ensure we don't allow acdding a Derivation that depends on another,
|
||||
/// not-yet-added Derivation.
|
||||
static FETCH_URL_OUT_PATH: LazyLock<StorePath<String>> = LazyLock::new(|| {
|
||||
StorePath::from_bytes(b"06qi00hylriyfm0nl827crgjvbax84mz-notmuch-extract-patch").unwrap()
|
||||
});
|
||||
|
||||
static FETCH_TARBALL: LazyLock<Fetch> = LazyLock::new(|| {
|
||||
Fetch::Tarball {
|
||||
url: Url::parse("https://github.com/NixOS/nixpkgs/archive/91050ea1e57e50388fa87a3302ba12d188ef723a.tar.gz").unwrap(),
|
||||
exp_nar_sha256: Some(nixbase32::decode_fixed("1hf6cgaci1n186kkkjq106ryf8mmlq9vnwgfwh625wa8hfgdn4dm").unwrap())
|
||||
}
|
||||
});
|
||||
|
||||
static FETCH_TARBALL_OUT_PATH: LazyLock<StorePath<String>> = LazyLock::new(|| {
|
||||
StorePath::from_bytes(b"7adgvk5zdfq4pwrhsm3n9lzypb12gw0g-source").unwrap()
|
||||
});
|
||||
|
||||
/// Ensure that we don't allow adding a derivation that depends on another,
|
||||
/// not-yet-added derivation.
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn drv_reject_if_missing_input_drv() {
|
||||
|
|
|
@ -213,6 +213,7 @@ mod test {
|
|||
use bytes::Bytes;
|
||||
use nix_compat::derivation::Derivation;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::LazyLock;
|
||||
use tvix_build::proto::{
|
||||
build_request::{AdditionalFile, BuildConstraints, EnvVar},
|
||||
BuildRequest,
|
||||
|
@ -223,15 +224,14 @@ mod test {
|
|||
use crate::tvix_build::NIX_ENVIRONMENT_VARS;
|
||||
|
||||
use super::derivation_to_build_request;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
static ref INPUT_NODE_FOO_NAME: Bytes = "mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar".into();
|
||||
static ref INPUT_NODE_FOO: Node = Node::Directory {
|
||||
digest: DUMMY_DIGEST.clone(),
|
||||
size: 42
|
||||
};
|
||||
}
|
||||
static INPUT_NODE_FOO_NAME: LazyLock<Bytes> =
|
||||
LazyLock::new(|| "mp57d33657rf34lzvlbpfa1gjfv5gmpg-bar".into());
|
||||
|
||||
static INPUT_NODE_FOO: LazyLock<Node> = LazyLock::new(|| Node::Directory {
|
||||
digest: DUMMY_DIGEST.clone(),
|
||||
size: 42,
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn test_derivation_to_build_request() {
|
||||
|
|
Loading…
Add table
Reference in a new issue