From ee9b9778b503160a1afc33ba852f39196d0ef0a4 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 11 Dec 2025 03:48:33 -0500 Subject: [PATCH] Patch `lazy_static` to `std::sync::LazyLock` This does remove the no-`std` variant of `lazy_static`, but that was unused and `std` was not additively implemented (making it poor to work with). This primarily tidies our `deny.toml` with one less `git` dependency. --- Cargo.lock | 3 +-- Cargo.toml | 8 +++----- deny.toml | 1 - patches/lazy_static/Cargo.toml | 16 ++++++++++++++++ patches/lazy_static/src/lib.rs | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 patches/lazy_static/Cargo.toml create mode 100644 patches/lazy_static/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ba66df86..1843e686 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4148,8 +4148,7 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.5.0" -source = "git+https://github.com/rust-lang-nursery/lazy-static.rs?rev=5735630d46572f1e5377c8f2ba0f79d18f53b10c#5735630d46572f1e5377c8f2ba0f79d18f53b10c" +version = "1.99.0" [[package]] name = "leb128fmt" diff --git a/Cargo.toml b/Cargo.toml index 9975d574..95172450 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -200,8 +200,9 @@ dalek-ff-group = { path = "patches/dalek-ff-group" } minimal-ed448 = { path = "crypto/ed448" } modular-frost = { path = "crypto/frost" } -# Patch due to `std` now including the required functionality -is_terminal_polyfill = { path = "./patches/is_terminal_polyfill" } +# Patches due to `std` now including the required functionality +is_terminal_polyfill = { path = "patches/is_terminal_polyfill" } +lazy_static = { path = "patches/lazy_static" } # This has a non-deprecated `std` alternative since Rust's 2024 edition home = { path = "patches/home" } @@ -209,9 +210,6 @@ home = { path = "patches/home" } darling = { path = "patches/darling" } thiserror = { path = "patches/thiserror" } -# https://github.com/rust-lang-nursery/lazy-static.rs/issues/201 -lazy_static = { git = "https://github.com/rust-lang-nursery/lazy-static.rs", rev = "5735630d46572f1e5377c8f2ba0f79d18f53b10c" } - # directories-next was created because directories was unmaintained # directories-next is now unmaintained while directories is maintained # The directories author pulls in ridiculously pointless crates and prefers diff --git a/deny.toml b/deny.toml index 87e8979a..b4d05526 100644 --- a/deny.toml +++ b/deny.toml @@ -147,7 +147,6 @@ unknown-registry = "deny" unknown-git = "deny" allow-registry = ["https://github.com/rust-lang/crates.io-index"] allow-git = [ - "https://github.com/rust-lang-nursery/lazy-static.rs", "https://github.com/kayabaNerve/elliptic-curves", "https://github.com/monero-oxide/monero-oxide", "https://github.com/serai-dex/patch-polkadot-sdk", diff --git a/patches/lazy_static/Cargo.toml b/patches/lazy_static/Cargo.toml new file mode 100644 index 00000000..aaaa1869 --- /dev/null +++ b/patches/lazy_static/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "lazy_static" +version = "1.99.0" +description = "`lazy_static` which patches to `std::sync::LazyLock`" +license = "MIT" +repository = "https://github.com/serai-dex/serai/tree/develop/patches/lazy_static" +authors = ["Luke Parker "] +keywords = [] +edition = "2021" +rust-version = "1.80" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[workspace] diff --git a/patches/lazy_static/src/lib.rs b/patches/lazy_static/src/lib.rs new file mode 100644 index 00000000..770da386 --- /dev/null +++ b/patches/lazy_static/src/lib.rs @@ -0,0 +1,14 @@ +#[macro_export] +macro_rules! lazy_static { + ($($(#[$attr: meta])* $vis: vis static ref $name: ident: $type: ty = $value: expr;)*) => { + $( + $(#[$attr])* + $vis static $name: std::sync::LazyLock<$type> = std::sync::LazyLock::new(|| $value); + )* + } +} + +/// Explicitly initialize a static declared with [`lazy_static`]. +pub fn initialize T>(lazy: &std::sync::LazyLock) { + std::sync::LazyLock::force(lazy); +}