rust-windowing / rust-windowing/winit
Support `wasm32v1-none`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
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, andclippy::alloc_instead_of_coreand replacestdusage withcoreandallocwhere trivial. - Add
#![no_std] extern crate std; extern crate alloc;towinit-core,winit-web, andwinitto swap from thestdimplicit prelude to thecoreimplicit. - Disable default features on most dependencies
- Add
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. - Change
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.- Probably need to bring in
once_lock.
Relevant platforms
Web
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by auditing the winit-core, winit-web, and winit crates against the ten listed wasm32v1-none and no_std blockers, especially public APIs using PathBuf, Mutex, Instant, and io::Error. Build the relevant crates for wasm32v1-none first, then verify that the platform APIs and dependencies compile without the current std assumptions; done means the target builds with compatible web functionality.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100