Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various codebase rots (stale CI, new Rust lints, broken MSRV checks by transitive dependency upgrades) #164

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions android-activity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = [
Expand Down
13 changes: 6 additions & 7 deletions android-activity/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +13 to +16
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rib I don't have any alternative to propose to users to compare configurations besides calling the expensive fn copy() to make a deep-clone of ndk::configuration::Configuration which exactly defeats the purpose of initially making this "cheap to copy".

By having this an updatable RwLock rather than a simple Arc it is no longer possible to compare for configuration differences and prevent possibly expensive reconfiguration/updates in the users' loops. If this was "just an Arc" users could do exactly that while still "cloning" the configuration around cheaply.

In any case, every time the callback fires a new AConfiguration is allocated and filled anyway, rather than "reading into" the existing AConfiguration. But the docs at https://developer.android.com/ndk/reference/group/configuration#aconfiguration_fromassetmanager are incredibly vague by mentioning Create and return a new AConfiguration while it has to take an existing allocated (but possibly new/empty?) AConfiguration.

#[derive(Clone)]
pub struct ConfigurationRef {
config: Arc<RwLock<Configuration>>,
Expand All @@ -28,8 +29,6 @@ impl PartialEq for ConfigurationRef {
}
}
impl Eq for ConfigurationRef {}
unsafe impl Send for ConfigurationRef {}
unsafe impl Sync for ConfigurationRef {}
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved

impl fmt::Debug for ConfigurationRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
11 changes: 4 additions & 7 deletions android-activity/src/game_activity/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
15 changes: 11 additions & 4 deletions android-activity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {},

Expand Down Expand Up @@ -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()
}
Expand Down
8 changes: 4 additions & 4 deletions android-activity/src/native_activity/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WaitableNativeActivityState>,
}
unsafe impl Send for NativeActivityGlue {}
unsafe impl Sync for NativeActivityGlue {}

impl Deref for NativeActivityGlue {
type Target = WaitableNativeActivityState;
Expand Down Expand Up @@ -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<NativeWindow>,
}
Expand Down Expand Up @@ -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,
}),
Expand Down