From 75745b1bf92e3a71b7c9f9fa9127c9a617148ac4 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 10 Oct 2024 14:28:42 -0400 Subject: [PATCH] refactor(hal): s/once_cell::Lazy/std::sync::LazyLock Weaken our dependence on the `once_cell` crate by using functionality from `std` instead that was upstreamed from `once_cell`, this time with what's available in Rust 1.80+. It's not yet possible to eliminate this dependency entirely, but do what we can for now. --- Cargo.lock | 1 - wgpu-hal/Cargo.toml | 1 - wgpu-hal/src/gles/egl.rs | 14 +++++++++++--- wgpu-hal/src/gles/wgl.rs | 7 +++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe637cfc5b..554479940e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4149,7 +4149,6 @@ dependencies = [ "naga", "ndk-sys", "objc", - "once_cell", "ordered-float", "parking_lot", "profiling", diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 57103e4c05..4018a3e067 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -127,7 +127,6 @@ parking_lot.workspace = true profiling = { workspace = true, default-features = false } raw-window-handle.workspace = true thiserror.workspace = true -once_cell.workspace = true ordered-float = { workspace = true, optional = true } # backends common diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 399d467e3a..f2e4f1d952 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -1,9 +1,16 @@ use glow::HasContext; use hashbrown::HashMap; -use once_cell::sync::Lazy; use parking_lot::{MappedMutexGuard, Mutex, MutexGuard, RwLock}; -use std::{ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, sync::Arc, time::Duration}; +use std::{ + ffi, + mem::ManuallyDrop, + os::raw, + ptr, + rc::Rc, + sync::{Arc, LazyLock}, + time::Duration, +}; /// The amount of time to wait while trying to obtain a lock to the adapter context const CONTEXT_LOCK_TIMEOUT_SECS: u64 = 1; @@ -468,7 +475,8 @@ struct Inner { // Different calls to `eglGetPlatformDisplay` may return the same `Display`, making it a global // state of all our `EglContext`s. This forces us to track the number of such context to prevent // terminating the display if it's currently used by another `EglContext`. -static DISPLAYS_REFERENCE_COUNT: Lazy>> = Lazy::new(Default::default); +static DISPLAYS_REFERENCE_COUNT: LazyLock>> = + LazyLock::new(Default::default); fn initialize_display( egl: &EglInstance, diff --git a/wgpu-hal/src/gles/wgl.rs b/wgpu-hal/src/gles/wgl.rs index c1272371c8..ac3e7d73f0 100644 --- a/wgpu-hal/src/gles/wgl.rs +++ b/wgpu-hal/src/gles/wgl.rs @@ -5,7 +5,7 @@ use std::{ ptr, sync::{ mpsc::{sync_channel, SyncSender}, - Arc, + Arc, LazyLock, }, thread, time::Duration, @@ -17,7 +17,6 @@ use glutin_wgl_sys::wgl_extra::{ CONTEXT_PROFILE_MASK_ARB, }; use hashbrown::HashSet; -use once_cell::sync::Lazy; use parking_lot::{Mutex, MutexGuard, RwLock}; use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; use wgt::InstanceFlags; @@ -320,8 +319,8 @@ fn create_global_window_class() -> Result { } fn get_global_window_class() -> Result { - static GLOBAL: Lazy> = - Lazy::new(create_global_window_class); + static GLOBAL: LazyLock> = + LazyLock::new(create_global_window_class); GLOBAL.clone() }