diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cbc87f..dc7f708 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,20 @@ jobs: steps: - uses: actions/checkout@v4 + # Downgrade all dependencies to their minimum version, both to ensure our + # minimum version bounds are correct and buildable, as well as to satisfy + # our MSRV check when arbitrary dependencies bump their MSRV beyond our + # MSRV in a patch-release. + # This implies that downstream consumers can only rely on our MSRV when + # downgrading various (transitive) dependencies. + - uses: hecrj/setup-rust-action@v2 + with: + rust-version: nightly + if: ${{ matrix.rust-version != 'stable' }} + - name: Downgrade dependencies + run: cargo +nightly generate-lockfile -Zminimal-versions + if: ${{ matrix.rust-version != 'stable' }} + - uses: hecrj/setup-rust-action@v2 with: rust-version: ${{ matrix.rust-version }} @@ -87,13 +101,6 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt - - name: Format run: cargo fmt --all -- --check working-directory: android-activity diff --git a/android-activity/Cargo.toml b/android-activity/Cargo.toml index 59b0b54..56e7aeb 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" @@ -35,15 +36,15 @@ cesu8 = "1" jni = "0.21" ndk-sys = "0.6.0" ndk = { version = "0.9.0", default-features = false } -ndk-context = "0.1" +ndk-context = "0.1.1" android-properties = "0.2" num_enum = "0.7" bitflags = "2.0" -libc = "0.2" +libc = "0.2.139" thiserror = "1" [build-dependencies] -cc = { version = "1.0", features = ["parallel"] } +cc = { version = "1.0.42", features = ["parallel"] } [package.metadata.docs.rs] targets = [ diff --git a/android-activity/src/config.rs b/android-activity/src/config.rs index 7d818ec..ab1bf1e 100644 --- a/android-activity/src/config.rs +++ b/android-activity/src/config.rs @@ -6,13 +6,14 @@ 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. +/// # Warning /// -/// If the application is notified of configuration changes then those changes -/// will become visible via pre-existing configuration references. +/// The value held by this reference **will change** with every [`super::MainEvent::ConfigChanged`] +/// event that is raised. You should **not** [`Clone`] this type to compare it against a +/// "new" [`super::AndroidApp::config()`] when that event is raised, since both point to the same +/// internal [`ndk::configuration::Configuration`] and will be identical. #[derive(Clone)] pub struct ConfigurationRef { config: Arc>, @@ -28,8 +29,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 e3c561d..51063ff 100644 --- a/android-activity/src/game_activity/ffi.rs +++ b/android-activity/src/game_activity/ffi.rs @@ -16,17 +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"), - any(target_arch = "arm", target_arch = "armv7") -))] +#[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"); diff --git a/android-activity/src/lib.rs b/android-activity/src/lib.rs index 6095108..45cc887 100644 --- a/android-activity/src/lib.rs +++ b/android-activity/src/lib.rs @@ -268,9 +268,9 @@ pub enum MainEvent<'a> { /// input focus. LostFocus, - /// Command from main thread: the current device configuration has changed. - /// You can get a copy of the latest [`ndk::configuration::Configuration`] by calling - /// [`AndroidApp::config()`] + /// Command from main thread: the current device configuration has changed. Any + /// reference gotten via [`AndroidApp::config()`] will automatically contain the latest + /// [`ndk::configuration::Configuration`]. #[non_exhaustive] ConfigChanged {}, @@ -617,7 +617,14 @@ impl AndroidApp { self.inner.read().unwrap().create_waker() } - /// Returns a (cheaply clonable) reference to this application's [`ndk::configuration::Configuration`] + /// Returns a **reference** to this application's [`ndk::configuration::Configuration`]. + /// + /// # Warning + /// + /// The value held by this reference **will change** with every [`MainEvent::ConfigChanged`] + /// event that is raised. You should **not** [`Clone`] this type to compare it against a + /// "new" [`AndroidApp::config()`] when that event is raised, since both point to the same + /// internal [`ndk::configuration::Configuration`] and will be identical. pub fn config(&self) -> ConfigurationRef { self.inner.read().unwrap().config() } 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, }),