From 48e7f219a3aaa43084d042590b2871c01415e642 Mon Sep 17 00:00:00 2001 From: Zoxc Date: Mon, 15 Aug 2022 10:19:59 +0200 Subject: [PATCH] Add CI for android (#1900) * Add CI for android * Don't use arboard on Android * Fix Android support for eframe --- .github/workflows/rust.yml | 15 +++++++++++++++ eframe/src/native/run.rs | 16 +++++++++------- egui-winit/Cargo.toml | 4 +++- egui-winit/src/clipboard.rs | 10 +++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5cd5070a..5be2cc79 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -195,3 +195,18 @@ jobs: - run: rustup target add wasm32-unknown-unknown - run: ./sh/setup_web.sh - run: ./sh/wasm_bindgen_check.sh + + android: + name: android + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: 1.61.0 + target: aarch64-linux-android + override: true + + - run: cargo check --features wgpu --target aarch64-linux-android + working-directory: eframe diff --git a/eframe/src/native/run.rs b/eframe/src/native/run.rs index a0b730f2..b67271a6 100644 --- a/eframe/src/native/run.rs +++ b/eframe/src/native/run.rs @@ -468,7 +468,7 @@ mod wgpu_integration { .unwrap(); // SAFETY: `window` must outlive `painter`. - #[allow(unsafe_code)] + #[allow(unsafe_code, unused_mut, unused_unsafe)] let painter = unsafe { let mut painter = egui_wgpu::winit::Painter::new( wgpu::Backends::PRIMARY | wgpu::Backends::GL, @@ -486,7 +486,7 @@ mod wgpu_integration { painter }; - let wgpu_render_state = painter.render_state().expect("Uninitialized"); + let wgpu_render_state = painter.render_state(); let system_theme = native_options.system_theme(); let mut integration = epi_integration::EpiIntegration::new( @@ -497,7 +497,7 @@ mod wgpu_integration { storage, #[cfg(feature = "glow")] None, - Some(wgpu_render_state.clone()), + wgpu_render_state.clone(), ); let theme = system_theme.unwrap_or(native_options.default_theme); integration.egui_ctx.set_visuals(theme.egui_visuals()); @@ -515,7 +515,7 @@ mod wgpu_integration { storage: integration.frame.storage(), #[cfg(feature = "glow")] gl: None, - wgpu_render_state: Some(wgpu_render_state), + wgpu_render_state, }); if app.warm_up_enabled() { @@ -629,11 +629,13 @@ mod wgpu_integration { match event { #[cfg(target_os = "android")] winit::event::Event::Resumed => unsafe { - painter.set_window(Some(&window)); + self.painter.set_window(Some(&self.window)); + EventResult::RepaintAsap }, #[cfg(target_os = "android")] - winit::event::Event::Paused => unsafe { - painter.set_window(None); + winit::event::Event::Suspended => unsafe { + self.painter.set_window(None); + EventResult::Wait }, winit::event::Event::WindowEvent { event, .. } => { diff --git a/egui-winit/Cargo.toml b/egui-winit/Cargo.toml index 95247e5c..b1e1d75d 100644 --- a/egui-winit/Cargo.toml +++ b/egui-winit/Cargo.toml @@ -49,7 +49,6 @@ tracing = { version = "0.1", default-features = false, features = ["std"] } winit = "0.27.2" #! ### Optional dependencies -arboard = { version = "2.1", optional = true, default-features = false } ## Enable this when generating docs. document-features = { version = "0.2", optional = true } @@ -64,3 +63,6 @@ webbrowser = { version = "0.7", optional = true } [target.'cfg(any(target_os="linux", target_os="dragonfly", target_os="freebsd", target_os="netbsd", target_os="openbsd"))'.dependencies] smithay-clipboard = { version = "0.6.3", optional = true } + +[target.'cfg(not(target_os = "android"))'.dependencies] +arboard = { version = "2.1", optional = true, default-features = false } diff --git a/egui-winit/src/clipboard.rs b/egui-winit/src/clipboard.rs index ef11b12f..576a78e5 100644 --- a/egui-winit/src/clipboard.rs +++ b/egui-winit/src/clipboard.rs @@ -5,7 +5,7 @@ use std::os::raw::c_void; /// If the "clipboard" feature is off, or we cannot connect to the OS clipboard, /// then a fallback clipboard that just works works within the same app is used instead. pub struct Clipboard { - #[cfg(feature = "arboard")] + #[cfg(all(feature = "arboard", not(target_os = "android")))] arboard: Option, #[cfg(all( @@ -28,7 +28,7 @@ impl Clipboard { #[allow(unused_variables)] pub fn new(#[allow(unused_variables)] wayland_display: Option<*mut c_void>) -> Self { Self { - #[cfg(feature = "arboard")] + #[cfg(all(feature = "arboard", not(target_os = "android")))] arboard: init_arboard(), #[cfg(all( any( @@ -66,7 +66,7 @@ impl Clipboard { }; } - #[cfg(feature = "arboard")] + #[cfg(all(feature = "arboard", not(target_os = "android")))] if let Some(clipboard) = &mut self.arboard { return match clipboard.get_text() { Ok(text) => Some(text), @@ -96,7 +96,7 @@ impl Clipboard { return; } - #[cfg(feature = "arboard")] + #[cfg(all(feature = "arboard", not(target_os = "android")))] if let Some(clipboard) = &mut self.arboard { if let Err(err) = clipboard.set_text(text) { tracing::error!("Copy/Cut error: {}", err); @@ -108,7 +108,7 @@ impl Clipboard { } } -#[cfg(feature = "arboard")] +#[cfg(all(feature = "arboard", not(target_os = "android")))] fn init_arboard() -> Option { match arboard::Clipboard::new() { Ok(clipboard) => Some(clipboard),