Bump MSRV to v1.73 (#3743)
This commit is contained in:
parent
d8ffd4bb26
commit
1552eb21f7
7 changed files with 32 additions and 72 deletions
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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<T>() -> (Sender<T>, Receiver<T>) {
|
|||
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<T>(Arc<SenderInner<T>>);
|
||||
|
||||
struct SenderInner<T> {
|
||||
// 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<mpsc::Sender<T>>,
|
||||
pub struct Sender<T> {
|
||||
sender: mpsc::Sender<T>,
|
||||
shared: Arc<Shared>,
|
||||
}
|
||||
|
||||
impl<T> Sender<T> {
|
||||
pub fn send(&self, event: T) -> Result<(), SendError<T>> {
|
||||
self.0.sender.lock().unwrap().send(event)?;
|
||||
self.0.shared.waker.wake();
|
||||
self.sender.send(event)?;
|
||||
self.shared.waker.wake();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SenderInner<T> {
|
||||
fn close(&self) {
|
||||
impl<T> Drop for Sender<T> {
|
||||
fn drop(&mut self) {
|
||||
self.shared.closed.store(true, Ordering::Relaxed);
|
||||
self.shared.waker.wake();
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Sender<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(Arc::clone(&self.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for SenderInner<T> {
|
||||
fn drop(&mut self) {
|
||||
self.close();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Receiver<T> {
|
||||
receiver: Rc<mpsc::Receiver<T>>,
|
||||
receiver: mpsc::Receiver<T>,
|
||||
shared: Arc<Shared>,
|
||||
}
|
||||
|
||||
|
|
@ -95,18 +75,6 @@ impl<T> Receiver<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Receiver<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self { receiver: Rc::clone(&self.receiver), shared: Arc::clone(&self.shared) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for Receiver<T> {
|
||||
fn drop(&mut self) {
|
||||
self.shared.closed.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
struct Shared {
|
||||
closed: AtomicBool,
|
||||
waker: AtomicWaker,
|
||||
|
|
|
|||
|
|
@ -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<T: 'static>(Wrapper<T, Sender<Closure<T>>, Closure<T>>);
|
||||
pub struct Dispatcher<T: 'static>(Wrapper<T, Arc<Sender<Closure<T>>>, Closure<T>>);
|
||||
|
||||
struct Closure<T>(Box<dyn FnOnce(&T) + Send>);
|
||||
|
||||
|
|
@ -11,6 +12,8 @@ impl<T> Dispatcher<T> {
|
|||
#[track_caller]
|
||||
pub fn new(main_thread: MainThreadMarker, value: T) -> Option<(Self, DispatchRunner<T>)> {
|
||||
let (sender, receiver) = channel::<Closure<T>>();
|
||||
let sender = Arc::new(sender);
|
||||
let receiver = Rc::new(receiver);
|
||||
|
||||
Wrapper::new(
|
||||
main_thread,
|
||||
|
|
@ -21,7 +24,7 @@ impl<T> Dispatcher<T> {
|
|||
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<T> Dispatcher<T> {
|
|||
}
|
||||
|
||||
pub struct DispatchRunner<T: 'static> {
|
||||
wrapper: Wrapper<T, Sender<Closure<T>>, Closure<T>>,
|
||||
receiver: Receiver<Closure<T>>,
|
||||
wrapper: Wrapper<T, Arc<Sender<Closure<T>>>, Closure<T>>,
|
||||
receiver: Rc<Receiver<Closure<T>>>,
|
||||
}
|
||||
|
||||
impl<T> DispatchRunner<T> {
|
||||
|
|
|
|||
|
|
@ -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 <https://doc.rust-lang.org/1.73.0/src/core/num/uint_macros.rs.html#2086-2094>.
|
||||
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<bool> = const { OnceCell::new() };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue