From 872d0f759918ab8626892cc46a99c62cc92b9b4a Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 29 Jul 2024 09:42:53 +0200 Subject: [PATCH 1/3] game_activity/ffi: Drop cfg for inexistant `target_arch = "armv7"` [Rust 1.80 from July 25th 2024] points out that `armv7` is not a known, valid value for the `target_arch` cfg variable. This is confirmed by the docs not listing it either: https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch Hence drop this entirely, and rely purely on `target_arch = "arm"`. [Rust 1.80 from July 25th 2024]: https://blog.rust-lang.org/2024/07/25/Rust-1.80.0.html --- android-activity/src/game_activity/ffi.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/android-activity/src/game_activity/ffi.rs b/android-activity/src/game_activity/ffi.rs index e3c561d..e8be24c 100644 --- a/android-activity/src/game_activity/ffi.rs +++ b/android-activity/src/game_activity/ffi.rs @@ -16,10 +16,7 @@ use jni_sys::*; use libc::{pthread_cond_t, pthread_mutex_t, pthread_t}; use ndk_sys::{AAssetManager, AConfiguration, ALooper, ALooper_callbackFunc, ANativeWindow, ARect}; -#[cfg(all( - any(target_os = "android", feature = "test"), - any(target_arch = "arm", target_arch = "armv7") -))] +#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "arm"))] include!("ffi_arm.rs"); #[cfg(all(any(target_os = "android", feature = "test"), target_arch = "aarch64"))] From 2ac3a7bb99ef7ab9ccb7f651be657871b70118f8 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 29 Jul 2024 09:51:52 +0200 Subject: [PATCH 2/3] Fix `unexpected-cfgs` by adding `api-level-30` feature and removing `test` Some code copied from the NDK carried over the respective `feature` `cfg` guards, without ever adding the feature to the `[features]` list in `Cargo.toml`. Now that Rust detects these mishaps, we can fix it by removing `test` (bindings don't seem to be run-tested) and reexpose `ConfigurationRef::screen_round()` which was behind a previously unsettable `feature = "api-level-30"`. Also remove `unsafe impl Send/Sync for ConfigurationRef` since the upstream `ndk` already declares `Configuration` to be `Send` and `Sync`, and `RwLock` and `Arc` carry that through. --- android-activity/Cargo.toml | 1 + android-activity/src/config.rs | 2 -- android-activity/src/game_activity/ffi.rs | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/android-activity/Cargo.toml b/android-activity/Cargo.toml index 59b0b54..c05ad3f 100644 --- a/android-activity/Cargo.toml +++ b/android-activity/Cargo.toml @@ -27,6 +27,7 @@ rust-version = "1.69.0" default = [] game-activity = [] native-activity = [] +api-level-30 = ["ndk/api-level-30"] [dependencies] log = "0.4" diff --git a/android-activity/src/config.rs b/android-activity/src/config.rs index 7d818ec..2c3dce8 100644 --- a/android-activity/src/config.rs +++ b/android-activity/src/config.rs @@ -28,8 +28,6 @@ impl PartialEq for ConfigurationRef { } } impl Eq for ConfigurationRef {} -unsafe impl Send for ConfigurationRef {} -unsafe impl Sync for ConfigurationRef {} impl fmt::Debug for ConfigurationRef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/android-activity/src/game_activity/ffi.rs b/android-activity/src/game_activity/ffi.rs index e8be24c..51063ff 100644 --- a/android-activity/src/game_activity/ffi.rs +++ b/android-activity/src/game_activity/ffi.rs @@ -16,14 +16,14 @@ use jni_sys::*; use libc::{pthread_cond_t, pthread_mutex_t, pthread_t}; use ndk_sys::{AAssetManager, AConfiguration, ALooper, ALooper_callbackFunc, ANativeWindow, ARect}; -#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "arm"))] +#[cfg(all(any(target_os = "android"), target_arch = "arm"))] include!("ffi_arm.rs"); -#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "aarch64"))] +#[cfg(all(any(target_os = "android"), target_arch = "aarch64"))] include!("ffi_aarch64.rs"); -#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "x86"))] +#[cfg(all(any(target_os = "android"), target_arch = "x86"))] include!("ffi_i686.rs"); -#[cfg(all(any(target_os = "android", feature = "test"), target_arch = "x86_64"))] +#[cfg(all(any(target_os = "android"), target_arch = "x86_64"))] include!("ffi_x86_64.rs"); From 0bf4a974b370559cc75fd1336bddf1d61e009b1a Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 29 Jul 2024 10:11:46 +0200 Subject: [PATCH 3/3] native_activity: Fix clippy lints around `NativeActivityGlue` not `SendSync` and unwritten `redraw_needed` field --- android-activity/src/config.rs | 9 +++------ android-activity/src/native_activity/glue.rs | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/android-activity/src/config.rs b/android-activity/src/config.rs index 2c3dce8..45bc5e4 100644 --- a/android-activity/src/config.rs +++ b/android-activity/src/config.rs @@ -6,13 +6,10 @@ use ndk::configuration::{ ScreenSize, Touchscreen, UiModeNight, UiModeType, }; -/// A (cheaply clonable) reference to this application's [`ndk::configuration::Configuration`] +/// A runtime-replacable reference to [`ndk::configuration::Configuration`]. /// -/// This provides a thread-safe way to access the latest configuration state for -/// an application without deeply copying the large [`ndk::configuration::Configuration`] struct. -/// -/// If the application is notified of configuration changes then those changes -/// will become visible via pre-existing configuration references. +/// If the application is notified of configuration changes then those changes will become visible +/// via pre-existing configuration references. #[derive(Clone)] pub struct ConfigurationRef { config: Arc>, diff --git a/android-activity/src/native_activity/glue.rs b/android-activity/src/native_activity/glue.rs index 2e4371c..dab3e29 100644 --- a/android-activity/src/native_activity/glue.rs +++ b/android-activity/src/native_activity/glue.rs @@ -81,12 +81,14 @@ pub struct WaitableNativeActivityState { pub cond: Condvar, } +// SAFETY: ndk::NativeActivity is also SendSync. +unsafe impl Send for WaitableNativeActivityState {} +unsafe impl Sync for WaitableNativeActivityState {} + #[derive(Debug, Clone)] pub struct NativeActivityGlue { pub inner: Arc, } -unsafe impl Send for NativeActivityGlue {} -unsafe impl Sync for NativeActivityGlue {} impl Deref for NativeActivityGlue { type Target = WaitableNativeActivityState; @@ -223,7 +225,6 @@ pub struct NativeActivityState { /// Set as soon as the Java main thread notifies us of an /// `onDestroyed` callback. pub destroyed: bool, - pub redraw_needed: bool, pub pending_input_queue: *mut ndk_sys::AInputQueue, pub pending_window: Option, } @@ -370,7 +371,6 @@ impl WaitableNativeActivityState { thread_state: NativeThreadState::Init, app_has_saved_state: false, destroyed: false, - redraw_needed: false, pending_input_queue: ptr::null_mut(), pending_window: None, }),