wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Use LazyLock for std environments and OnceBox for no_std

Open FalkWoldmann opened this issue 4 weeks ago • 2 comments

Description Right now, we always use once_cell in naga, even when std with LazyLock is available.

Testing I ran cargo xtask test locally.

Squash or Rebase?

Rebase

Checklist

  • [x] Run cargo fmt.
  • [x] Run taplo format.
  • [x] Run cargo clippy --tests. If applicable, add:
    • [x] --target wasm32-unknown-unknown
  • [x] Run cargo xtask test to run tests.
  • [x] If this contains user-facing changes, add a CHANGELOG.md entry.

FalkWoldmann avatar Dec 03 '25 09:12 FalkWoldmann

The "cleanest" way of ensuring that once_lock is actually optional for std builds would be to introduce an explicit std feature. This would, however, mean breaking changes for no_std users, as they would then need to add naga with no default features and the once_cell feature. Would this be okay with you?

FalkWoldmann avatar Dec 03 '25 09:12 FalkWoldmann

@FalkWoldmann: Yes, please! Filed https://github.com/gfx-rs/wgpu/issues/8701 for tracking. 🙂

ErichDonGubler avatar Dec 10 '25 20:12 ErichDonGubler

Just waiting for an answer to this comment before merging; friendly ping for @FalkWoldmann, in case this fell off the radar.

ErichDonGubler avatar Dec 19 '25 16:12 ErichDonGubler

Hi, yeah, sorry! Missed it :) the main motivation is to use the components which are already available via std to reduce the amount of external code that is run. However, we still bundle the dependency, so one could argue if this really changes a lot. I would say so, since I am of the opinion that the std features should always be preferred if they provide the features we need, which is the case here.

FalkWoldmann avatar Dec 19 '25 18:12 FalkWoldmann