diff --git a/winit-core/Cargo.toml b/winit-core/Cargo.toml index 0b9dd9e621..bce82c983b 100644 --- a/winit-core/Cargo.toml +++ b/winit-core/Cargo.toml @@ -23,11 +23,9 @@ rwh_06.workspace = true serde = { workspace = true, optional = true } smol_str.workspace = true -[target.'cfg(target_family = "wasm")'.dependencies] +# `wasm32-unknown-unknown` and `wasm32-none`, but not `wasm32-wasi`. +[target.'cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))'.dependencies] web-time.workspace = true -[build-dependencies] -cfg_aliases.workspace = true - [dev-dependencies] winit.workspace = true diff --git a/winit-core/build.rs b/winit-core/build.rs deleted file mode 100644 index 915ec231b8..0000000000 --- a/winit-core/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -use cfg_aliases::cfg_aliases; - -fn main() { - // The script doesn't depend on our code. - println!("cargo:rerun-if-changed=build.rs"); - - // Setup cfg aliases. - cfg_aliases! { - web_platform: { all(target_family = "wasm", target_os = "unknown") }, - } -} diff --git a/winit-core/src/event.rs b/winit-core/src/event.rs index 416723749c..42c37c8d1c 100644 --- a/winit-core/src/event.rs +++ b/winit-core/src/event.rs @@ -1,15 +1,11 @@ //! The event enums and assorted supporting types. use std::path::PathBuf; use std::sync::{Mutex, Weak}; -#[cfg(not(web_platform))] -use std::time::Instant; use dpi::{PhysicalPosition, PhysicalSize}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use smol_str::SmolStr; -#[cfg(web_platform)] -use web_time::Instant; use crate::error::RequestError; use crate::event_loop::AsyncRequestSerial; @@ -17,6 +13,7 @@ use crate::keyboard::{self, ModifiersKeyState, ModifiersKeys, ModifiersState}; #[cfg(doc)] use crate::window::Window; use crate::window::{ActivationToken, Theme}; +use crate::Instant; /// Describes the reason the event loop is resuming. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/winit-core/src/event_loop/mod.rs b/winit-core/src/event_loop/mod.rs index 8d35b1180b..71307ee7c2 100644 --- a/winit-core/src/event_loop/mod.rs +++ b/winit-core/src/event_loop/mod.rs @@ -4,18 +4,16 @@ pub mod run_on_demand; use std::fmt::{self, Debug}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; -#[cfg(not(web_platform))] -use std::time::{Duration, Instant}; +use std::time::Duration; use rwh_06::{DisplayHandle, HandleError, HasDisplayHandle}; -#[cfg(web_platform)] -use web_time::{Duration, Instant}; use crate::as_any::AsAny; use crate::cursor::{CustomCursor, CustomCursorSource}; use crate::error::RequestError; use crate::monitor::MonitorHandle; use crate::window::{Theme, Window, WindowAttributes}; +use crate::Instant; pub trait ActiveEventLoop: AsAny + fmt::Debug { /// Creates an [`EventLoopProxy`] that can be used to dispatch user events diff --git a/winit-core/src/event_loop/run_on_demand.rs b/winit-core/src/event_loop/run_on_demand.rs index a6e225623f..4fa5a019b0 100644 --- a/winit-core/src/event_loop/run_on_demand.rs +++ b/winit-core/src/event_loop/run_on_demand.rs @@ -32,13 +32,7 @@ pub trait EventLoopExtRunOnDemand { /// # Caveats /// - This extension isn't available on all platforms, since it's not always possible to return /// to the caller (specifically this is impossible on iOS and Web - though with the Web - /// backend it is possible to use - #[cfg_attr( - web_platform, - doc = " [`EventLoopExtWeb::spawn_app()`][crate::platform::web::EventLoopExtWeb::spawn_app()]" - )] - #[cfg_attr(not(web_platform), doc = " `EventLoopExtWeb::spawn_app()`")] - /// [^1] more than once instead). + /// backend it is possible to use `EventLoopExtWeb::spawn_app()`[^1] more than once instead). /// - No [`Window`] state can be carried between separate runs of the event loop. /// /// You are strongly encouraged to use [`EventLoop::run_app()`] for portability, unless you diff --git a/winit-core/src/keyboard.rs b/winit-core/src/keyboard.rs index 156a32d4ad..22fbe29480 100644 --- a/winit-core/src/keyboard.rs +++ b/winit-core/src/keyboard.rs @@ -1560,9 +1560,9 @@ impl NamedKey { /// # Examples /// /// ``` - /// # #[cfg(web_platform)] + /// # #[cfg(target_family = "wasm")] /// # wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); - /// # #[cfg_attr(web_platform, wasm_bindgen_test::wasm_bindgen_test)] + /// # #[cfg_attr(target_family = "wasm", wasm_bindgen_test::wasm_bindgen_test)] /// # fn main() { /// use winit_core::keyboard::NamedKey; /// @@ -1587,9 +1587,9 @@ impl Key { /// # Examples /// /// ``` - /// # #[cfg(web_platform)] + /// # #[cfg(target_family = "wasm")] /// # wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); - /// # #[cfg_attr(web_platform, wasm_bindgen_test::wasm_bindgen_test)] + /// # #[cfg_attr(target_family = "wasm", wasm_bindgen_test::wasm_bindgen_test)] /// # fn main() { /// use winit_core::keyboard::{Key, NamedKey}; /// diff --git a/winit-core/src/lib.rs b/winit-core/src/lib.rs index 358f0c3a6f..89bc682164 100644 --- a/winit-core/src/lib.rs +++ b/winit-core/src/lib.rs @@ -19,3 +19,11 @@ pub mod icon; pub mod keyboard; pub mod monitor; pub mod window; + +// `Instant` is not actually available on `wasm32-unknown-unknown`, the `std` implementation there +// is a stub. And `wasm32-none` doesn't even have `std`. Instead, we use `web_time::Instant`. +#[cfg(not(all(target_family = "wasm", any(target_os = "unknown", target_os = "none"))))] +pub(crate) use std::time::Instant; + +#[cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))] +pub(crate) use web_time::Instant;