From 16d860736b090449f75a8974861f7e81549c8561 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 14 Jan 2024 18:54:52 +0100 Subject: [PATCH] Platform is called Web not Wasm (#3393) --- Cargo.toml | 2 +- README.md | 4 ++-- build.rs | 6 +++--- examples/control_flow.rs | 4 ++-- examples/custom_cursors.rs | 22 +++++++++++----------- examples/custom_events.rs | 4 ++-- examples/focus.rs | 4 ++-- examples/multithreaded.rs | 6 +++--- examples/request_redraw_threaded.rs | 4 ++-- examples/timer.rs | 4 ++-- examples/web.rs | 8 ++++---- examples/web_aspect_ratio.rs | 2 +- examples/window_pump_events.rs | 2 +- src/event.rs | 4 ++-- src/event_loop.rs | 14 +++++++------- src/platform/mod.rs | 2 +- src/platform/run_on_demand.rs | 2 +- src/platform/web.rs | 16 ++++++++-------- src/platform_impl/mod.rs | 4 ++-- 19 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 33521e3b..74ab937b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ targets = [ "x86_64-apple-ios", # Android "aarch64-linux-android", - # WebAssembly + # Web "wasm32-unknown-unknown", ] rustdoc-args = ["--cfg", "docsrs"] diff --git a/README.md b/README.md index 3ca51979..e00c27ce 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ same MSRV policy. Note that windows don't appear on Wayland until you draw/present to them. -#### WebAssembly +#### Web To run the web example: `cargo run-wasm --example web` @@ -87,7 +87,7 @@ either [provide Winit with a `` element][web with_canvas], or [let Winit create a `` element which you can then retrieve][web canvas getter] and insert it into the DOM yourself. -For the example code using Winit with WebAssembly, check out the [web example]. For +For the example code using Winit on Web, check out the [web example]. For information on using Rust on WebAssembly, check out the [Rust and WebAssembly book]. diff --git a/build.rs b/build.rs index 7d83d771..371e4978 100644 --- a/build.rs +++ b/build.rs @@ -8,7 +8,7 @@ fn main() { cfg_aliases! { // Systems. android_platform: { target_os = "android" }, - wasm_platform: { all(target_family = "wasm", not(target_os = "emscripten")) }, + web_platform: { all(target_family = "wasm", target_os = "unknown") }, macos_platform: { target_os = "macos" }, ios_platform: { target_os = "ios" }, windows_platform: { target_os = "windows" }, @@ -17,8 +17,8 @@ fn main() { redox: { target_os = "redox" }, // Native displays. - x11_platform: { all(feature = "x11", free_unix, not(wasm), not(redox)) }, - wayland_platform: { all(feature = "wayland", free_unix, not(wasm), not(redox)) }, + x11_platform: { all(feature = "x11", free_unix, not(redox)) }, + wayland_platform: { all(feature = "wayland", free_unix, not(redox)) }, orbital_platform: { redox }, } } diff --git a/examples/control_flow.rs b/examples/control_flow.rs index 5032d0bf..2819497e 100644 --- a/examples/control_flow.rs +++ b/examples/control_flow.rs @@ -1,9 +1,9 @@ #![allow(clippy::single_match)] use std::thread; -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] use std::time; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use web_time as time; use simple_logger::SimpleLogger; diff --git a/examples/custom_cursors.rs b/examples/custom_cursors.rs index a5c69505..11f16f77 100644 --- a/examples/custom_cursors.rs +++ b/examples/custom_cursors.rs @@ -1,6 +1,6 @@ #![allow(clippy::single_match, clippy::disallowed_methods)] -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] use simple_logger::SimpleLogger; use winit::{ event::{ElementState, Event, KeyEvent, WindowEvent}, @@ -8,14 +8,14 @@ use winit::{ keyboard::Key, window::{CursorIcon, CustomCursor, WindowBuilder}, }; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use { std::sync::atomic::{AtomicU64, Ordering}, std::time::Duration, winit::platform::web::CustomCursorExtWebSys, }; -#[cfg(wasm_platform)] +#[cfg(web_platform)] static COUNTER: AtomicU64 = AtomicU64::new(0); fn decode_cursor(bytes: &[u8], window_target: &EventLoopWindowTarget) -> CustomCursor { @@ -28,22 +28,22 @@ fn decode_cursor(bytes: &[u8], window_target: &EventLoopWindowTarget) -> CustomC builder.build(window_target) } -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] #[path = "util/fill.rs"] mod fill; fn main() -> Result<(), impl std::error::Error> { - #[cfg(not(wasm_platform))] + #[cfg(not(web_platform))] SimpleLogger::new() .with_level(log::LevelFilter::Info) .init() .unwrap(); - #[cfg(wasm_platform)] + #[cfg(web_platform)] console_log::init_with_level(log::Level::Debug).unwrap(); let event_loop = EventLoop::new().unwrap(); let builder = WindowBuilder::new().with_title("A fantastic window!"); - #[cfg(wasm_platform)] + #[cfg(web_platform)] let builder = { use winit::platform::web::WindowBuilderExtWebSys; builder.with_append(true) @@ -83,7 +83,7 @@ fn main() -> Result<(), impl std::error::Error> { log::debug!("Setting cursor visibility to {:?}", cursor_visible); window.set_cursor_visible(cursor_visible); } - #[cfg(wasm_platform)] + #[cfg(web_platform)] Key::Character("4") => { log::debug!("Setting cursor to a random image from an URL"); window.set_cursor( @@ -98,7 +98,7 @@ fn main() -> Result<(), impl std::error::Error> { .build(_elwt), ); } - #[cfg(wasm_platform)] + #[cfg(web_platform)] Key::Character("5") => { log::debug!("Setting cursor to an animation"); window.set_cursor( @@ -125,11 +125,11 @@ fn main() -> Result<(), impl std::error::Error> { _ => {} }, WindowEvent::RedrawRequested => { - #[cfg(not(wasm_platform))] + #[cfg(not(web_platform))] fill::fill_window(&window); } WindowEvent::CloseRequested => { - #[cfg(not(wasm_platform))] + #[cfg(not(web_platform))] _elwt.exit(); } _ => (), diff --git a/examples/custom_events.rs b/examples/custom_events.rs index 50501e67..40bf957c 100644 --- a/examples/custom_events.rs +++ b/examples/custom_events.rs @@ -1,6 +1,6 @@ #![allow(clippy::single_match)] -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] fn main() -> Result<(), impl std::error::Error> { use simple_logger::SimpleLogger; use winit::{ @@ -56,7 +56,7 @@ fn main() -> Result<(), impl std::error::Error> { }) } -#[cfg(wasm_platform)] +#[cfg(web_platform)] fn main() { panic!("This example is not supported on web."); } diff --git a/examples/focus.rs b/examples/focus.rs index 29d3c621..e8c66237 100644 --- a/examples/focus.rs +++ b/examples/focus.rs @@ -3,9 +3,9 @@ //! Example for focusing a window. use simple_logger::SimpleLogger; -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] use std::time; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use web_time as time; use winit::{ event::{Event, StartCause, WindowEvent}, diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index 3bcf462f..8453d10f 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -1,6 +1,6 @@ #![allow(clippy::single_match)] -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] fn main() -> Result<(), impl std::error::Error> { use std::{collections::HashMap, sync::mpsc, thread, time::Duration}; @@ -205,7 +205,7 @@ fn main() -> Result<(), impl std::error::Error> { }) } -#[cfg(wasm_platform)] +#[cfg(web_platform)] fn main() { - panic!("Example not supported on Wasm"); + panic!("Example not supported on Web"); } diff --git a/examples/request_redraw_threaded.rs b/examples/request_redraw_threaded.rs index 6070c2ae..f4412001 100644 --- a/examples/request_redraw_threaded.rs +++ b/examples/request_redraw_threaded.rs @@ -1,6 +1,6 @@ #![allow(clippy::single_match)] -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] fn main() -> Result<(), impl std::error::Error> { use std::{sync::Arc, thread, time}; @@ -53,7 +53,7 @@ fn main() -> Result<(), impl std::error::Error> { }) } -#[cfg(wasm_platform)] +#[cfg(web_platform)] fn main() { unimplemented!() // `Window` can't be sent between threads } diff --git a/examples/timer.rs b/examples/timer.rs index 62c0eee4..f8e03a7b 100644 --- a/examples/timer.rs +++ b/examples/timer.rs @@ -1,9 +1,9 @@ #![allow(clippy::single_match)] use std::time::Duration; -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] use std::time::Instant; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use web_time::Instant; use simple_logger::SimpleLogger; diff --git a/examples/web.rs b/examples/web.rs index febc903a..82534d6b 100644 --- a/examples/web.rs +++ b/examples/web.rs @@ -11,18 +11,18 @@ pub fn main() -> Result<(), impl std::error::Error> { let event_loop = EventLoop::new().unwrap(); let builder = WindowBuilder::new().with_title("A fantastic window!"); - #[cfg(wasm_platform)] + #[cfg(web_platform)] let builder = { use winit::platform::web::WindowBuilderExtWebSys; builder.with_append(true) }; let window = builder.build(&event_loop).unwrap(); - #[cfg(wasm_platform)] + #[cfg(web_platform)] let log_list = wasm::insert_canvas_and_create_log_list(&window); event_loop.run(move |event, elwt| { - #[cfg(wasm_platform)] + #[cfg(web_platform)] wasm::log_event(&log_list, &event); match event { @@ -57,7 +57,7 @@ pub fn main() -> Result<(), impl std::error::Error> { }) } -#[cfg(wasm_platform)] +#[cfg(web_platform)] mod wasm { use std::num::NonZeroU32; diff --git a/examples/web_aspect_ratio.rs b/examples/web_aspect_ratio.rs index 38bbc555..274d581b 100644 --- a/examples/web_aspect_ratio.rs +++ b/examples/web_aspect_ratio.rs @@ -4,7 +4,7 @@ pub fn main() { println!("This example must be run with cargo run-wasm --example web_aspect_ratio") } -#[cfg(wasm_platform)] +#[cfg(web_platform)] mod wasm { use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; diff --git a/examples/window_pump_events.rs b/examples/window_pump_events.rs index 040ad7f0..cbe25762 100644 --- a/examples/window_pump_events.rs +++ b/examples/window_pump_events.rs @@ -68,7 +68,7 @@ fn main() -> std::process::ExitCode { } } -#[cfg(any(ios_platform, wasm_platform, orbital_platform))] +#[cfg(any(ios_platform, web_platform, orbital_platform))] fn main() { println!("This platform doesn't support pump_events."); } diff --git a/src/event.rs b/src/event.rs index 66871835..53a65654 100644 --- a/src/event.rs +++ b/src/event.rs @@ -34,13 +34,13 @@ //! [`ControlFlow::WaitUntil`]: crate::event_loop::ControlFlow::WaitUntil use std::path::PathBuf; use std::sync::{Mutex, Weak}; -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] use std::time::Instant; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use smol_str::SmolStr; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use web_time::Instant; use crate::error::ExternalError; diff --git a/src/event_loop.rs b/src/event_loop.rs index fa50bdd9..1cade1f0 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -14,9 +14,9 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::{error, fmt}; -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] use std::time::{Duration, Instant}; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use web_time::{Duration, Instant}; use crate::error::EventLoopError; @@ -130,7 +130,7 @@ impl EventLoopBuilder { }) } - #[cfg(wasm_platform)] + #[cfg(web_platform)] pub(crate) fn allow_event_loop_recreation() { EVENT_LOOP_CREATED.store(false, Ordering::Relaxed); } @@ -223,10 +223,10 @@ impl EventLoop { /// /// Web applications are recommended to use #[cfg_attr( - wasm_platform, + web_platform, doc = "[`EventLoopExtWebSys::spawn()`][crate::platform::web::EventLoopExtWebSys::spawn()]" )] - #[cfg_attr(not(wasm_platform), doc = "`EventLoopExtWebSys::spawn()`")] + #[cfg_attr(not(web_platform), doc = "`EventLoopExtWebSys::spawn()`")] /// [^1] instead of [`run()`] to avoid the need /// for the Javascript exception trick, and to make it clearer that the event loop runs /// asynchronously (via the browser's own, internal, event loop) and doesn't block the @@ -236,9 +236,9 @@ impl EventLoop { /// /// [`set_control_flow()`]: EventLoopWindowTarget::set_control_flow() /// [`run()`]: Self::run() - /// [^1]: `EventLoopExtWebSys::spawn()` is only available on WASM. + /// [^1]: `EventLoopExtWebSys::spawn()` is only available on Web. #[inline] - #[cfg(not(all(wasm_platform, target_feature = "exception-handling")))] + #[cfg(not(all(web_platform, target_feature = "exception-handling")))] pub fn run(self, event_handler: F) -> Result<(), EventLoopError> where F: FnMut(Event, &EventLoopWindowTarget), diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 94dcec65..187489da 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -14,7 +14,7 @@ pub mod orbital; pub mod startup_notify; #[cfg(any(wayland_platform, docsrs))] pub mod wayland; -#[cfg(any(wasm_platform, docsrs))] +#[cfg(any(web_platform, docsrs))] pub mod web; #[cfg(any(windows_platform, docsrs))] pub mod windows; diff --git a/src/platform/run_on_demand.rs b/src/platform/run_on_demand.rs index b877a657..603efab1 100644 --- a/src/platform/run_on_demand.rs +++ b/src/platform/run_on_demand.rs @@ -58,7 +58,7 @@ pub trait EventLoopExtRunOnDemand { /// - **iOS:** It's not possible to stop and start an `NSApplication` repeatedly on iOS. /// #[cfg_attr( - not(wasm_platform), + not(web_platform), doc = "[^1]: `spawn()` is only available on `wasm` platforms." )] /// diff --git a/src/platform/web.rs b/src/platform/web.rs index ecbe064e..2f301605 100644 --- a/src/platform/web.rs +++ b/src/platform/web.rs @@ -34,18 +34,18 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use web_sys::HtmlCanvasElement; use crate::cursor::CustomCursorBuilder; use crate::event::Event; use crate::event_loop::{EventLoop, EventLoopWindowTarget}; -#[cfg(wasm_platform)] +#[cfg(web_platform)] use crate::platform_impl::CustomCursorFuture as PlatformCustomCursorFuture; use crate::platform_impl::{PlatformCustomCursor, PlatformCustomCursorBuilder}; use crate::window::{CustomCursor, Window, WindowBuilder}; -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] #[doc(hidden)] pub struct HtmlCanvasElement; @@ -93,7 +93,7 @@ pub trait WindowBuilderExtWebSys { /// /// [`None`] by default. #[cfg_attr( - not(wasm_platform), + not(web_platform), doc = "", doc = "[`HtmlCanvasElement`]: #only-available-on-wasm" )] @@ -150,11 +150,11 @@ pub trait EventLoopExtWebSys { /// /// Unlike #[cfg_attr( - all(wasm_platform, target_feature = "exception-handling"), + all(web_platform, target_feature = "exception-handling"), doc = "`run()`" )] #[cfg_attr( - not(all(wasm_platform, target_feature = "exception-handling")), + not(all(web_platform, target_feature = "exception-handling")), doc = "[`run()`]" )] /// [^1], this returns immediately, and doesn't throw an exception in order to @@ -166,7 +166,7 @@ pub trait EventLoopExtWebSys { /// event loop when switching between tabs on a single page application. /// #[cfg_attr( - not(all(wasm_platform, target_feature = "exception-handling")), + not(all(web_platform, target_feature = "exception-handling")), doc = "[`run()`]: EventLoop::run()" )] /// [^1]: `run()` is _not_ available on WASM when the target supports `exception-handling`. @@ -327,7 +327,7 @@ impl CustomCursorBuilderExtWebSys for CustomCursorBuilder { } } -#[cfg(not(wasm_platform))] +#[cfg(not(web_platform))] struct PlatformCustomCursorFuture; #[derive(Debug)] diff --git a/src/platform_impl/mod.rs b/src/platform_impl/mod.rs index c8933777..1e2acead 100644 --- a/src/platform_impl/mod.rs +++ b/src/platform_impl/mod.rs @@ -16,7 +16,7 @@ mod platform; #[cfg(ios_platform)] #[path = "ios/mod.rs"] mod platform; -#[cfg(wasm_platform)] +#[cfg(web_platform)] #[path = "web/mod.rs"] mod platform; #[cfg(orbital_platform)] @@ -63,7 +63,7 @@ impl From for RootFullscreen { not(android_platform), not(x11_platform), not(wayland_platform), - not(wasm_platform), + not(web_platform), not(orbital_platform), ))] compile_error!("The platform you're compiling for is not supported by winit");