Browse Source

Fix iOS build, and add iOS step to CI (#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
pull/5005/head
lucasmerlin 2 months ago
committed by GitHub
parent
commit
c9e00e50ad
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 22
      .github/workflows/rust.yml
  2. 10
      crates/eframe/src/native/epi_integration.rs
  3. 15
      crates/eframe/src/native/run.rs

22
.github/workflows/rust.yml

@ -1,4 +1,4 @@
on: [push, pull_request]
on: [ push, pull_request ]
name: Rust
@ -167,6 +167,26 @@ jobs:
# ---------------------------------------------------------------------------
ios:
name: ios
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.76.0
targets: aarch64-apple-ios
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
# Default features are disabled because glutin doesn't compile for ios.
- run: cargo check --features wgpu --target aarch64-apple-ios --no-default-features
working-directory: crates/eframe
# ---------------------------------------------------------------------------
windows:
name: Check Windows
runs-on: windows-latest

10
crates/eframe/src/native/epi_integration.rs

@ -7,11 +7,12 @@ use winit::event_loop::ActiveEventLoop;
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};
use egui::{DeferredViewportUiCallback, NumExt as _, ViewportBuilder, ViewportId};
use egui::{DeferredViewportUiCallback, ViewportBuilder, ViewportId};
use egui_winit::{EventResponse, WindowSettings};
use crate::epi;
#[cfg_attr(target_os = "ios", allow(dead_code, unused_variables, unused_mut))]
pub fn viewport_builder(
egui_zoom_factor: f32,
event_loop: &ActiveEventLoop,
@ -53,8 +54,10 @@ pub fn viewport_builder(
if clamp_size_to_monitor_size {
if let Some(initial_window_size) = viewport_builder.inner_size {
let initial_window_size = initial_window_size
.at_most(largest_monitor_point_size(egui_zoom_factor, event_loop));
let initial_window_size = egui::NumExt::at_most(
initial_window_size,
largest_monitor_point_size(egui_zoom_factor, event_loop),
);
viewport_builder = viewport_builder.with_inner_size(initial_window_size);
}
}
@ -95,6 +98,7 @@ pub fn apply_window_settings(
}
}
#[cfg(not(target_os = "ios"))]
fn largest_monitor_point_size(egui_zoom_factor: f32, event_loop: &ActiveEventLoop) -> egui::Vec2 {
crate::profile_function!();

15
crates/eframe/src/native/run.rs

@ -1,4 +1,4 @@
use std::{cell::RefCell, time::Instant};
use std::time::Instant;
use winit::{
application::ApplicationHandler,
@ -32,11 +32,12 @@ fn create_event_loop(native_options: &mut epi::NativeOptions) -> Result<EventLoo
///
/// We reuse the event-loop so we can support closing and opening an eframe window
/// multiple times. This is just a limitation of winit.
#[cfg(not(target_os = "ios"))]
fn with_event_loop<R>(
mut native_options: epi::NativeOptions,
f: impl FnOnce(&mut EventLoop<UserEvent>, epi::NativeOptions) -> R,
) -> Result<R> {
thread_local!(static EVENT_LOOP: RefCell<Option<EventLoop<UserEvent>>> = RefCell::new(None));
thread_local!(static EVENT_LOOP: std::cell::RefCell<Option<EventLoop<UserEvent>>> = std::cell::RefCell::new(None));
EVENT_LOOP.with(|event_loop| {
// Since we want to reference NativeOptions when creating the EventLoop we can't
@ -174,16 +175,6 @@ impl<T: WinitApp> WinitAppWrapper<T> {
});
if let Some(next_repaint_time) = next_repaint_time {
// WaitUntil seems to not work on iOS
#[cfg(target_os = "ios")]
winit_app
.window_id_from_viewport_id(egui::ViewportId::ROOT)
.map(|window_id| {
winit_app
.window(window_id)
.map(|window| window.request_redraw())
});
event_loop.set_control_flow(ControlFlow::WaitUntil(next_repaint_time));
};
}

Loading…
Cancel
Save