From 6570f0bf4090390a702d7592ed6eb414ed473498 Mon Sep 17 00:00:00 2001 From: Jack Spira Date: Sun, 5 Sep 2021 14:30:47 -0700 Subject: [PATCH] okay fixed our winit hell situation --- imgui-examples/Cargo.toml | 4 +-- imgui-winit-support/Cargo.toml | 4 +-- imgui-winit-support/UPDATING_WINIT.md | 8 ++++++ imgui-winit-support/src/lib.rs | 41 +++++++++++---------------- 4 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 imgui-winit-support/UPDATING_WINIT.md diff --git a/imgui-examples/Cargo.toml b/imgui-examples/Cargo.toml index 73bc789..40c00b7 100644 --- a/imgui-examples/Cargo.toml +++ b/imgui-examples/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "examples" +name = "imgui-examples" version = "0.0.0" edition = "2018" authors = ["The imgui-rs Developers"] @@ -11,7 +11,7 @@ publish = false [dev-dependencies] clipboard = "0.5" -glium = { version = "0.29", default-features = true } +glium = { version = "0.30", default-features = true } image = "0.23" imgui = { path = "../imgui" } imgui-glium-renderer = { path = "../imgui-glium-renderer" } diff --git a/imgui-winit-support/Cargo.toml b/imgui-winit-support/Cargo.toml index 5e255ab..c5a45bc 100644 --- a/imgui-winit-support/Cargo.toml +++ b/imgui-winit-support/Cargo.toml @@ -15,11 +15,11 @@ winit-19 = { version = ">= 0.16, < 0.20", package = "winit", optional = true } winit-20 = { version = ">= 0.20, < 0.22", package = "winit", optional = true } winit-22 = { version = "0.22", package = "winit", optional = true } winit-23 = { version = "0.23", package = "winit", optional = true } -winit-24 = { version = "0.24", package = "winit", optional = true } +winit-24 = { version = "=0.24", package = "winit", optional = true } winit-25 = { version = "0.25", package = "winit", optional = true } [features] -default = ["winit-24"] # TODO: Change to winit-25 when glutin has upgraded to it +default = ["winit-25"] # This is phrased as a negative (unlike most features) so that it needs to be # explicitly disabled (and `default-features = false` won't do it). To avoid diff --git a/imgui-winit-support/UPDATING_WINIT.md b/imgui-winit-support/UPDATING_WINIT.md new file mode 100644 index 0000000..9ff786d --- /dev/null +++ b/imgui-winit-support/UPDATING_WINIT.md @@ -0,0 +1,8 @@ +# Updating Winit + +Updating the default version of Winit is very annoying and error prone. We should make some automated way to do it so we don't have any issues in the future, but here is what needs to be done: + +1. Make sure that glutin is on the new version of Winit that you want to use. It's easier if our default winit version is on that new default. +2. Update the default in the Cargo.toml by simply changing the default guard. +3. At the top of lib.rs, edit the CFG guards which handle `use winit_x as winit;` such that the new default only relies on a positive feature guard (just copy the form used for the old default). If you don't do this, you'll get some particularly strange errors about two crates being used, since somehow the dependency resolver will pick a winit that the user didn't choose (and presumably won't use if it actually made it to compilation). +4. Profit?? diff --git a/imgui-winit-support/src/lib.rs b/imgui-winit-support/src/lib.rs index 8243862..e564f4c 100644 --- a/imgui-winit-support/src/lib.rs +++ b/imgui-winit-support/src/lib.rs @@ -79,10 +79,10 @@ //! //! The following versions are supported, controlled by the listed feature. //! -//! - The `winit-25` feature uses winit versions compatible with `0.25`. -//! - The `winit-24` feature supports winit versions `0.24`. This is +//! - The `winit-25` feature uses winit versions compatible with `0.25`. This is //! on by default, so to use any other version you need to disable this crates //! default features. +//! - The `winit-24` feature supports winit versions `0.24`. //! - The `winit-23` feature uses winit versions compatible with `0.23`. //! - The `winit-22` feature uses winit versions compatible with `0.22`. //! - The `winit-20` feature should support winit either `0.20` or winit `0.21`. @@ -95,7 +95,7 @@ //! feature, fixing the configuration, or disabling `debug_assertions`. //! //! Conversely, if no `winit-*` features are enabled, we will fail to compile. -//! This is not an issue generally, as by default we turn on `winit-24`. +//! This is not an issue generally, as by default we turn on `winit-25`. //! //! All of this is in attempt to preserve the additive nature of features (while //! still helping users notice project configuration issues), however it's done @@ -133,10 +133,10 @@ //! - Changing the default feature to the new latest `winit` version is *not* a //! breaking change. -#[cfg(all(not(feature = "winit-24"), feature = "winit-25"))] +#[cfg(feature = "winit-25")] use winit_25 as winit; -#[cfg(feature = "winit-24")] +#[cfg(all(not(feature = "winit-25"), feature = "winit-24"))] use winit_24 as winit; #[cfg(all( @@ -194,22 +194,6 @@ use winit::{ TouchPhase, VirtualKeyCode, Window, WindowEvent, }; -#[cfg(any( - feature = "winit-20", - feature = "winit-22", - feature = "winit-23", - feature = "winit-24", - feature = "winit-25" -))] -use winit::{ - error::ExternalError, - event::{ - DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase, - VirtualKeyCode, WindowEvent, - }, - window::{CursorIcon as MouseCursor, Window}, -}; - // Ensure at least one is enabled #[cfg(not(any( feature = "winit-19", @@ -221,6 +205,15 @@ use winit::{ )))] compile_error!("Please enable at least one version of `winit` (see documentation for details)."); +use winit::{ + error::ExternalError, + event::{ + DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase, + VirtualKeyCode, WindowEvent, + }, + window::{CursorIcon as MouseCursor, Window}, +}; + // FIXME(thom): make updading winit and adding a new feature less of a hassle here. fn check_multiple_winits() { use std::io::Write as _; @@ -258,8 +251,8 @@ fn check_multiple_winits() { (this likely indicates misconfiguration, see documentation for details)." ); let feats = [ - ("winit-25", cfg!(feature = "winit-25"), ""), - ("winit-24", cfg!(feature = "winit-24"), " (default)"), + ("winit-25", cfg!(feature = "winit-25"), " (default)"), + ("winit-24", cfg!(feature = "winit-24"), ""), ("winit-23", cfg!(feature = "winit-23"), ""), ("winit-22", cfg!(feature = "winit-22"), ""), ("winit-20", cfg!(feature = "winit-20"), ""), @@ -270,7 +263,7 @@ fn check_multiple_winits() { let _ = writeln!(err, " `feature = {:?}` is enabled{}", name, extra); } } - if cfg!(feature = "winit-24") && winits_enabled == 2 { + if cfg!(feature = "winit-25") && winits_enabled == 2 { let _ = writeln!( err, " Perhaps you are missing a `default-features = false`?",