diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecf78fcf..f9f43a94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: strategy: fail-fast: false matrix: - toolchain: [stable, nightly, '1.70.0'] + toolchain: [stable, nightly, '1.73'] platform: # Note: Make sure that we test all the `docs.rs` targets defined in Cargo.toml! - { name: 'Windows 64bit MSVC', target: x86_64-pc-windows-msvc, os: windows-latest, } @@ -61,10 +61,10 @@ jobs: - { name: 'web', target: wasm32-unknown-unknown, os: ubuntu-latest, } exclude: # Android is tested on stable-3 - - toolchain: '1.70.0' + - toolchain: '1.73' platform: { name: 'Android', target: aarch64-linux-android, os: ubuntu-latest, options: '--package=winit --features=android-native-activity', cmd: 'apk --' } include: - - toolchain: '1.70.0' + - toolchain: '1.73' platform: { name: 'Android', target: aarch64-linux-android, os: ubuntu-latest, options: '--package=winit --features=android-native-activity', cmd: 'apk --' } - toolchain: 'nightly' platform: { @@ -149,13 +149,13 @@ jobs: - name: Test dpi crate if: > contains(matrix.platform.name, 'Linux 64bit') && - matrix.toolchain != '1.70.0' + matrix.toolchain != '1.73' run: cargo test -p dpi - name: Build tests if: > !contains(matrix.platform.target, 'redox') && - matrix.toolchain != '1.70.0' + matrix.toolchain != '1.73' run: cargo $CMD test --no-run $OPTIONS - name: Run tests @@ -164,7 +164,7 @@ jobs: !contains(matrix.platform.target, 'ios') && !contains(matrix.platform.target, 'wasm32') && !contains(matrix.platform.target, 'redox') && - matrix.toolchain != '1.70.0' + matrix.toolchain != '1.73' run: cargo $CMD test $OPTIONS - name: Lint with clippy @@ -174,7 +174,7 @@ jobs: - name: Build tests with serde enabled if: > !contains(matrix.platform.target, 'redox') && - matrix.toolchain != '1.70.0' + matrix.toolchain != '1.73' run: cargo $CMD test --no-run $OPTIONS --features serde - name: Run tests with serde enabled @@ -183,7 +183,7 @@ jobs: !contains(matrix.platform.target, 'ios') && !contains(matrix.platform.target, 'wasm32') && !contains(matrix.platform.target, 'redox') && - matrix.toolchain != '1.70.0' + matrix.toolchain != '1.73' run: cargo $CMD test $OPTIONS --features serde - name: Check docs.rs documentation diff --git a/Cargo.toml b/Cargo.toml index 97b8924a..0dbd6c65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -346,7 +346,7 @@ resolver = "2" members = ["dpi"] [workspace.package] -rust-version = "1.70.0" +rust-version = "1.73" repository = "https://github.com/rust-windowing/winit" license = "Apache-2.0" edition = "2021" diff --git a/README.md b/README.md index 0b4af6e4..67c044c0 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ another library. ## MSRV Policy -This crate's Minimum Supported Rust Version (MSRV) is **1.70**. Changes to +This crate's Minimum Supported Rust Version (MSRV) is **1.73**. Changes to the MSRV will be accompanied by a minor version bump. As a **tentative** policy, the upper bound of the MSRV is given by the following diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index a0ac5e70..a86879a0 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -44,6 +44,7 @@ changelog entry. - On Web, let events wake up event loop immediately when using `ControlFlow::Poll`. +- Bump MSRV from `1.70` to `1.73`. ### Removed diff --git a/src/platform_impl/web/async/channel.rs b/src/platform_impl/web/async/channel.rs index 42401a28..380b7cb8 100644 --- a/src/platform_impl/web/async/channel.rs +++ b/src/platform_impl/web/async/channel.rs @@ -1,8 +1,7 @@ use std::future; -use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{self, RecvError, SendError, TryRecvError}; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use std::task::Poll; use super::AtomicWaker; @@ -11,54 +10,35 @@ pub fn channel() -> (Sender, Receiver) { let (sender, receiver) = mpsc::channel(); let shared = Arc::new(Shared { closed: AtomicBool::new(false), waker: AtomicWaker::new() }); - let sender = - Sender(Arc::new(SenderInner { sender: Mutex::new(sender), shared: Arc::clone(&shared) })); - let receiver = Receiver { receiver: Rc::new(receiver), shared }; + let sender = Sender { sender, shared: Arc::clone(&shared) }; + let receiver = Receiver { receiver, shared }; (sender, receiver) } -pub struct Sender(Arc>); - -struct SenderInner { - // We need to wrap it into a `Mutex` to make it `Sync`. So the sender can't - // be accessed on the main thread, as it could block. Additionally we need - // to wrap `Sender` in an `Arc` to make it clonable on the main thread without - // having to block. - sender: Mutex>, +pub struct Sender { + sender: mpsc::Sender, shared: Arc, } impl Sender { pub fn send(&self, event: T) -> Result<(), SendError> { - self.0.sender.lock().unwrap().send(event)?; - self.0.shared.waker.wake(); + self.sender.send(event)?; + self.shared.waker.wake(); Ok(()) } } -impl SenderInner { - fn close(&self) { +impl Drop for Sender { + fn drop(&mut self) { self.shared.closed.store(true, Ordering::Relaxed); self.shared.waker.wake(); } } -impl Clone for Sender { - fn clone(&self) -> Self { - Self(Arc::clone(&self.0)) - } -} - -impl Drop for SenderInner { - fn drop(&mut self) { - self.close(); - } -} - pub struct Receiver { - receiver: Rc>, + receiver: mpsc::Receiver, shared: Arc, } @@ -95,18 +75,6 @@ impl Receiver { } } -impl Clone for Receiver { - fn clone(&self) -> Self { - Self { receiver: Rc::clone(&self.receiver), shared: Arc::clone(&self.shared) } - } -} - -impl Drop for Receiver { - fn drop(&mut self) { - self.shared.closed.store(true, Ordering::Relaxed); - } -} - struct Shared { closed: AtomicBool, waker: AtomicWaker, diff --git a/src/platform_impl/web/async/dispatcher.rs b/src/platform_impl/web/async/dispatcher.rs index 10ab345e..dffb04e9 100644 --- a/src/platform_impl/web/async/dispatcher.rs +++ b/src/platform_impl/web/async/dispatcher.rs @@ -1,9 +1,10 @@ use super::super::main_thread::MainThreadMarker; use super::{channel, Receiver, Sender, Wrapper}; use std::cell::Ref; +use std::rc::Rc; use std::sync::{Arc, Condvar, Mutex}; -pub struct Dispatcher(Wrapper>, Closure>); +pub struct Dispatcher(Wrapper>>, Closure>); struct Closure(Box); @@ -11,6 +12,8 @@ impl Dispatcher { #[track_caller] pub fn new(main_thread: MainThreadMarker, value: T) -> Option<(Self, DispatchRunner)> { let (sender, receiver) = channel::>(); + let sender = Arc::new(sender); + let receiver = Rc::new(receiver); Wrapper::new( main_thread, @@ -21,7 +24,7 @@ impl Dispatcher { closure(value.borrow().as_ref().unwrap()) }, { - let receiver = receiver.clone(); + let receiver = Rc::clone(&receiver); move |value| async move { while let Ok(Closure(closure)) = receiver.next().await { // SAFETY: The given `Closure` here isn't really `'static`, so we shouldn't @@ -89,8 +92,8 @@ impl Dispatcher { } pub struct DispatchRunner { - wrapper: Wrapper>, Closure>, - receiver: Receiver>, + wrapper: Wrapper>>, Closure>, + receiver: Rc>>, } impl DispatchRunner { diff --git a/src/platform_impl/web/web_sys/schedule.rs b/src/platform_impl/web/web_sys/schedule.rs index c8b82b2e..a2ef874d 100644 --- a/src/platform_impl/web/web_sys/schedule.rs +++ b/src/platform_impl/web/web_sys/schedule.rs @@ -74,7 +74,7 @@ impl Schedule { let duration = duration .as_secs() .checked_mul(1000) - .and_then(|secs| secs.checked_add(duration_millis_ceil(duration).into())) + .and_then(|secs| secs.checked_add(duration.subsec_micros().div_ceil(1000).into())) .unwrap_or(u64::MAX); options.delay(duration as f64); @@ -127,7 +127,9 @@ impl Schedule { .ok() .and_then(|secs: i32| secs.checked_mul(1000)) .and_then(|secs: i32| { - let millis: i32 = duration_millis_ceil(duration) + let millis: i32 = duration + .subsec_micros() + .div_ceil(1000) .try_into() .expect("millis are somehow bigger then 1K"); secs.checked_add(millis) @@ -169,20 +171,6 @@ impl Drop for Schedule { } } -// TODO: Replace with `u32::div_ceil()` when we hit Rust v1.73. -fn duration_millis_ceil(duration: Duration) -> u32 { - let micros = duration.subsec_micros(); - - // From . - let d = micros / 1000; - let r = micros % 1000; - if r > 0 && 1000 > 0 { - d + 1 - } else { - d - } -} - fn has_scheduler_support(window: &web_sys::Window) -> bool { thread_local! { static SCHEDULER_SUPPORT: OnceCell = const { OnceCell::new() };