Skip to content

Support wasm32v1-none #4629

Description

@bushrat011899

Description

When compiling for web, wasm32-unknown-unknown is currently the defacto target. However, this target has an evolving set of enabled Wasm features, which can cause browser compatibility issues. Rust's solution to this problem is the relatively recent wasm32v1-none target, which enables the bare minimum set of Wasm features, maintaining a consistent compatibility. Critically, this target also undoes the decision to use a stubbed std, opting instead for wasm32v1-none to just be a no_std target.

I noticed winit was missing this compatibility while working on wgpu#6826, as I have made enough progress to start working on examples.

Based on a cursory glance, here are some changes I think would need to be made:

  1. Warn on clippy::std_instead_of_core, clippy::std_instead_of_alloc, and clippy::alloc_instead_of_core and replace std usage with core and alloc where trivial.
  2. Add #![no_std] extern crate std; extern crate alloc; to winit-core, winit-web, and winit to swap from the std implicit prelude to the core implicit.
  3. Disable default features on most dependencies
  4. Add libm to winit-core. Note that dpi has an inlined subset of libm, I don't believe this is advisable for winit-core, as round, sin, cos, tan, atan, atan2, and hypot are all required.
  5. Change WindowEvent. The Drag events include public usage of PathBuf. Either the enum needs to be non_exhaustive with those arms gated, or some further encapsulation is required.
  6. SurfaceSizeWriter uses Mutex in its public API. This could be pretty easily abstracted with a new type wrapping either an alternate Mutex (e.g., spin), or it could just be a packed AtomicU64.
  7. web-time currently lacks no_std support for no particular reason, so either APIs involving Instant need to be gated, or further work upstream is required.
  8. BadIcon wraps an io::Error. This type is moved into core on nightly, but there's no ETA for stabilisation.
  9. winit-web makes extensive usage of thread_local's. These can be safely replaced with unsafe impl Send + Sync wrappers, since Wasm without atomics is trivially single threaded only. This is the approach wgpu uses.
  10. Probably need to bring in once_lock.

Relevant platforms

Web

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions