Skip to content

MVP no_std for wgpu-core #7746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

bushrat011899
Copy link
Contributor

@bushrat011899 bushrat011899 commented Jun 2, 2025

Connections

Description

Adds no_std support to wgpu-core through 3 changes:

  1. Use num-traits within timestamp_normalization to account for the floating point methods only available with std.
  2. Make parking_lot optional by falling back to either std::sync::{Mutex, RwLock}, spin::{Mutex, RwLock}, or core::cell::RefCell based on selecting either parking_lot, std, spin, or no locking implementation.
    a. Note that spin was already in the lockfile via crossbeam-deque so this feature is "free"
    b. Note that RefCell is !Sync, so users should select spin in no_std environments. The use of RefCell as a fallback just allows compilation to succeed without any features enabled.
  3. Make once_cell optional by falling back to core::cell:OnceCell.
    a. Note that once_cell is no_std compatible, but it requires activating the critical-section feature to access its implementation of OnceCell. Adding such a feature would therefore add critical-section to the lockfile, requiring thorough review due to its use of unsafe and extern "Rust". I believe it is a safe inclusion, but it can be avoided here so I'd rather save that quality of life feature for a follow-up. Users are still able to use once_cell with wgpu-core on no_std, they just have to enable once_cell/critical-section themselves.
    b. Note that core::cell::OnceCell is !Sync, so users should prefer to enable critical-section themselves.

To preserve existing behavior, the newly added parking_lot and once_cell features are enabled by default.

Testing

Added wgpu-core to the wasm32v1-none CI test.

Squash or Rebase?

Squash

Checklist

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

@bushrat011899 bushrat011899 requested a review from a team as a code owner June 2, 2025 02:30
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