Replace lazy_static with LazyLock

This commit is contained in:
Tristan Ross 2026-01-27 12:02:42 -08:00
parent 4a3163d18a
commit 4551c2b378
No known key found for this signature in database
GPG key ID: 58BB826E9F8688F4
6 changed files with 13 additions and 28 deletions

3
Cargo.lock generated
View file

@ -564,7 +564,6 @@ dependencies = [
"anyhow", "anyhow",
"cstr", "cstr",
"ctor", "ctor",
"lazy_static",
"nix-bindings-bdwgc-sys", "nix-bindings-bdwgc-sys",
"nix-bindings-expr-sys", "nix-bindings-expr-sys",
"nix-bindings-store", "nix-bindings-store",
@ -614,7 +613,6 @@ dependencies = [
"anyhow", "anyhow",
"cstr", "cstr",
"ctor", "ctor",
"lazy_static",
"nix-bindings-expr", "nix-bindings-expr",
"nix-bindings-fetchers", "nix-bindings-fetchers",
"nix-bindings-flake-sys", "nix-bindings-flake-sys",
@ -644,7 +642,6 @@ dependencies = [
"ctor", "ctor",
"harmonia-store-core", "harmonia-store-core",
"hex-literal", "hex-literal",
"lazy_static",
"nix-bindings-store-sys", "nix-bindings-store-sys",
"nix-bindings-util", "nix-bindings-util",
"nix-bindings-util-sys", "nix-bindings-util-sys",

View file

@ -19,7 +19,6 @@ nix-bindings-bdwgc-sys = { path = "../nix-bindings-bdwgc-sys", version = "0.2.1"
nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" } nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" } nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" }
nix-bindings-expr-sys = { path = "../nix-bindings-expr-sys", version = "0.2.1" } nix-bindings-expr-sys = { path = "../nix-bindings-expr-sys", version = "0.2.1" }
lazy_static = "1.4"
ctor = "0.2" ctor = "0.2"
tempfile = "3.10" tempfile = "3.10"
cstr = "0.2" cstr = "0.2"

View file

@ -133,7 +133,6 @@ use crate::value::{Int, Value, ValueType};
use anyhow::Context as _; use anyhow::Context as _;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use cstr::cstr; use cstr::cstr;
use lazy_static::lazy_static;
use nix_bindings_bdwgc_sys as gc; use nix_bindings_bdwgc_sys as gc;
use nix_bindings_expr_sys as raw; use nix_bindings_expr_sys as raw;
use nix_bindings_store::path::StorePath; use nix_bindings_store::path::StorePath;
@ -148,17 +147,13 @@ use std::ffi::{c_char, CString};
use std::iter::FromIterator; use std::iter::FromIterator;
use std::os::raw::c_uint; use std::os::raw::c_uint;
use std::ptr::{null, null_mut, NonNull}; use std::ptr::{null, null_mut, NonNull};
use std::sync::{Arc, Weak}; use std::sync::{Arc, LazyLock, Weak};
lazy_static! { static INIT: LazyLock<Result<()>> = LazyLock::new(|| unsafe {
static ref INIT: Result<()> = { gc::GC_allow_register_threads();
unsafe { check_call!(raw::libexpr_init(&mut Context::new()))?;
gc::GC_allow_register_threads(); Ok(())
check_call!(raw::libexpr_init(&mut Context::new()))?; });
Ok(())
}
};
}
pub fn init() -> Result<()> { pub fn init() -> Result<()> {
let x = INIT.as_ref(); let x = INIT.as_ref();

View file

@ -17,7 +17,6 @@ nix-bindings-fetchers = { path = "../nix-bindings-fetchers", version = "0.2.1" }
nix-bindings-store = { path = "../nix-bindings-store", version = "0.2.1" } nix-bindings-store = { path = "../nix-bindings-store", version = "0.2.1" }
nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" } nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" }
nix-bindings-flake-sys = { path = "../nix-bindings-flake-sys", version = "0.2.1" } nix-bindings-flake-sys = { path = "../nix-bindings-flake-sys", version = "0.2.1" }
lazy_static = "1.4"
ctor = "0.2" ctor = "0.2"
tempfile = "3.10" tempfile = "3.10"
cstr = "0.2" cstr = "0.2"

View file

@ -16,7 +16,6 @@ anyhow = "1.0"
nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" } nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" }
nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" } nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" } nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" }
lazy_static = "1.4"
zerocopy = "0.8" zerocopy = "0.8"
harmonia-store-core = { version = "0.0.0-alpha.0", optional = true } harmonia-store-core = { version = "0.0.0-alpha.0", optional = true }
serde_json = { version = "1.0", optional = true } serde_json = { version = "1.0", optional = true }

View file

@ -1,5 +1,4 @@
use anyhow::{bail, Error, Result}; use anyhow::{bail, Error, Result};
use lazy_static::lazy_static;
use nix_bindings_store_sys as raw; use nix_bindings_store_sys as raw;
use nix_bindings_util::context::Context; use nix_bindings_util::context::Context;
use nix_bindings_util::string_return::{ use nix_bindings_util::string_return::{
@ -13,19 +12,17 @@ use std::collections::HashMap;
use std::ffi::{c_char, CString}; use std::ffi::{c_char, CString};
use std::ptr::null_mut; use std::ptr::null_mut;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::sync::{Arc, Mutex, Weak}; use std::sync::{Arc, LazyLock, Mutex, Weak};
#[cfg(nix_at_least = "2.33.0pre")] #[cfg(nix_at_least = "2.33.0pre")]
use crate::derivation::Derivation; use crate::derivation::Derivation;
use crate::path::StorePath; use crate::path::StorePath;
/* TODO make Nix itself thread safe */ /* TODO make Nix itself thread safe */
lazy_static! { static INIT: LazyLock<Result<()>> = LazyLock::new(|| unsafe {
static ref INIT: Result<()> = unsafe { check_call!(raw::libstore_init(&mut Context::new()))?;
check_call!(raw::libstore_init(&mut Context::new()))?; Ok(())
Ok(()) });
};
}
struct StoreRef { struct StoreRef {
inner: NonNull<raw::Store>, inner: NonNull<raw::Store>,
@ -68,9 +65,8 @@ impl StoreWeak {
/// Protects against https://github.com/NixOS/nix/issues/11979 (unless different parameters are passed, in which case it's up to luck, but you do get your own parameters as you asked for). /// Protects against https://github.com/NixOS/nix/issues/11979 (unless different parameters are passed, in which case it's up to luck, but you do get your own parameters as you asked for).
type StoreCacheMap = HashMap<(Option<String>, Vec<(String, String)>), StoreWeak>; type StoreCacheMap = HashMap<(Option<String>, Vec<(String, String)>), StoreWeak>;
lazy_static! { static STORE_CACHE: LazyLock<Arc<Mutex<StoreCacheMap>>> =
static ref STORE_CACHE: Arc<Mutex<StoreCacheMap>> = Arc::new(Mutex::new(HashMap::new())); LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
}
#[cfg(nix_at_least = "2.33.0pre")] #[cfg(nix_at_least = "2.33.0pre")]
unsafe extern "C" fn callback_get_result_store_path_set( unsafe extern "C" fn callback_get_result_store_path_set(