Skip to content

Commit 478427b

Browse files
authored
Remove the need for cfg_aliases in winit-core (#4271)
1 parent b0f26c7 commit 478427b

File tree

7 files changed

+18
-34
lines changed

7 files changed

+18
-34
lines changed

winit-core/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ rwh_06.workspace = true
2323
serde = { workspace = true, optional = true }
2424
smol_str.workspace = true
2525

26-
[target.'cfg(target_family = "wasm")'.dependencies]
26+
# `wasm32-unknown-unknown` and `wasm32-none`, but not `wasm32-wasi`.
27+
[target.'cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))'.dependencies]
2728
web-time.workspace = true
2829

29-
[build-dependencies]
30-
cfg_aliases.workspace = true
31-
3230
[dev-dependencies]
3331
winit.workspace = true

winit-core/build.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

winit-core/src/event.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
//! The event enums and assorted supporting types.
22
use std::path::PathBuf;
33
use std::sync::{Mutex, Weak};
4-
#[cfg(not(web_platform))]
5-
use std::time::Instant;
64

75
use dpi::{PhysicalPosition, PhysicalSize};
86
#[cfg(feature = "serde")]
97
use serde::{Deserialize, Serialize};
108
use smol_str::SmolStr;
11-
#[cfg(web_platform)]
12-
use web_time::Instant;
139

1410
use crate::error::RequestError;
1511
use crate::event_loop::AsyncRequestSerial;
1612
use crate::keyboard::{self, ModifiersKeyState, ModifiersKeys, ModifiersState};
1713
#[cfg(doc)]
1814
use crate::window::Window;
1915
use crate::window::{ActivationToken, Theme};
16+
use crate::Instant;
2017

2118
/// Describes the reason the event loop is resuming.
2219
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

winit-core/src/event_loop/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ pub mod run_on_demand;
44
use std::fmt::{self, Debug};
55
use std::sync::atomic::{AtomicUsize, Ordering};
66
use std::sync::Arc;
7-
#[cfg(not(web_platform))]
8-
use std::time::{Duration, Instant};
7+
use std::time::Duration;
98

109
use rwh_06::{DisplayHandle, HandleError, HasDisplayHandle};
11-
#[cfg(web_platform)]
12-
use web_time::{Duration, Instant};
1310

1411
use crate::as_any::AsAny;
1512
use crate::cursor::{CustomCursor, CustomCursorSource};
1613
use crate::error::RequestError;
1714
use crate::monitor::MonitorHandle;
1815
use crate::window::{Theme, Window, WindowAttributes};
16+
use crate::Instant;
1917

2018
pub trait ActiveEventLoop: AsAny + fmt::Debug {
2119
/// Creates an [`EventLoopProxy`] that can be used to dispatch user events

winit-core/src/event_loop/run_on_demand.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ pub trait EventLoopExtRunOnDemand {
3232
/// # Caveats
3333
/// - This extension isn't available on all platforms, since it's not always possible to return
3434
/// to the caller (specifically this is impossible on iOS and Web - though with the Web
35-
/// backend it is possible to use
36-
#[cfg_attr(
37-
web_platform,
38-
doc = " [`EventLoopExtWeb::spawn_app()`][crate::platform::web::EventLoopExtWeb::spawn_app()]"
39-
)]
40-
#[cfg_attr(not(web_platform), doc = " `EventLoopExtWeb::spawn_app()`")]
41-
/// [^1] more than once instead).
35+
/// backend it is possible to use `EventLoopExtWeb::spawn_app()`[^1] more than once instead).
4236
/// - No [`Window`] state can be carried between separate runs of the event loop.
4337
///
4438
/// You are strongly encouraged to use [`EventLoop::run_app()`] for portability, unless you

winit-core/src/keyboard.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,9 +1560,9 @@ impl NamedKey {
15601560
/// # Examples
15611561
///
15621562
/// ```
1563-
/// # #[cfg(web_platform)]
1563+
/// # #[cfg(target_family = "wasm")]
15641564
/// # wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
1565-
/// # #[cfg_attr(web_platform, wasm_bindgen_test::wasm_bindgen_test)]
1565+
/// # #[cfg_attr(target_family = "wasm", wasm_bindgen_test::wasm_bindgen_test)]
15661566
/// # fn main() {
15671567
/// use winit_core::keyboard::NamedKey;
15681568
///
@@ -1587,9 +1587,9 @@ impl Key {
15871587
/// # Examples
15881588
///
15891589
/// ```
1590-
/// # #[cfg(web_platform)]
1590+
/// # #[cfg(target_family = "wasm")]
15911591
/// # wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
1592-
/// # #[cfg_attr(web_platform, wasm_bindgen_test::wasm_bindgen_test)]
1592+
/// # #[cfg_attr(target_family = "wasm", wasm_bindgen_test::wasm_bindgen_test)]
15931593
/// # fn main() {
15941594
/// use winit_core::keyboard::{Key, NamedKey};
15951595
///

winit-core/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ pub mod icon;
1919
pub mod keyboard;
2020
pub mod monitor;
2121
pub mod window;
22+
23+
// `Instant` is not actually available on `wasm32-unknown-unknown`, the `std` implementation there
24+
// is a stub. And `wasm32-none` doesn't even have `std`. Instead, we use `web_time::Instant`.
25+
#[cfg(not(all(target_family = "wasm", any(target_os = "unknown", target_os = "none"))))]
26+
pub(crate) use std::time::Instant;
27+
28+
#[cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))]
29+
pub(crate) use web_time::Instant;

0 commit comments

Comments
 (0)