Skip to content

Commit 546b829

Browse files
lucasmerlin486c
authored andcommitted
Fix iOS build, and add iOS step to CI (emilk#4898)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> This PR - adds a pipeline to check the ios build - removes the iOS WaitUntil workaround, which doesn't seem to be necessary anymore after the winit update (and caused the build for iOS to fail again because of a missing self - ~removes a iOS workaround for window size which doesn't seem necessary anymore~ Turns out it was still needed (but you need to actually restart the app for the issue to show up, so I didn't catch it first) - fixes some cargo check errors in run.rs I've done all these changes in a single PR because otherwise the pipeline doesn't run but I can also split them in separate PRs if that makes it easier to review
1 parent 1867293 commit 546b829

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

.github/workflows/rust.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
on: [push, pull_request]
1+
on: [ push, pull_request ]
22

33
name: Rust
44

@@ -167,6 +167,26 @@ jobs:
167167

168168
# ---------------------------------------------------------------------------
169169

170+
ios:
171+
name: ios
172+
runs-on: ubuntu-22.04
173+
steps:
174+
- uses: actions/checkout@v4
175+
176+
- uses: dtolnay/rust-toolchain@master
177+
with:
178+
toolchain: 1.76.0
179+
targets: aarch64-apple-ios
180+
181+
- name: Set up cargo cache
182+
uses: Swatinem/rust-cache@v2
183+
184+
# Default features are disabled because glutin doesn't compile for ios.
185+
- run: cargo check --features wgpu --target aarch64-apple-ios --no-default-features
186+
working-directory: crates/eframe
187+
188+
# ---------------------------------------------------------------------------
189+
170190
windows:
171191
name: Check Windows
172192
runs-on: windows-latest

crates/eframe/src/native/epi_integration.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use winit::event_loop::ActiveEventLoop;
77

88
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};
99

10-
use egui::{DeferredViewportUiCallback, NumExt as _, ViewportBuilder, ViewportId};
10+
use egui::{DeferredViewportUiCallback, ViewportBuilder, ViewportId};
1111
use egui_winit::{EventResponse, WindowSettings};
1212

1313
use crate::epi;
1414

15+
#[cfg_attr(target_os = "ios", allow(dead_code, unused_variables, unused_mut))]
1516
pub fn viewport_builder(
1617
egui_zoom_factor: f32,
1718
event_loop: &ActiveEventLoop,
@@ -53,8 +54,10 @@ pub fn viewport_builder(
5354

5455
if clamp_size_to_monitor_size {
5556
if let Some(initial_window_size) = viewport_builder.inner_size {
56-
let initial_window_size = initial_window_size
57-
.at_most(largest_monitor_point_size(egui_zoom_factor, event_loop));
57+
let initial_window_size = egui::NumExt::at_most(
58+
initial_window_size,
59+
largest_monitor_point_size(egui_zoom_factor, event_loop),
60+
);
5861
viewport_builder = viewport_builder.with_inner_size(initial_window_size);
5962
}
6063
}
@@ -95,6 +98,7 @@ pub fn apply_window_settings(
9598
}
9699
}
97100

101+
#[cfg(not(target_os = "ios"))]
98102
fn largest_monitor_point_size(egui_zoom_factor: f32, event_loop: &ActiveEventLoop) -> egui::Vec2 {
99103
crate::profile_function!();
100104

crates/eframe/src/native/run.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{cell::RefCell, time::Instant};
1+
use std::time::Instant;
22

33
use winit::{
44
application::ApplicationHandler,
@@ -32,11 +32,12 @@ fn create_event_loop(native_options: &mut epi::NativeOptions) -> Result<EventLoo
3232
///
3333
/// We reuse the event-loop so we can support closing and opening an eframe window
3434
/// multiple times. This is just a limitation of winit.
35+
#[cfg(not(target_os = "ios"))]
3536
fn with_event_loop<R>(
3637
mut native_options: epi::NativeOptions,
3738
f: impl FnOnce(&mut EventLoop<UserEvent>, epi::NativeOptions) -> R,
3839
) -> Result<R> {
39-
thread_local!(static EVENT_LOOP: RefCell<Option<EventLoop<UserEvent>>> = RefCell::new(None));
40+
thread_local!(static EVENT_LOOP: std::cell::RefCell<Option<EventLoop<UserEvent>>> = std::cell::RefCell::new(None));
4041

4142
EVENT_LOOP.with(|event_loop| {
4243
// Since we want to reference NativeOptions when creating the EventLoop we can't
@@ -174,16 +175,6 @@ impl<T: WinitApp> WinitAppWrapper<T> {
174175
});
175176

176177
if let Some(next_repaint_time) = next_repaint_time {
177-
// WaitUntil seems to not work on iOS
178-
#[cfg(target_os = "ios")]
179-
winit_app
180-
.window_id_from_viewport_id(egui::ViewportId::ROOT)
181-
.map(|window_id| {
182-
winit_app
183-
.window(window_id)
184-
.map(|window| window.request_redraw())
185-
});
186-
187178
event_loop.set_control_flow(ControlFlow::WaitUntil(next_repaint_time));
188179
};
189180
}

0 commit comments

Comments
 (0)