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:
- 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.
- 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.
- Disable default features on most dependencies
- 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.
- 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.
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.
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.
BadIcon wraps an io::Error. This type is moved into core on nightly, but there's no ETA for stabilisation.
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.
- Probably need to bring in
once_lock.
Relevant platforms
Web
Description
When compiling for web,
wasm32-unknown-unknownis 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 recentwasm32v1-nonetarget, which enables the bare minimum set of Wasm features, maintaining a consistent compatibility. Critically, this target also undoes the decision to use a stubbedstd, opting instead forwasm32v1-noneto just be ano_stdtarget.I noticed
winitwas 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:
clippy::std_instead_of_core,clippy::std_instead_of_alloc, andclippy::alloc_instead_of_coreand replacestdusage withcoreandallocwhere trivial.#![no_std] extern crate std; extern crate alloc;towinit-core,winit-web, andwinitto swap from thestdimplicit prelude to thecoreimplicit.libmtowinit-core. Note thatdpihas an inlined subset oflibm, I don't believe this is advisable forwinit-core, asround,sin,cos,tan,atan,atan2, andhypotare all required.WindowEvent. TheDragevents include public usage ofPathBuf. Either the enum needs to benon_exhaustivewith those arms gated, or some further encapsulation is required.SurfaceSizeWriterusesMutexin its public API. This could be pretty easily abstracted with a new type wrapping either an alternateMutex(e.g.,spin), or it could just be a packedAtomicU64.web-timecurrently lacksno_stdsupport for no particular reason, so either APIs involvingInstantneed to be gated, or further work upstream is required.BadIconwraps anio::Error. This type is moved intocoreonnightly, but there's no ETA for stabilisation.winit-webmakes extensive usage ofthread_local's. These can be safely replaced withunsafe impl Send + Syncwrappers, since Wasm without atomics is trivially single threaded only. This is the approachwgpuuses.once_lock.Relevant platforms
Web