From 63730c440d4eaef84bbdbb1fd8d56fe1768fde70 Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Mon, 17 Aug 2026 10:37:54 +1000 Subject: [PATCH] wgpu-sync: Add `once_cell` Centralizes configuration of `once_cell` and avoids duplicating fallback logic across crates. --- Cargo.lock | 1 + wgpu-sync/Cargo.toml | 5 +++-- wgpu-sync/src/lib.rs | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e00efa31..2ec6ed539 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5037,6 +5037,7 @@ version = "30.0.0" dependencies = [ "cfg-if", "lock_api", + "once_cell", "parking_lot", ] diff --git a/wgpu-sync/Cargo.toml b/wgpu-sync/Cargo.toml index ed5ad74ac..7ab4d2f52 100644 --- a/wgpu-sync/Cargo.toml +++ b/wgpu-sync/Cargo.toml @@ -29,10 +29,11 @@ alloc_instead_of_core = "warn" [features] default = ["std"] -std = ["alloc", "dep:parking_lot"] -alloc = [] +std = ["alloc", "dep:parking_lot", "once_cell/std"] +alloc = ["once_cell/alloc"] [dependencies] cfg-if.workspace = true lock_api = { workspace = true, default-features = false } parking_lot = { workspace = true, optional = true } +once_cell = { workspace = true, default-features = false, features = ["race"] } diff --git a/wgpu-sync/src/lib.rs b/wgpu-sync/src/lib.rs index a504c4e43..b49b8db6d 100644 --- a/wgpu-sync/src/lib.rs +++ b/wgpu-sync/src/lib.rs @@ -28,6 +28,18 @@ pub use rwlock::RawRwLock; #[cfg(feature = "std")] pub use parking_lot::{Condvar, Mutex as CondvarMutex}; +#[cfg(feature = "alloc")] +pub use once_cell::race::OnceBox; +pub use once_cell::race::{OnceBool, OnceNonZeroUsize, OnceRef}; + +cfg_if::cfg_if! { + if #[cfg(feature = "std")] { + pub use once_cell::sync::{Lazy, OnceCell}; + } else { + pub use once_cell::unsync::{Lazy, OnceCell}; + } +} + /// A [`Mutex`](lock_api::Mutex) using [`RawMutex`] for its backing implementation. pub type Mutex = lock_api::Mutex;