Skip to content

chore: migrate once_cell to std::sync::LazyLock (bumps MSRV to 1.85)#972

Closed
anikettuli wants to merge 1 commit intoStremio:developmentfrom
anikettuli:claude/once-cell-to-std
Closed

chore: migrate once_cell to std::sync::LazyLock (bumps MSRV to 1.85)#972
anikettuli wants to merge 1 commit intoStremio:developmentfrom
anikettuli:claude/once-cell-to-std

Conversation

@anikettuli
Copy link
Copy Markdown

Summary

Migrates every once_cell::sync::Lazy usage in the workspace to std::sync::LazyLock (stabilized in Rust 1.80), drops once_cell from both Cargo.toml manifests, and bumps the declared MSRV from 1.771.85 to satisfy the LazyLock requirement.

Why this change

std::sync::LazyLock is an exact drop-in replacement for once_cell::sync::Lazy on supported toolchains — same API, same behavior, same performance characteristics. Keeping once_cell around for a feature the standard library now ships is pure dependency bloat.

Effect

  • One fewer third-party crate in the build graph on every build. Small but real shrink to compile time and Cargo.lock.
  • Aligns with standard Rust idioms — new contributors don't need to learn once_cell::sync::Lazy when LazyLock does the same job.
  • No runtime behavior change. LazyLock and Lazy use identical OnceLock internals; performance is equivalent.
  • No public API / no serialized-shape change.

Changes

Code — 10 files, mechanical replacement

For every file below: use once_cell::sync::Lazy;use std::sync::LazyLock;, and every Lazy::new(...) / Lazy<T> renamed to LazyLock::new(...) / LazyLock<T>. The static items themselves (e.g., CINEMETA_URL, FETCH_HANDLER) have the exact same type semantics as before.

  • src/addon_transport/http_transport/http_transport.rs
  • src/constants.rs
  • src/models/ctx/update_notifications.rs
  • src/models/player.rs
  • src/unit_tests/ctx/notifications/update_notifications.rs
  • src/unit_tests/ctx/sync_library_with_api.rs
  • src/unit_tests/deep_links/library_item_deep_links.rs
  • src/unit_tests/env.rs
  • stremio-core-web/src/env.rs
  • stremio-core-web/src/stremio_core_web.rs

OnceCell / OnceLock usage was not present in this workspace, so that half of the usual migration was not needed.

Manifest

  • Cargo.toml (root) — drop once_cell = "1", bump rust-version "1.77""1.85", fix an outdated comment that referenced msrv.yaml.
  • stremio-core-web/Cargo.toml — drop once_cell = "1".
  • stremio-watched-bitfield/Cargo.toml — bump rust-version "1.60""1.85" for workspace-wide consistency.
  • .github/workflows/msrv.ymlRUST_MSRV_VERSION: '1.77''1.85'.

Why the MSRV bump

LazyLock was stabilized in Rust 1.80. Setting MSRV to 1.85 (rather than the minimum 1.80) matches the build.yml CI matrix and leaves some headroom. It overlaps perfectly with #970 (the standalone MSRV bump PR) — whichever merges first, the other's MSRV diff becomes a no-op on rebase.

Dependency on other PRs

Test plan

Verified locally (Rust 1.85.1 stable-x86_64-pc-windows-gnu):

  • cargo test -p stremio-core --lib202 passed, 0 failed
  • cargo test -p stremio-watched-bitfield7 passed, 0 failed
  • cargo clippy --all --no-deps -- -D warnings — clean
  • cargo fmt --check — clean

`std::sync::LazyLock` (stabilized in Rust 1.80) provides the same behavior
as `once_cell::sync::Lazy` without a third-party dependency. Migrating cuts
one crate from every build and tightens the stdlib alignment story.

`OnceCell` / `OnceLock` usage was not present in the workspace, so this PR
focuses purely on the `Lazy` migration.

Changes:
- 10 files: `use once_cell::sync::Lazy;` -> `use std::sync::LazyLock;`,
  and every `Lazy::new(...)` / `: Lazy<T>` renamed to `LazyLock::new(...)`
  / `: LazyLock<T>`. No behavior change - API is drop-in identical.
- Cargo.toml (root): drop `once_cell = "1"`, bump `rust-version` to 1.85.
- stremio-core-web/Cargo.toml: drop `once_cell = "1"`.
- stremio-watched-bitfield/Cargo.toml: bump `rust-version` to 1.85 for
  consistency with the workspace.
- .github/workflows/msrv.yml: RUST_MSRV_VERSION to 1.85.

The MSRV bump is required because `LazyLock` needs Rust 1.80+. Bumping
to 1.85 matches the CI matrix (build.yml uses stable) so there is no
fresh floor to enforce separately. If Stremio#970 (the standalone MSRV bump PR)
lands first, the MSRV changes here become no-ops; if this lands first,
Stremio#970 becomes a no-op. Either merge order is clean.

Touched files:
  src/addon_transport/http_transport/http_transport.rs
  src/constants.rs
  src/models/ctx/update_notifications.rs
  src/models/player.rs
  src/unit_tests/ctx/notifications/update_notifications.rs
  src/unit_tests/ctx/sync_library_with_api.rs
  src/unit_tests/deep_links/library_item_deep_links.rs
  src/unit_tests/env.rs
  stremio-core-web/src/env.rs
  stremio-core-web/src/stremio_core_web.rs

Verified locally (Rust 1.85.1 stable-x86_64-pc-windows-gnu):
  cargo test -p stremio-core --lib         -> 202 passed, 0 failed
  cargo test -p stremio-watched-bitfield   -> 7 passed, 0 failed
  cargo clippy --all --no-deps -D warnings -> clean
  cargo fmt --check                         -> clean
Copilot AI review requested due to automatic review settings April 20, 2026 05:08
@github-actions
Copy link
Copy Markdown

stremio-core-web prebuild

Prebuild artifact published by the Build workflow for branch claude/once-cell-to-std.

Paste one of these into stremio-web's package.json and run pnpm install to wire this prebuild into a corresponding stremio-web PR:

Release

"@stremio/stremio-core-web": "https://stremio.github.io/stremio-core/stremio-core-web/claude/once-cell-to-std/stremio-stremio-core-web-0.56.3.tgz"

Dev

"@stremio/stremio-core-web": "https://stremio.github.io/stremio-core/stremio-core-web/claude/once-cell-to-std/dev/stremio-stremio-core-web-0.56.3.tgz"

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the workspace from once_cell::sync::Lazy to std::sync::LazyLock, removes the direct once_cell dependency from manifests, and bumps the declared MSRV to Rust 1.85 (including the MSRV CI workflow).

Changes:

  • Replace once_cell::sync::Lazy statics with std::sync::LazyLock across core, web, and unit test modules.
  • Remove once_cell = "1" from the relevant Cargo.toml manifests and update MSRV metadata/CI.
  • Update Cargo.lock accordingly (including lockfile format version bump).

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Cargo.toml Bumps MSRV to 1.85 and removes direct once_cell dependency.
stremio-watched-bitfield/Cargo.toml Aligns crate MSRV to 1.85.
stremio-core-web/Cargo.toml Removes direct once_cell dependency.
.github/workflows/msrv.yml Updates MSRV CI toolchain to 1.85.
Cargo.lock Removes once_cell from affected crates’ direct dependency lists; lockfile version updates.
src/constants.rs Converts global Lazy<...> statics to LazyLock<...>.
src/models/player.rs Converts PUSH_TO_LIBRARY_EVERY to LazyLock.
src/models/ctx/update_notifications.rs Converts REQUEST_LAST_VIDEOS_EVERY to LazyLock.
src/addon_transport/http_transport/http_transport.rs Converts CINEMETA_ADDONS_CATALOG_URL to LazyLock.
src/unit_tests/env.rs Migrates unit-test globals from Lazy to LazyLock.
src/unit_tests/deep_links/library_item_deep_links.rs Migrates test fixtures to LazyLock.
src/unit_tests/ctx/sync_library_with_api.rs Migrates test fixtures to LazyLock.
src/unit_tests/ctx/notifications/update_notifications.rs Migrates test fixtures to LazyLock.
stremio-core-web/src/env.rs Migrates web env statics to LazyLock.
stremio-core-web/src/stremio_core_web.rs Migrates runtime static to LazyLock.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::sync::LazyLock;
Comment thread src/unit_tests/env.rs
use futures::{channel::mpsc::Receiver, future, Future, StreamExt, TryFutureExt};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::sync::LazyLock;
@anikettuli
Copy link
Copy Markdown
Author

Superseded by #973 — the five dead-weight/MSRV modernizations are bundled there to avoid five near-identical Cargo.toml / Cargo.lock merges. Each change remains a distinct commit for piecewise review.

@anikettuli anikettuli closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants